Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui: replace python imp library with importlib for python 3.12 #4201

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,23 @@ def RunCmd(

if len(command) == 1:
if command[0].startswith("g.gui."):
import imp
import inspect
import importlib.util
import importlib.machinery

def load_source(modname, filename):
loader = importlib.machinery.SourceFileLoader(
modname, filename
)
spec = importlib.util.spec_from_file_location(
modname, filename, loader=loader
)
module = importlib.util.module_from_spec(spec)
# Module is always executed and not cached in sys.modules.
# Uncomment the following line to cache the module.
# sys.modules[module.__name__] = module
loader.exec_module(module)
return module

pyFile = command[0]
if sys.platform == "win32":
Expand All @@ -601,7 +616,7 @@ def RunCmd(
parent=self._guiparent,
message=_("Module <%s> not found.") % command[0],
)
pymodule = imp.load_source(command[0].replace(".", "_"), pyPath)
pymodule = load_source(command[0].replace(".", "_"), pyPath)
pymain = inspect.getfullargspec(pymodule.main)
if pymain and "giface" in pymain.args:
pymodule.main(self._giface)
Expand Down
Loading