From c48df655d1358c0a379c34e3d0a3437e00f226cb Mon Sep 17 00:00:00 2001 From: David Sangrey <rixxan@hullseals.space> Date: Tue, 30 Apr 2024 23:16:51 -0400 Subject: [PATCH 1/3] [#1462] LoadModule Replacement, Take Two The previous attempt was almost correct - but we needed to ensure that the system was aware of the module in order to handle it correctly. --- plug.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/plug.py b/plug.py index dad08bc6..11ed96bc 100644 --- a/plug.py +++ b/plug.py @@ -47,14 +47,14 @@ last_error = LastError() class Plugin: """An EDMC plugin.""" - def __init__(self, name: str, loadfile: str | None, plugin_logger: logging.Logger | None): + def __init__(self, name: str, loadfile: str | None, plugin_logger: logging.Logger | None): # noqa: CCR001 """ Load a single plugin. :param name: Base name of the file being loaded from. :param loadfile: Full path/filename of the plugin. :param plugin_logger: The logging instance for this plugin to use. - :raises Exception: Typically ImportError or OSError + :raises Exception: Typically, ImportError or OSError """ self.name: str = name # Display name. self.folder: str | None = name # basename of plugin folder. None for internal plugins. @@ -66,19 +66,23 @@ class Plugin: try: filename = 'plugin_' filename += name.encode(encoding='ascii', errors='replace').decode('utf-8').replace('.', '_') - module = importlib.machinery.SourceFileLoader( - filename, - loadfile - ).load_module() - if getattr(module, 'plugin_start3', None): - newname = module.plugin_start3(os.path.dirname(loadfile)) - self.name = str(newname) if newname else self.name - self.module = module - elif getattr(module, 'plugin_start', None): - logger.warning(f'plugin {name} needs migrating\n') - PLUGINS_not_py3.append(self) + spec = importlib.util.spec_from_file_location(filename, loadfile) + + if spec is not None and spec.loader is not None: # Check if spec and spec.loader are not None + module = importlib.util.module_from_spec(spec) + sys.modules[module.__name__] = module + spec.loader.exec_module(module) + if getattr(module, 'plugin_start3', None): + newname = module.plugin_start3(os.path.dirname(loadfile)) + self.name = str(newname) if newname else self.name + self.module = module + elif getattr(module, 'plugin_start', None): + logger.warning(f'plugin {name} needs migrating\n') + PLUGINS_not_py3.append(self) + else: + logger.error(f'plugin {name} has no plugin_start3() function') else: - logger.error(f'plugin {name} has no plugin_start3() function') + logger.error(f'Failed to load Plugin "{name}" from file "{loadfile}"') except Exception: logger.exception(f': Failed for Plugin "{name}"') raise From 47f36a035c723c28b63f23944298f536e56860e2 Mon Sep 17 00:00:00 2001 From: David Sangrey <rixxan@hullseals.space> Date: Wed, 1 May 2024 11:08:27 -0400 Subject: [PATCH 2/3] [1462] Remove Useless Comment Add Slightly More Useful Comment --- plug.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plug.py b/plug.py index 11ed96bc..bd98f2bb 100644 --- a/plug.py +++ b/plug.py @@ -67,8 +67,8 @@ class Plugin: filename = 'plugin_' filename += name.encode(encoding='ascii', errors='replace').decode('utf-8').replace('.', '_') spec = importlib.util.spec_from_file_location(filename, loadfile) - - if spec is not None and spec.loader is not None: # Check if spec and spec.loader are not None + # Replaces older load_module() code. Includes a safety check that the module name is set. + if spec is not None and spec.loader is not None: module = importlib.util.module_from_spec(spec) sys.modules[module.__name__] = module spec.loader.exec_module(module) From 77720685de54e368fcdeff5eb405819df4543ce5 Mon Sep 17 00:00:00 2001 From: David Sangrey <rixxan@hullseals.space> Date: Mon, 20 May 2024 11:50:33 -0400 Subject: [PATCH 3/3] [Minor] Update Version for Alpha Tracking --- config/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/__init__.py b/config/__init__.py index 7e81d968..bf514186 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -53,7 +53,7 @@ appcmdname = 'EDMC' # <https://semver.org/#semantic-versioning-specification-semver> # Major.Minor.Patch(-prerelease)(+buildmetadata) # NB: Do *not* import this, use the functions appversion() and appversion_nobuild() -_static_appversion = '5.10.6' +_static_appversion = '5.11.0-alpha3' _cached_version: semantic_version.Version | None = None copyright = '© 2015-2019 Jonathan Harris, 2020-2024 EDCD'