aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDavid Shah <dave@ds0.me>2019-04-17 10:57:19 +0100
committerDavid Shah <dave@ds0.me>2019-04-17 10:57:19 +0100
commit90ceb829f347372975310d40d2bb6bade0352890 (patch)
treee7418c3243288323e5abbea3cb7b49b023dbb755 /common
parent659c9325591845806143865563081a6644a3b900 (diff)
downloadnextpnr-90ceb829f347372975310d40d2bb6bade0352890.tar.gz
nextpnr-90ceb829f347372975310d40d2bb6bade0352890.tar.bz2
nextpnr-90ceb829f347372975310d40d2bb6bade0352890.zip
pybindings: Fix use of import in user scripts
Signed-off-by: David Shah <dave@ds0.me>
Diffstat (limited to 'common')
-rw-r--r--common/pybindings.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/common/pybindings.cc b/common/pybindings.cc
index e1fc8534..f8f366cf 100644
--- a/common/pybindings.cc
+++ b/common/pybindings.cc
@@ -25,6 +25,7 @@
#include "jsonparse.h"
#include "nextpnr.h"
+#include <boost/filesystem.hpp>
#include <fstream>
#include <memory>
#include <signal.h>
@@ -233,6 +234,12 @@ void init_python(const char *executable, bool first)
PyImport_AppendInittab(TOSTRING(MODULE_NAME), PYINIT_MODULE_NAME);
Py_SetProgramName(program);
Py_Initialize();
+
+ // Add cwd to Python's search path so `import` can be used in user scripts
+ boost::filesystem::path cwd = boost::filesystem::absolute("./").normalize();
+ PyObject *sys_path = PySys_GetObject("path");
+ PyList_Insert(sys_path, 0, PyUnicode_FromString(cwd.string().c_str()));
+
PyImport_ImportModule(TOSTRING(MODULE_NAME));
PyRun_SimpleString("from " TOSTRING(MODULE_NAME) " import *");
} catch (boost::python::error_already_set const &) {