mirror of https://github.com/KLayout/klayout.git
On Windows, Python needs to have a proper PYTHONHOME, otherwise a warning is issued
This commit is contained in:
parent
f1f92e5a0c
commit
ef4cbb045b
|
|
@ -222,6 +222,8 @@ PythonInterpreter::PythonInterpreter (bool embedded)
|
||||||
// If set, use $KLAYOUT_PYTHONHOME to initialize the path.
|
// If set, use $KLAYOUT_PYTHONHOME to initialize the path.
|
||||||
// Otherwise there may be some conflict between external installations and KLayout.
|
// Otherwise there may be some conflict between external installations and KLayout.
|
||||||
|
|
||||||
|
bool has_klayout_pythonhome = false;
|
||||||
|
|
||||||
// Python is not easily convinced to use an external path properly.
|
// Python is not easily convinced to use an external path properly.
|
||||||
// So we simply redirect PYTHONHOME
|
// So we simply redirect PYTHONHOME
|
||||||
std::string pythonhome_name ("PYTHONHOME");
|
std::string pythonhome_name ("PYTHONHOME");
|
||||||
|
|
@ -230,6 +232,7 @@ PythonInterpreter::PythonInterpreter (bool embedded)
|
||||||
tl::unset_env (pythonhome_name);
|
tl::unset_env (pythonhome_name);
|
||||||
}
|
}
|
||||||
if (tl::has_env (klayout_pythonhome_name)) {
|
if (tl::has_env (klayout_pythonhome_name)) {
|
||||||
|
has_klayout_pythonhome = true;
|
||||||
tl::set_env (pythonhome_name, tl::get_env (klayout_pythonhome_name));
|
tl::set_env (pythonhome_name, tl::get_env (klayout_pythonhome_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -237,6 +240,22 @@ PythonInterpreter::PythonInterpreter (bool embedded)
|
||||||
|
|
||||||
tl_assert (sizeof (wchar_t) == 2);
|
tl_assert (sizeof (wchar_t) == 2);
|
||||||
|
|
||||||
|
std::string inst_dir;
|
||||||
|
|
||||||
|
wchar_t buffer[MAX_PATH];
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if ((len = GetModuleFileNameW (NULL, buffer, MAX_PATH)) > 0) {
|
||||||
|
inst_dir = tl::absolute_path (tl::to_string (std::wstring (buffer, len)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! has_klayout_pythonhome) {
|
||||||
|
|
||||||
|
// Use our own installation path for PYTHOHOME unless given
|
||||||
|
Py_SetPythonHome (tl::to_wstring (inst_dir).c_str ());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (! has_klayout_pythonpath) {
|
if (! has_klayout_pythonpath) {
|
||||||
|
|
||||||
// If present, read the paths from a file in INST_PATH/.python-paths.txt.
|
// If present, read the paths from a file in INST_PATH/.python-paths.txt.
|
||||||
|
|
@ -247,34 +266,27 @@ PythonInterpreter::PythonInterpreter (bool embedded)
|
||||||
|
|
||||||
std::string path;
|
std::string path;
|
||||||
|
|
||||||
wchar_t buffer[MAX_PATH];
|
std::string path_file = tl::combine_path (inst_dir, ".python-paths.txt");
|
||||||
int len;
|
if (tl::file_exists (path_file)) {
|
||||||
if ((len = GetModuleFileNameW (NULL, buffer, MAX_PATH)) > 0) {
|
|
||||||
|
|
||||||
std::string inst_dir = tl::absolute_path (tl::to_string (std::wstring (buffer, len)));
|
tl::log << tl::to_string (tr ("Reading Python path from ")) << path_file;
|
||||||
std::string path_file = tl::combine_path (inst_dir, ".python-paths.txt");
|
|
||||||
if (tl::file_exists (path_file)) {
|
|
||||||
|
|
||||||
tl::log << tl::to_string (tr ("Reading Python path from ")) << path_file;
|
tl::InputStream path_file_stream (path_file);
|
||||||
|
std::string path_file_text = path_file_stream.read_all ();
|
||||||
|
|
||||||
tl::InputStream path_file_stream (path_file);
|
tl::Eval eval;
|
||||||
std::string path_file_text = path_file_stream.read_all ();
|
eval.set_global_var ("inst_path", tl::Variant (inst_dir));
|
||||||
|
tl::Expression ex;
|
||||||
|
eval.parse (ex, path_file_text.c_str ());
|
||||||
|
tl::Variant v = ex.execute ();
|
||||||
|
|
||||||
tl::Eval eval;
|
if (v.is_list ()) {
|
||||||
eval.set_global_var ("inst_path", tl::Variant (inst_dir));
|
for (tl::Variant::iterator i = v.begin (); i != v.end (); ++i) {
|
||||||
tl::Expression ex;
|
if (! path.empty ()) {
|
||||||
eval.parse (ex, path_file_text.c_str ());
|
path += ";";
|
||||||
tl::Variant v = ex.execute ();
|
|
||||||
|
|
||||||
if (v.is_list ()) {
|
|
||||||
for (tl::Variant::iterator i = v.begin (); i != v.end (); ++i) {
|
|
||||||
if (! path.empty ()) {
|
|
||||||
path += ";";
|
|
||||||
}
|
|
||||||
path += i->to_string ();
|
|
||||||
}
|
}
|
||||||
|
path += i->to_string ();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue