Skip to content

Commit

Permalink
gui: replace python imp library with importlib for python 3.12 (OSGeo…
Browse files Browse the repository at this point in the history
  • Loading branch information
petrasovaa authored Aug 20, 2024
1 parent a4257a1 commit fdfec39
Showing 1 changed file with 17 additions and 2 deletions.
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

0 comments on commit fdfec39

Please sign in to comment.