Debian Codegraph @

src/fenrirscreenreader/utils/module_utils.py

raw
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 # Fenrir TTY screen reader
4 # By Chrys, Storm Dragon, and contributors.
5 import sys
6
7 version = sys.version[:3] # we only need major.minor version.
8 if version in ["3.3", "3.4"]:
9 from importlib.machinery import SourceFileLoader
10 else: # Python 3.5+, no support for python < 3.3.
11 import importlib.util
12
13
14 def import_module(moduleName, moduleLocation):
15 if version in ["3.3", "3.4"]:
16 return SourceFileLoader(moduleName, moduleLocation).load_module()
17 else:
18 spec = importlib.util.spec_from_file_location(
19 moduleName, moduleLocation
20 )
21 driver_mod = importlib.util.module_from_spec(spec)
22 spec.loader.exec_module(driver_mod)
23 return driver_mod