|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | #include "py_panda.h"
|
8 |
| -#include "executionEnvironment.h" |
9 | 8 |
|
10 | 9 | #ifdef HAVE_PYTHON
|
11 | 10 |
|
@@ -696,66 +695,6 @@ PyObject *Dtool_PyModuleInitHelper(const LibraryDef *defs[], const char *modulen
|
696 | 695 | #endif
|
697 | 696 | }
|
698 | 697 |
|
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 |
| - |
759 | 698 | PyModule_AddIntConstant(module, "Dtool_PyNativeInterface", 1);
|
760 | 699 | return module;
|
761 | 700 | }
|
|
0 commit comments