diff --git a/.gitmodules b/.gitmodules index b54ee37..2726187 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "lib/pyind11"] - path = lib/pyind11 - url = https://github.com/pybind/pybind11 [submodule "pybind11"] path = pybind11 url = https://github.com/pybind/pybind11 diff --git a/CMakeLists.txt b/CMakeLists.txt index bc5194c..c0ed91f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,9 +6,10 @@ else() include(${CMAKE_CURRENT_LIST_DIR}/../cmake_common/mo2.cmake) endif() +set(PYBIND11_FINDPYTHON true) set(PYTHON_EXECUTABLE ${PYTHON_ROOT}/PCBuild/amd64/python.exe) -set(PYTHON_INCLUDE_DIR ${PYTHON_ROOT}/Include) -set(PYTHON_LIBRARY ${PYTHON_ROOT}/PCBuild/amd64/python38.lib) +set(PYTHON_INCLUDE_DIRS ${PYTHON_ROOT}/Include) +set(PYTHON_LIBRARIES ${PYTHON_ROOT}/PCBuild/amd64/python310.lib) add_subdirectory(pybind11) diff --git a/src/proxy/plugin_python_en.ts b/src/proxy/plugin_python_en.ts index 639f459..b2049aa 100644 --- a/src/proxy/plugin_python_en.ts +++ b/src/proxy/plugin_python_en.ts @@ -3,18 +3,6 @@ ProxyPython - - - Python Initialization failed - - - - - On a previous start the Python Plugin failed to initialize. -Do you want to try initializing python again (at the risk of another crash)? -Suggestion: Select "no", and click the warning sign for further help. Afterwards you have to re-enable the python plugin. - - Python Proxy @@ -26,48 +14,48 @@ Suggestion: Select "no", and click the warning sign for further help. - + ModOrganizer path contains a semicolon - + Python DLL not found - + Invalid Python DLL - + Initializing Python failed - - + + invalid problem key %1 - + The path to Mod Organizer (%1) contains a semicolon. <br>While this is legal on NTFS drives, many softwares do not handle it correctly.<br>Unfortunately MO depends on libraries that seem to fall into that group.<br>As a result the python plugin cannot be loaded, and the only solution we canoffer is to remove the semicolon or move MO to a path without a semicolon. - + The Python plugin DLL was not found, maybe your antivirus deleted it. Re-installing MO2 might fix the problem. - + The Python plugin DLL is invalid, maybe your antivirus is blocking it. Re-installing MO2 and adding exclusions for it to your AV might fix the problem. - + The initialization of the Python plugin DLL failed, unfortunately without any details. diff --git a/src/runner-pybind11/CMakeLists.txt b/src/runner-pybind11/CMakeLists.txt index f3c8867..82fe39d 100644 --- a/src/runner-pybind11/CMakeLists.txt +++ b/src/runner-pybind11/CMakeLists.txt @@ -7,7 +7,7 @@ pybind11_add_module(pythonrunner SHARED) mo2_configure_library(pythonrunner WARNINGS OFF AUTOMOC ON - TRANSLATIONS ON + TRANSLATIONS OFF PRIVATE_DEPENDS uibase boost Qt::Core ) set_target_properties(pythonrunner @@ -15,16 +15,15 @@ set_target_properties(pythonrunner OUTPUT_NAME "pythonrunner" PREFIX "" SUFFIX ".dll") -# target_link_libraries(pythonrunner PRIVATE pybind11::embed) -# target_include_directories(pythonrunner PRIVATE ${PYTHON_ROOT}/Include) +target_link_libraries(pythonrunner PRIVATE pybind11::embed) +target_include_directories(pythonrunner PRIVATE ${PYTHON_ROOT}/Include) # this is kind of broken but it only works with this... target_link_directories(pythonrunner PRIVATE - ${MO2_INSTALL_LIBS_PATH} ${Boost_LIBRARY_DIRS}) target_compile_definitions(pythonrunner - PRIVATE QT_NO_KEYWORDS PYTHONRUNNER_LIBRARY) + PRIVATE PYTHONRUNNER_LIBRARY) mo2_install_target(pythonrunner INSTALLDIR bin/plugins/data) mo2_add_filter(NAME src/converters GROUPS diff --git a/src/runner-pybind11/converters_qt_sip.cpp b/src/runner-pybind11/converters_qt_sip.cpp index 9fc9e9d..559c44e 100644 --- a/src/runner-pybind11/converters_qt_sip.cpp +++ b/src/runner-pybind11/converters_qt_sip.cpp @@ -10,82 +10,53 @@ namespace mo2::details { const sipAPIDef* sipAPI() { - QString exception; - static const sipAPIDef* sipApi = nullptr; - if (sipApi == nullptr) { - #if defined(SIP_USE_PYCAPSULE) - PyImport_ImportModule("PyQt5.sip"); + QString exception; + static const sipAPIDef* sipApi = nullptr; + if (sipApi == nullptr) { + PyImport_ImportModule("PyQt6.sip"); - auto errorObj = PyErr_Occurred(); - if (errorObj != NULL) { - PyObject* type, * value, * traceback; - PyErr_Fetch(&type, &value, &traceback); - PyErr_NormalizeException(&type, &value, &traceback); - if (traceback != NULL) { - py::handle h_type(type); - py::handle h_val(value); - py::handle h_tb(traceback); - py::module_ tb = py::module_::import("traceback"); - py::object fmt_exp(tb.attr("format_exception")); - py::object exp_list(fmt_exp(h_type, h_val, h_tb)); - py::object exp_str(py::str("\n").attr("join")(exp_list)); - exception = QString::fromStdString(exp_str.cast()); - } - PyErr_Restore(type, value, traceback); - throw MOBase::Exception(QString("Failed to load PyQt5: %1").arg(exception)); - } - - sipApi = (const sipAPIDef*)PyCapsule_Import("PyQt5.sip._C_API", 0); - if (sipApi == NULL) { - auto errorObj = PyErr_Occurred(); - if (errorObj != NULL) { - PyObject* type, * value, * traceback; - PyErr_Fetch(&type, &value, &traceback); - PyErr_NormalizeException(&type, &value, &traceback); - if (traceback != NULL) { - py::handle h_type(type); - py::handle h_val(value); - py::handle h_tb(traceback); - py::module_ tb = py::module_::import("traceback"); - py::object fmt_exp(tb.attr("format_exception")); - py::object exp_list(fmt_exp(h_type, h_val, h_tb)); - py::object exp_str(py::str("\n").attr("join")(exp_list)); - exception = QString::fromStdString(exp_str.cast()); - } - PyErr_Restore(type, value, traceback); - } - throw MOBase::Exception(QString("Failed to load SIP API: %1").arg(exception)); - } - #else - PyObject* sip_module; - PyObject* sip_module_dict; - PyObject* c_api; - - /* Import the SIP module. */ - sip_module = PyImport_ImportModule("PyQt5.sip"); - - if (sip_module == NULL) - return NULL; - - /* Get the module's dictionary. */ - sip_module_dict = PyModule_GetDict(sip_module); - - /* Get the "_C_API" attribute. */ - c_api = PyDict_GetItemString(sip_module_dict, "_C_API"); - - if (c_api == NULL) - return NULL; - - /* Sanity check that it is the right type. */ - if (!PyCObject_Check(c_api)) - return NULL; - - /* Get the actual pointer from the object. */ - sipApi = (const sipAPIDef*)PyCObject_AsVoidPtr(c_api); - #endif + auto errorObj = PyErr_Occurred(); + if (errorObj != NULL) { + PyObject* type, * value, * traceback; + PyErr_Fetch(&type, &value, &traceback); + PyErr_NormalizeException(&type, &value, &traceback); + if (traceback != NULL) { + py::handle h_type(type); + py::handle h_val(value); + py::handle h_tb(traceback); + py::object tb(py::module_::import("traceback")); + py::object fmt_exp(tb.attr("format_exception")); + py::object exp_list(fmt_exp(h_type, h_val, h_tb)); + py::object exp_str(py::str("\n").attr("join")(exp_list)); + exception = QString::fromStdString(exp_str.cast()); + } + PyErr_Restore(type, value, traceback); + throw MOBase::Exception(QString("Failed to load PyQt6: %1").arg(exception)); } - return sipApi; + sipApi = (const sipAPIDef*)PyCapsule_Import("PyQt6.sip._C_API", 0); + if (sipApi == NULL) { + auto errorObj = PyErr_Occurred(); + if (errorObj != NULL) { + PyObject* type, * value, * traceback; + PyErr_Fetch(&type, &value, &traceback); + PyErr_NormalizeException(&type, &value, &traceback); + if (traceback != NULL) { + py::handle h_type(type); + py::handle h_val(value); + py::handle h_tb(traceback); + py::object tb(py::module_::import("traceback")); + py::object fmt_exp(tb.attr("format_exception")); + py::object exp_list(fmt_exp(h_type, h_val, h_tb)); + py::object exp_str(py::str("\n").attr("join")(exp_list)); + exception = QString::fromStdString(exp_str.cast()); + } + PyErr_Restore(type, value, traceback); + } + throw MOBase::Exception(QString("Failed to load SIP API: %1").arg(exception)); + } + } + return sipApi; } } diff --git a/src/runner-pybind11/pythonrunner.cpp b/src/runner-pybind11/pythonrunner.cpp index 6906f5c..332c912 100644 --- a/src/runner-pybind11/pythonrunner.cpp +++ b/src/runner-pybind11/pythonrunner.cpp @@ -70,8 +70,8 @@ namespace py = pybind11; PYBIND11_MODULE(mobase, m) { - py::module_::import("PyQt5.QtCore"); - py::module_::import("PyQt5.QtWidgets"); + py::module_::import("PyQt6.QtCore"); + py::module_::import("PyQt6.QtWidgets"); py::detail::type_caster t1; py::detail::type_caster t2; @@ -1223,7 +1223,7 @@ bool PythonRunner::initPython() mainNamespace); mainNamespace["mobase"] = py::module_::import("mobase"); - mo2::details::configure_python_logging(mainNamespace["mobase"]); + mo2::python::configure_python_logging(mainNamespace["mobase"]); return true; } catch (const py::error_already_set&) {