__init__.py
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import os
import pathlib
import pkg_resources
import sys
import sysconfig
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
major = int(pkg_resources.get_distribution(__name__.partition('.')[0]).version.partition(".")[0])
# TODO: CAMPid 0970432108721340872130742130870874321
def import_it(*segments):
import importlib
m = {
"pyqt_tools": "pyqt{major}_tools".format(major=major),
"pyqt_plugins": "pyqt{major}_plugins".format(major=major),
"qt_tools": "qt{major}_tools".format(major=major),
"qt_applications": "qt{major}_applications".format(major=major),
"PyQt": "PyQt{major}".format(major=major),
}
majored = [m[segments[0]], *segments[1:]]
return importlib.import_module(".".join(majored))
qt_tools = import_it("qt_tools")
PyQt = import_it("PyQt")
import_it("PyQt", "QtCore")
pyqt_plugins = import_it("pyqt_plugins")
import_it("pyqt_plugins", "utilities")
pyqt_version = tuple(
int(segment)
for segment in PyQt.QtCore.PYQT_VERSION_STR.split('.')
)
root = pathlib.Path(__file__).resolve().parent
# TODO: so apparently qml wants it all lower case...
if sys.platform == 'win32':
root = pathlib.Path(pyqt_plugins.utilities.fspath(root).lower())
plugins = root.joinpath('Qt', 'plugins')
pyqt_root = pathlib.Path(PyQt.__file__).resolve().parent
if pyqt_version >= (6,):
pyqt_qt_root = pyqt_root.joinpath('Qt6')
elif pyqt_version >= (5, 15, 4):
pyqt_qt_root = pyqt_root.joinpath('Qt5')
else:
pyqt_qt_root = pyqt_root.joinpath('Qt')
pyqt_qml_path = pyqt_qt_root.joinpath('qml')
pyqt_plugins_path = pyqt_qt_root.joinpath('plugins')
def create_environment(reference=None):
if reference is None:
reference = dict(os.environ)
environment = qt_tools.create_environment(reference=reference)
if sys.platform in {'linux', 'darwin'}:
environment.update(pyqt_plugins.utilities.add_to_env_var_path_list(
env=environment,
name='LD_LIBRARY_PATH',
before=[],
after=[sysconfig.get_config_var('LIBDIR')],
))
environment.update(pyqt_plugins.utilities.add_to_env_var_path_list(
env=environment,
name='QT_PLUGIN_PATH',
before=[],
after=[
pyqt_plugins.utilities.fspath(pyqt_plugins_path),
pyqt_plugins.utilities.fspath(plugins),
],
))
# TODO: maybe also
# PyQt.QtCore.QLibraryInfo.location(
# PyQt.QtCore.QLibraryInfo.PluginsPath,
# )
environment.update(pyqt_plugins.utilities.add_to_env_var_path_list(
env=environment,
name='PYTHONPATH',
before=sys.path,
after=[''],
))
environment.update(pyqt_plugins.utilities.add_to_env_var_path_list(
env=environment,
name='PATH',
before=sys.path,
after=[''],
))
return environment