Skip to content

Commit bcb00ae

Browse files
committed
Adding debug statements
1 parent cbf68a6 commit bcb00ae

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

Libs/Optimize/Optimize.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include "OptimizeParameters.h"
3838
#include "ShapeworksUtils.h"
3939

40+
#include <iostream>
41+
4042
// pybind
4143
#include <pybind11/embed.h>
4244

@@ -74,47 +76,58 @@ bool Optimize::Run() {
7476
m_last_update_time = m_start_time;
7577

7678
ShapeWorksUtils::setup_threads();
77-
7879
if (m_python_filename != "") {
7980
#ifdef _WIN32
8081
// Save current directory
8182
char original_dir[MAX_PATH];
8283
_getcwd(original_dir, MAX_PATH);
84+
std::cerr << "Original CWD: " << original_dir << "\n";
8385

8486
// need to set PYTHONHOME to the same directory as python.exe on Windows
8587
std::string found_path = find_in_path("python.exe");
8688
if (found_path != "") {
8789
std::cerr << "python.exe found in: " << found_path << "\n";
8890
_putenv_s("PYTHONHOME", found_path.c_str());
8991
}
90-
9192
// Change to safe directory for Python init
9293
_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";
9397
#endif
94-
9598
py::initialize_interpreter();
9699

97100
#ifdef _WIN32
101+
// Debug: Check CWD from Python's perspective
102+
py::exec("import os; print('Python CWD after init:', os.getcwd())");
103+
98104
// Restore original directory
99105
_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())");
100111
#endif
101112

102113
auto dir = m_python_filename;
103-
104114
auto filename = dir.substr(dir.find_last_of("/") + 1);
105115
SW_LOG("Running Python File: {}", filename);
106116
filename = filename.substr(0, filename.length() - 3); // remove .py
107117
dir = dir.substr(0, dir.find_last_of("/") + 1);
108118

109119
py::module sys = py::module::import("sys");
120+
std::cerr << "sys.path before insert:\n";
110121
py::print(sys.attr("path"));
122+
111123
sys.attr("path").attr("insert")(1, dir);
124+
std::cerr << "sys.path after insert of dir '" << dir << "':\n";
112125
py::print(sys.attr("path"));
113126

127+
std::cerr << "About to import module: " << filename << "\n";
114128
py::module module = py::module::import(filename.c_str());
115129
py::object result = module.attr("run")(this);
116130
}
117-
118131
if (!SetParameters()) {
119132
return false;
120133
}

0 commit comments

Comments
 (0)