Skip to content

Commit

Permalink
Bugfix - a few hours on Stackoverflow showed me that nobody did this …
Browse files Browse the repository at this point in the history
…before (or asked the stupid questions that I had in my mind). This seems to work at least on Windows, but is deemed to be implementation dependent...
  • Loading branch information
christofmuc committed Jun 16, 2020
1 parent 06a25e1 commit 62ead2c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions adaptions/GenericAdaption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,14 @@ namespace knobkraft {
{
try {
ScopedLock lock(GenericAdaption::multiThreadGuard);
auto types = py::module::import("types");
auto importlib = py::module::import("importlib.util");
checkForPythonOutputAndLog();
auto adaption_module = types.attr("ModuleType")(moduleName); // Create an empty module with the right name
auto spec = importlib.attr("spec_from_loader")(moduleName, py::none()); // Create an empty module with the right name
auto adaption_module = importlib.attr("module_from_spec")(spec);
auto builtins = py::module::import("builtins");
adaption_module.attr("__builtins__") = builtins; // That seems to be implementation depend... https://docs.python.org/3/library/builtins.html
checkForPythonOutputAndLog();
py::exec(adaptionCode, py::globals(), adaption_module.attr("__dict__")); // Now run the define statements in the code, creating the defines within the right namespace
py::exec(adaptionCode, adaption_module.attr("__dict__")); // Now run the define statements in the code, creating the defines within the right namespace
checkForPythonOutputAndLog();
auto newAdaption = std::make_shared<GenericAdaption>(py::cast<py::module>(adaption_module));
//if (newAdaption) newAdaption->logNamespace();
Expand Down

0 comments on commit 62ead2c

Please sign in to comment.