diff options
author | Slávek Banko <slavek.banko@axis.cz> | 2022-07-28 15:26:54 +0200 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2022-07-28 15:26:54 +0200 |
commit | b34531364d5c0d3be7056d87011afd8bd538a0e7 (patch) | |
tree | e3651bce37b4d4564ff424ea381d645bc490f731 /module-init.py | |
parent | 6be046642290c28c17949022fb66ae02ac21d544 (diff) | |
download | pytqt-b34531364d5c0d3be7056d87011afd8bd538a0e7.tar.gz pytqt-b34531364d5c0d3be7056d87011afd8bd538a0e7.zip |
Changed testing for the presence of optional modules,
because simply testing a file with a ".so" extension
does not work on multiarch Python installations.
Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
Diffstat (limited to 'module-init.py')
-rw-r--r-- | module-init.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/module-init.py b/module-init.py index bc5f31b..00bb4e8 100644 --- a/module-init.py +++ b/module-init.py @@ -12,6 +12,23 @@ for m_path in sys.path: for m_path in tqt_modules: sys.path.insert(0, m_path) +# Checking if the module is available +def is_module_available(module_name): + if sys.version_info < (3, 0): + # python 2 + import pkgutil + mod_loader = pkgutil.find_loader(module_name) + if sys.version_info <= (3, 3): + # python 3.0 to 3.3 + import pkgutil + mod_loader = pkgutil.find_loader(module_name) + elif sys.version_info >= (3, 4): + # python 3.4 and above + import importlib.util + mod_loader = importlib.util.find_spec(module_name) + + return mod_loader is not None + # Base modules __all__ = [ 'qt', @@ -24,11 +41,11 @@ __all__ = [ ] # Optional modules -if os.path.exists(os.path.join(m_pyqt_dir, 'qtaxcontainer.so')): +if is_module_available('qtaxcontainer'): __all__.append('qtaxcontainer') -if os.path.exists(os.path.join(m_pyqt_dir, 'qtext.so')): +if is_module_available('qtext'): __all__.append('qtext') -if os.path.exists(os.path.join(m_pyqt_dir, 'qtgl.so')): +if is_module_available('qtgl'): __all__.append('qtgl') # Import namespaces |