Skip to content

Commit 4a90e54

Browse files
committed
py_panda: Remove panda-specific MAIN_DIR init code
1 parent 0d35390 commit 4a90e54

File tree

1 file changed

+0
-61
lines changed

1 file changed

+0
-61
lines changed

src/interrogatedb/py_panda.cxx

-61
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
#include "py_panda.h"
8-
#include "executionEnvironment.h"
98

109
#ifdef HAVE_PYTHON
1110

@@ -696,66 +695,6 @@ PyObject *Dtool_PyModuleInitHelper(const LibraryDef *defs[], const char *modulen
696695
#endif
697696
}
698697

699-
// MAIN_DIR needs to be set very early; this seems like a convenient place
700-
// to do that. Perhaps we'll find a better place for this in the future.
701-
static bool initialized_main_dir = false;
702-
if (!initialized_main_dir) {
703-
/*if (interrogatedb_cat.is_debug()) {
704-
// Good opportunity to print this out once, at startup.
705-
interrogatedb_cat.debug()
706-
<< "Python " << version << "\n";
707-
}*/
708-
709-
if (!ExecutionEnvironment::has_environment_variable("MAIN_DIR")) {
710-
// Grab the __main__ module.
711-
PyObject *main_module = PyImport_ImportModule("__main__");
712-
if (main_module == NULL) {
713-
std::cerr << "Warning: unable to import __main__\n";
714-
}
715-
716-
// Extract the __file__ attribute, if present.
717-
Filename main_dir;
718-
PyObject *file_attr = nullptr;
719-
if (main_module != nullptr) {
720-
file_attr = PyObject_GetAttrString(main_module, "__file__");
721-
}
722-
if (file_attr == nullptr) {
723-
// Must be running in the interactive interpreter. Use the CWD.
724-
main_dir = ExecutionEnvironment::get_cwd();
725-
} else {
726-
#if PY_MAJOR_VERSION >= 3
727-
Py_ssize_t length;
728-
wchar_t *buffer = PyUnicode_AsWideCharString(file_attr, &length);
729-
if (buffer != nullptr) {
730-
main_dir = Filename::from_os_specific_w(std::wstring(buffer, length));
731-
main_dir.make_absolute();
732-
main_dir = main_dir.get_dirname();
733-
PyMem_Free(buffer);
734-
}
735-
#else
736-
char *buffer;
737-
Py_ssize_t length;
738-
if (PyString_AsStringAndSize(file_attr, &buffer, &length) != -1) {
739-
main_dir = Filename::from_os_specific(std::string(buffer, length));
740-
main_dir.make_absolute();
741-
main_dir = main_dir.get_dirname();
742-
}
743-
#endif
744-
else {
745-
std::cerr << "Invalid string for __main__.__file__\n";
746-
}
747-
}
748-
ExecutionEnvironment::shadow_environment_variable("MAIN_DIR", main_dir.to_os_specific());
749-
PyErr_Clear();
750-
}
751-
initialized_main_dir = true;
752-
753-
// Also, while we are at it, initialize the thread swap hook.
754-
#if defined(HAVE_THREADS) && defined(SIMPLE_THREADS)
755-
global_thread_state_swap = PyThreadState_Swap;
756-
#endif
757-
}
758-
759698
PyModule_AddIntConstant(module, "Dtool_PyNativeInterface", 1);
760699
return module;
761700
}

0 commit comments

Comments
 (0)