|
37 | 37 | #include "OptimizeParameters.h" |
38 | 38 | #include "ShapeworksUtils.h" |
39 | 39 |
|
| 40 | +#include <iostream> |
| 41 | + |
40 | 42 | // pybind |
41 | 43 | #include <pybind11/embed.h> |
42 | 44 |
|
@@ -74,47 +76,58 @@ bool Optimize::Run() { |
74 | 76 | m_last_update_time = m_start_time; |
75 | 77 |
|
76 | 78 | ShapeWorksUtils::setup_threads(); |
77 | | - |
78 | 79 | if (m_python_filename != "") { |
79 | 80 | #ifdef _WIN32 |
80 | 81 | // Save current directory |
81 | 82 | char original_dir[MAX_PATH]; |
82 | 83 | _getcwd(original_dir, MAX_PATH); |
| 84 | + std::cerr << "Original CWD: " << original_dir << "\n"; |
83 | 85 |
|
84 | 86 | // need to set PYTHONHOME to the same directory as python.exe on Windows |
85 | 87 | std::string found_path = find_in_path("python.exe"); |
86 | 88 | if (found_path != "") { |
87 | 89 | std::cerr << "python.exe found in: " << found_path << "\n"; |
88 | 90 | _putenv_s("PYTHONHOME", found_path.c_str()); |
89 | 91 | } |
90 | | - |
91 | 92 | // Change to safe directory for Python init |
92 | 93 | _chdir("C:\\"); |
| 94 | + char cwd_after_change[MAX_PATH]; |
| 95 | + _getcwd(cwd_after_change, MAX_PATH); |
| 96 | + std::cerr << "CWD after change to C:\\: " << cwd_after_change << "\n"; |
93 | 97 | #endif |
94 | | - |
95 | 98 | py::initialize_interpreter(); |
96 | 99 |
|
97 | 100 | #ifdef _WIN32 |
| 101 | + // Debug: Check CWD from Python's perspective |
| 102 | + py::exec("import os; print('Python CWD after init:', os.getcwd())"); |
| 103 | + |
98 | 104 | // Restore original directory |
99 | 105 | _chdir(original_dir); |
| 106 | + char cwd_restored[MAX_PATH]; |
| 107 | + _getcwd(cwd_restored, MAX_PATH); |
| 108 | + std::cerr << "CWD after restore: " << cwd_restored << "\n"; |
| 109 | + |
| 110 | + py::exec("import os; print('Python CWD after restore:', os.getcwd())"); |
100 | 111 | #endif |
101 | 112 |
|
102 | 113 | auto dir = m_python_filename; |
103 | | - |
104 | 114 | auto filename = dir.substr(dir.find_last_of("/") + 1); |
105 | 115 | SW_LOG("Running Python File: {}", filename); |
106 | 116 | filename = filename.substr(0, filename.length() - 3); // remove .py |
107 | 117 | dir = dir.substr(0, dir.find_last_of("/") + 1); |
108 | 118 |
|
109 | 119 | py::module sys = py::module::import("sys"); |
| 120 | + std::cerr << "sys.path before insert:\n"; |
110 | 121 | py::print(sys.attr("path")); |
| 122 | + |
111 | 123 | sys.attr("path").attr("insert")(1, dir); |
| 124 | + std::cerr << "sys.path after insert of dir '" << dir << "':\n"; |
112 | 125 | py::print(sys.attr("path")); |
113 | 126 |
|
| 127 | + std::cerr << "About to import module: " << filename << "\n"; |
114 | 128 | py::module module = py::module::import(filename.c_str()); |
115 | 129 | py::object result = module.attr("run")(this); |
116 | 130 | } |
117 | | - |
118 | 131 | if (!SetParameters()) { |
119 | 132 | return false; |
120 | 133 | } |
|
0 commit comments