Skip to content

updated advanced customization of QT module import process #85

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

Open
wants to merge 1 commit into
base: 6.0
Choose a base branch
from
Open
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
26 changes: 18 additions & 8 deletions python/soma/qt_gui/qt_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@
make_compatible_qt5 = False


class QtImporter:
def find_module(self, fullname, path=None):
modsplit = fullname.split(".")
modpath = ".".join(modsplit[:-1])
class QtImporter(object):

def find_spec(self, fullname, path=None, target=None):
modsplit = fullname.split('.')
modpath = '.'.join(modsplit[:-1])
module_name = modsplit[-1]
if modpath != __name__ or fullname == "sip":
return None
Expand All @@ -75,14 +76,23 @@ def find_module(self, fullname, path=None):
try:
found = importlib.util.find_spec(module_name)
if found is not None:
return self
found.loader = self
return found
else:
return None
except ImportError:
return None
return self
found.loader = self
return found

def exec_module(self, module):
# this method can be used to execute the module in the module
# namespace, which can include adding variables, functions, etc.
pass

def load_module(self, name):
def create_module(self, spec=None, name=None):
if name is None:
name = spec.name
qt_backend = get_qt_backend()
module_name = name.split(".")[-1]
imp_module_name = module_name
Expand Down Expand Up @@ -133,7 +143,7 @@ def load_module(self, name):
mods.remove("Qt")
for mod in mods:
try:
psmods.append(self.load_module(".".join(base + [mod])))
psmods.append(self.create_module(name='.'.join(base + [mod])))
except ImportError:
pass
patch_main_modules(psmods)
Expand Down