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,11 +266,6 @@ PythonInterpreter::PythonInterpreter (bool embedded)
|
||||||
|
|
||||||
std::string path;
|
std::string path;
|
||||||
|
|
||||||
wchar_t buffer[MAX_PATH];
|
|
||||||
int len;
|
|
||||||
if ((len = GetModuleFileNameW (NULL, buffer, MAX_PATH)) > 0) {
|
|
||||||
|
|
||||||
std::string inst_dir = tl::absolute_path (tl::to_string (std::wstring (buffer, len)));
|
|
||||||
std::string path_file = tl::combine_path (inst_dir, ".python-paths.txt");
|
std::string path_file = tl::combine_path (inst_dir, ".python-paths.txt");
|
||||||
if (tl::file_exists (path_file)) {
|
if (tl::file_exists (path_file)) {
|
||||||
|
|
||||||
|
|
@ -277,8 +291,6 @@ PythonInterpreter::PythonInterpreter (bool embedded)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_SetPath (tl::to_wstring (path).c_str ());
|
Py_SetPath (tl::to_wstring (path).c_str ());
|
||||||
|
|
||||||
} catch (tl::Exception &ex) {
|
} catch (tl::Exception &ex) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue