Enabling pya initialization for app and ut_runner only.

This commit is contained in:
Matthias Koefferlein 2023-03-29 00:09:26 +02:00
parent 1cfe7b10ba
commit cb0f2b4166
7 changed files with 15 additions and 19 deletions

View File

@ -65,8 +65,6 @@
# include "gsiQtDesignerExternals.h" # include "gsiQtDesignerExternals.h"
# include "gsiQtUiToolsExternals.h" # include "gsiQtUiToolsExternals.h"
// pulls in the Qt GSI binding modules - need to be force loaded so they are available
// the pya Python module (Python >= 3.8 does not recognize DLL paths on Windows)
FORCE_LINK_GSI_QTCORE FORCE_LINK_GSI_QTCORE
FORCE_LINK_GSI_QTGUI FORCE_LINK_GSI_QTGUI
FORCE_LINK_GSI_QTWIDGETS FORCE_LINK_GSI_QTWIDGETS
@ -283,9 +281,6 @@ klayout_main_cont (int &argc, char **argv)
try { try {
// initialize the Python interpreter
pya::PythonInterpreter::initialize ();
// this registers the gsi definitions // this registers the gsi definitions
gsi::initialize_external (); gsi::initialize_external ();

View File

@ -616,6 +616,9 @@ ApplicationBase::init_app ()
mp_ruby_interpreter = new rba::RubyInterpreter (); mp_ruby_interpreter = new rba::RubyInterpreter ();
mp_python_interpreter = new pya::PythonInterpreter (); mp_python_interpreter = new pya::PythonInterpreter ();
// initialize the Python interpreter - load the pya module
pya::PythonInterpreter::initialize ();
// Read some configuration values that we need early // Read some configuration values that we need early
bool editable_from_config = false; bool editable_from_config = false;

View File

@ -326,16 +326,9 @@ PythonInterpreter::PythonInterpreter (bool embedded)
tl::warn << tl::to_string (tr ("Unable to find built-in Python module library path")); tl::warn << tl::to_string (tr ("Unable to find built-in Python module library path"));
} }
// Import the pya module
PyObject *pya_module = PyImport_ImportModule (pya_module_name);
if (pya_module == NULL) {
check_error ();
return;
}
// Build two objects that provide a way to redirect stdout, stderr // Build two objects that provide a way to redirect stdout, stderr
// and instantiate them two times for stdout and stderr. // and instantiate them two times for stdout and stderr.
PYAChannelObject::make_class (pya_module); PYAChannelObject::make_class ();
m_stdout_channel = PythonRef (PYAChannelObject::create (gsi::Console::OS_stdout)); m_stdout_channel = PythonRef (PYAChannelObject::create (gsi::Console::OS_stdout));
m_stdout = PythonPtr (m_stdout_channel.get ()); m_stdout = PythonPtr (m_stdout_channel.get ());
m_stderr_channel = PythonRef (PYAChannelObject::create (gsi::Console::OS_stderr)); m_stderr_channel = PythonRef (PYAChannelObject::create (gsi::Console::OS_stderr));
@ -601,7 +594,11 @@ PythonInterpreter::available () const
void void
PythonInterpreter::initialize () PythonInterpreter::initialize ()
{ {
// .. no implementation required .. // Import the pya module
PyObject *pya_module = PyImport_ImportModule (pya_module_name);
if (pya_module == NULL) {
check_error ();
}
} }
size_t size_t

View File

@ -248,6 +248,7 @@ public:
/** /**
* @brief Provide a first (basic) initialization * @brief Provide a first (basic) initialization
* Calling this method will load all Python functions and plugins and provide the pya module.
*/ */
static void initialize (); static void initialize ();

View File

@ -102,11 +102,11 @@ pya_channel_init (PyObject *self, PyObject *, PyObject *)
} }
void void
PYAChannelObject::make_class (PyObject *module) PYAChannelObject::make_class ()
{ {
static PyTypeObject channel_type = { static PyTypeObject channel_type = {
PyVarObject_HEAD_INIT (&PyType_Type, 0) PyVarObject_HEAD_INIT (&PyType_Type, 0)
"pya._Channel", // tp_name "__PYA_Channel", // tp_name
sizeof (PYAChannelObject) // tp_size sizeof (PYAChannelObject) // tp_size
}; };
@ -124,7 +124,8 @@ PYAChannelObject::make_class (PyObject *module)
PyType_Ready (&channel_type); PyType_Ready (&channel_type);
Py_INCREF (&channel_type); Py_INCREF (&channel_type);
PyModule_AddObject (module, "_Channel", (PyObject *) &channel_type); PyObject *module = PyImport_AddModule("__main__");
PyModule_AddObject (module, "__PYA_Channel", (PyObject *) &channel_type);
cls = &channel_type; cls = &channel_type;
} }

View File

@ -44,7 +44,7 @@ class SignalHandler;
struct PYAChannelObject struct PYAChannelObject
: public PyObject : public PyObject
{ {
static void make_class (PyObject *module); static void make_class ();
static PYAChannelObject *create (gsi::Console::output_stream chn); static PYAChannelObject *create (gsi::Console::output_stream chn);
gsi::Console::output_stream channel; gsi::Console::output_stream channel;

View File

@ -490,7 +490,6 @@ main_cont (int &argc, char **argv)
try { try {
pya::PythonInterpreter::initialize ();
gsi::initialize_external (); gsi::initialize_external ();
// Search and initialize plugin unit tests // Search and initialize plugin unit tests