mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Fix unloading of modules. Up warning levels to 4.
This commit is contained in:
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16)
|
||||
pybind11_add_module(mobase MODULE)
|
||||
mo2_configure_library(mobase
|
||||
SOURCE_TREE
|
||||
WARNINGS OFF
|
||||
WARNINGS 4
|
||||
AUTOMOC ON
|
||||
TRANSLATIONS OFF
|
||||
PRIVATE_DEPENDS uibase Qt::Core
|
||||
|
||||
@@ -25,9 +25,10 @@ namespace mo2::python {
|
||||
auto inspect = py::module_::import("inspect");
|
||||
auto current_frame = inspect.attr("currentframe")();
|
||||
py::sequence callable_frame = inspect.attr("getouterframes")(current_frame, 2);
|
||||
auto filename = callable_frame[-1].attr("filename").cast<std::string>();
|
||||
auto function = callable_frame[-1].attr("function").cast<std::string>();
|
||||
auto lineno = callable_frame[-1].attr("lineno").cast<int>();
|
||||
auto last_frame = callable_frame[py::int_(-1)];
|
||||
auto filename = last_frame.attr("filename").cast<std::string>();
|
||||
auto function = last_frame.attr("function").cast<std::string>();
|
||||
auto lineno = last_frame.attr("lineno").cast<int>();
|
||||
|
||||
// Only show once if requested:
|
||||
if (show_once && DeprecatedLines.contains({filename, lineno})) {
|
||||
|
||||
@@ -30,7 +30,6 @@ namespace mo2::python {
|
||||
namespace py = pybind11;
|
||||
|
||||
using namespace pybind11::literals;
|
||||
using namespace mo2::python;
|
||||
|
||||
void add_versioninfo_classes(py::module_ m)
|
||||
{
|
||||
|
||||
@@ -344,7 +344,7 @@ namespace mo2::python {
|
||||
pybind11::object extract_feature(IPluginGame const& game, pybind11::object type)
|
||||
{
|
||||
py::object py_feature = py::none();
|
||||
GameFeaturesHelper::apply([&]<class Feature>(Feature* feature) {
|
||||
GameFeaturesHelper::apply([&]<class Feature>(Feature*) {
|
||||
if (py::type::of<Feature>().is(type)) {
|
||||
py_feature = py::cast(game.feature<Feature>(),
|
||||
py::return_value_policy::reference);
|
||||
@@ -357,7 +357,7 @@ namespace mo2::python {
|
||||
{
|
||||
// constructing a dict from class name to actual object
|
||||
py::dict dict;
|
||||
GameFeaturesHelper::apply([&]<class Feature>(Feature* feature) {
|
||||
GameFeaturesHelper::apply([&]<class Feature>(Feature*) {
|
||||
dict[py::type::of<Feature>()] =
|
||||
py::cast(game.feature<Feature>(), py::return_value_policy::reference);
|
||||
});
|
||||
@@ -368,7 +368,7 @@ namespace mo2::python {
|
||||
convert_feature_list(py::dict const& py_features)
|
||||
{
|
||||
std::map<std::type_index, std::any> features;
|
||||
GameFeaturesHelper::apply([&]<class Feature>(Feature* feature) {
|
||||
GameFeaturesHelper::apply([&]<class Feature>(Feature*) {
|
||||
const auto py_type = py::type::of<Feature>();
|
||||
if (py_features.contains(py_type)) {
|
||||
features[std::type_index(typeid(Feature))] =
|
||||
|
||||
@@ -49,9 +49,8 @@ namespace mo2::detail {
|
||||
return std::make_shared<PyFileTree>(parent, name, m_Callback);
|
||||
}
|
||||
|
||||
bool
|
||||
doPopulate(std::shared_ptr<const IFileTree> parent,
|
||||
std::vector<std::shared_ptr<FileTreeEntry>>& entries) const override
|
||||
bool doPopulate(std::shared_ptr<const IFileTree> parent,
|
||||
std::vector<std::shared_ptr<FileTreeEntry>>&) const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,11 @@ namespace mo2::python {
|
||||
public:
|
||||
using PluginBase::PluginBase;
|
||||
|
||||
PyPluginBaseNoFinal(PyPluginBaseNoFinal const&) = delete;
|
||||
PyPluginBaseNoFinal(PyPluginBaseNoFinal&&) = delete;
|
||||
PyPluginBaseNoFinal& operator=(PyPluginBaseNoFinal const&) = delete;
|
||||
PyPluginBaseNoFinal& operator=(PyPluginBaseNoFinal&&) = delete;
|
||||
|
||||
bool init(IOrganizer* organizer) override
|
||||
{
|
||||
PYBIND11_OVERRIDE_PURE(bool, PluginBase, init, organizer);
|
||||
|
||||
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
add_library(plugin_python SHARED)
|
||||
mo2_configure_plugin(plugin_python
|
||||
WARNINGS OFF
|
||||
WARNINGS 4
|
||||
EXTRA_TRANSLATIONS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../runner
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../mobase
|
||||
|
||||
@@ -294,9 +294,9 @@ QString ProxyPython::fullDescription(unsigned int key) const
|
||||
}
|
||||
}
|
||||
|
||||
bool ProxyPython::hasGuidedFix(unsigned int key) const
|
||||
bool ProxyPython::hasGuidedFix(unsigned int) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void ProxyPython::startGuidedFix(unsigned int key) const {}
|
||||
void ProxyPython::startGuidedFix(unsigned int) const {}
|
||||
|
||||
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16)
|
||||
add_library(pybind11-qt STATIC)
|
||||
mo2_configure_library(pybind11-qt
|
||||
SOURCE_TREE
|
||||
WARNINGS OFF
|
||||
WARNINGS 4
|
||||
AUTOMOC OFF
|
||||
TRANSLATIONS OFF
|
||||
PRIVATE_DEPENDS Qt::Core Qt::Widgets
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace pybind11::detail {
|
||||
* instance or return false upon failure. The second argument
|
||||
* indicates whether implicit conversions should be applied.
|
||||
*/
|
||||
bool load(handle src, bool implicit)
|
||||
bool load(handle src, bool)
|
||||
{
|
||||
PyObject* tmp = PyNumber_Long(src.ptr());
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace pybind11::detail {
|
||||
* instance or return false upon failure. The second argument
|
||||
* indicates whether implicit conversions should be applied.
|
||||
*/
|
||||
bool type_caster<QString>::load(handle src, bool implicit)
|
||||
bool type_caster<QString>::load(handle src, bool)
|
||||
{
|
||||
|
||||
PyObject* objPtr = src.ptr();
|
||||
@@ -72,7 +72,7 @@ namespace pybind11::detail {
|
||||
src.length());
|
||||
}
|
||||
|
||||
bool type_caster<QVariant>::load(handle src, bool implicit)
|
||||
bool type_caster<QVariant>::load(handle src, bool)
|
||||
{
|
||||
// test for string first otherwise PyList_Check also works
|
||||
if (PyBytes_Check(src.ptr()) || PyUnicode_Check(src.ptr())) {
|
||||
@@ -90,7 +90,7 @@ namespace pybind11::detail {
|
||||
value = src.cast<QVariantMap>();
|
||||
return true;
|
||||
}
|
||||
else if (src == Py_None) {
|
||||
else if (src.is(pybind11::none())) {
|
||||
value = QVariant();
|
||||
return true;
|
||||
}
|
||||
@@ -118,27 +118,27 @@ namespace pybind11::detail {
|
||||
handle type_caster<QVariant>::cast(QVariant var, return_value_policy policy,
|
||||
handle parent)
|
||||
{
|
||||
switch (var.type()) {
|
||||
case QVariant::Invalid:
|
||||
switch (var.typeId()) {
|
||||
case QMetaType::UnknownType:
|
||||
return Py_None;
|
||||
case QVariant::Int:
|
||||
case QMetaType::Int:
|
||||
return PyLong_FromLong(var.toInt());
|
||||
case QVariant::UInt:
|
||||
case QMetaType::UInt:
|
||||
return PyLong_FromUnsignedLong(var.toUInt());
|
||||
case QVariant::Bool:
|
||||
case QMetaType::Bool:
|
||||
return PyBool_FromLong(var.toBool());
|
||||
case QVariant::String:
|
||||
case QMetaType::QString:
|
||||
return type_caster<QString>::cast(var.toString(), policy, parent);
|
||||
// We need to check for StringList here because these are not considered
|
||||
// List since List is QList<QVariant> will StringList is QList<QString>:
|
||||
case QVariant::StringList:
|
||||
case QMetaType::QStringList:
|
||||
return type_caster<QStringList>::cast(var.toStringList(), policy, parent);
|
||||
case QVariant::List:
|
||||
case QMetaType::QVariantList:
|
||||
return type_caster<QVariantList>::cast(var.toList(), policy, parent);
|
||||
case QVariant::Map:
|
||||
case QMetaType::QVariantMap:
|
||||
return type_caster<QVariantMap>::cast(var.toMap(), policy, parent);
|
||||
default: {
|
||||
PyErr_Format(PyExc_TypeError, "type unsupported: %d", var.type());
|
||||
PyErr_Format(PyExc_TypeError, "type unsupported: %d", var.userType());
|
||||
throw pybind11::error_already_set();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,23 +15,25 @@ namespace pybind11::detail::qt {
|
||||
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::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 = exp_str.cast<std::string>();
|
||||
{
|
||||
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 = exp_str.cast<std::string>();
|
||||
}
|
||||
PyErr_Restore(type, value, traceback);
|
||||
throw std::runtime_error{"Failed to load SIP API: " + exception};
|
||||
}
|
||||
PyErr_Restore(type, value, traceback);
|
||||
throw std::runtime_error{"Failed to load SIP API: " + exception};
|
||||
}
|
||||
|
||||
sipApi = (const sipAPIDef*)PyCapsule_Import("PyQt6.sip._C_API", 0);
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace mo2::python {
|
||||
|
||||
template <class T, std::size_t... Is, std::size_t... AIs, class Fn, class R,
|
||||
class... Args>
|
||||
auto wrap_fn_impl(std::index_sequence<Is...>, Fn&& fn, R (*sg)(Args...),
|
||||
auto wrap_fn_impl(std::index_sequence<Is...>, Fn&& fn, R (*)(Args...),
|
||||
std::index_sequence<AIs...>)
|
||||
{
|
||||
return [fn = std::forward<Fn>(fn)](
|
||||
@@ -63,10 +63,7 @@ namespace mo2::python {
|
||||
|
||||
template <class Type>
|
||||
struct load_wrapped_argument_helper<Type> {
|
||||
static bool load(Type& value, pybind11::handle src, bool convert)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
static bool load(Type&, pybind11::handle, bool) { return false; }
|
||||
};
|
||||
|
||||
template <class Type, class WrappedType, class... WrappedTypes>
|
||||
|
||||
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16)
|
||||
add_library(pythonrunner SHARED)
|
||||
mo2_configure_library(pythonrunner
|
||||
SOURCE_TREE
|
||||
WARNINGS OFF
|
||||
WARNINGS 4
|
||||
AUTOMOC ON
|
||||
TRANSLATIONS OFF
|
||||
PUBLIC_DEPENDS uibase Qt::Core
|
||||
|
||||
@@ -268,7 +268,7 @@ void PythonRunner::unload(const QString& identifier)
|
||||
for (std::size_t i = 0; i < py::len(keys); ++i) {
|
||||
py::object mod = modules[keys[i]];
|
||||
if (PyObject_HasAttrString(mod.ptr(), "__path__")) {
|
||||
QString mpath = mod.attr("__path__")[0].cast<QString>();
|
||||
QString mpath = mod.attr("__path__")[py::int_(0)].cast<QString>();
|
||||
|
||||
if (!folder.relativeFilePath(mpath).startsWith("..")) {
|
||||
// If the path is under identifier, we need to unload
|
||||
|
||||
@@ -38,7 +38,7 @@ foreach (test_file ${test_files})
|
||||
get_filename_component(target ${test_file} NAME_WLE)
|
||||
|
||||
string(REPLACE "test_" "" pymodule ${target})
|
||||
pybind11_add_module(${target} THIN_LTO ${test_file})
|
||||
pybind11_add_module(${target} EXCLUDE_FROM_ALL THIN_LTO ${test_file})
|
||||
set_target_properties(${target}
|
||||
PROPERTIES
|
||||
OUTPUT_NAME ${pymodule}
|
||||
|
||||
Reference in New Issue
Block a user