qturcompiler 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: qturcompiler
3
+ Version: 0.1.0
4
+ Summary: A universal compiler for Qt UI and resource files (.ui, .qrc) to Python modules
5
+ Author-email: MagIlyasDOMA <magilyas.doma.09@list.ru>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/MagIlyasDOMA/qturcompiler
8
+ Keywords: qt,compiler,uic,rcc,pyside,pyqt
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Topic :: Software Development :: Code Generators
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
@@ -0,0 +1,31 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "qturcompiler"
7
+ version = "0.1.0"
8
+ description = "A universal compiler for Qt UI and resource files (.ui, .qrc) to Python modules"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = {text = "MIT"}
12
+ authors = [
13
+ {name = "MagIlyasDOMA", email = "magilyas.doma.09@list.ru"}
14
+ ]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Operating System :: OS Independent",
19
+ "Topic :: Software Development :: Code Generators",
20
+ ]
21
+ keywords = ["qt", "compiler", "uic", "rcc", "pyside", "pyqt"]
22
+ dependencies = []
23
+
24
+ [project.scripts]
25
+ qtup = "qturcompiler:main"
26
+
27
+ [project.urls]
28
+ Homepage = "https://github.com/MagIlyasDOMA/qturcompiler"
29
+
30
+ [tool.setuptools]
31
+ py-modules = ["qturcompiler"]
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: qturcompiler
3
+ Version: 0.1.0
4
+ Summary: A universal compiler for Qt UI and resource files (.ui, .qrc) to Python modules
5
+ Author-email: MagIlyasDOMA <magilyas.doma.09@list.ru>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/MagIlyasDOMA/qturcompiler
8
+ Keywords: qt,compiler,uic,rcc,pyside,pyqt
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Topic :: Software Development :: Code Generators
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
@@ -0,0 +1,7 @@
1
+ pyproject.toml
2
+ qturcompiler.py
3
+ qturcompiler.egg-info/PKG-INFO
4
+ qturcompiler.egg-info/SOURCES.txt
5
+ qturcompiler.egg-info/dependency_links.txt
6
+ qturcompiler.egg-info/entry_points.txt
7
+ qturcompiler.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ qtup = qturcompiler:main
@@ -0,0 +1 @@
1
+ qturcompiler
@@ -0,0 +1,98 @@
1
+ import argparse
2
+ import subprocess
3
+ from os.path import splitext
4
+ from importlib.metadata import metadata as get_package_metadata, PackageNotFoundError
5
+ from typing import Literal, get_args
6
+ from pathlib import Path
7
+
8
+ QtLibraries = Literal['pyside6', 'pyqt6', 'pyqt5', 'pyside2']
9
+ FileType = Literal['ui', 'qrc']
10
+ COMPILERS = {
11
+ 'ui': {
12
+ 'pyside6': 'pyside6-uic',
13
+ 'pyqt6': 'pyuic6',
14
+ 'pyqt5': 'pyuic5',
15
+ 'pyside2': 'pyside2-uic',
16
+ },
17
+ 'qrc': {
18
+ 'pyside6': 'pyside6-rcc',
19
+ 'pyqt6': 'pyrcc6',
20
+ 'pyside2': 'pyside2-rcc',
21
+ }
22
+ }
23
+
24
+
25
+ class QtNotFound(Exception): pass
26
+
27
+
28
+ class IncorrectFileType(Exception): pass
29
+
30
+
31
+ def is_package_installed(package: str) -> bool:
32
+ try: get_package_metadata(package)
33
+ except PackageNotFoundError: return False
34
+ else: return True
35
+
36
+
37
+ def get_qt_lib():
38
+ for package in get_args(QtLibraries):
39
+ if is_package_installed(package):
40
+ return package
41
+ raise QtNotFound
42
+
43
+
44
+ def get_compiler(filetype: FileType, qtlib: QtLibraries = None):
45
+ if qtlib is None: qtlib = get_qt_lib()
46
+ return COMPILERS[filetype][qtlib]
47
+
48
+
49
+ def qtur_file(value) -> Path:
50
+ value = Path(value)
51
+ if not value.is_file(): raise FileNotFoundError(value)
52
+ if value.suffix not in ('.qrc', '.ui'): raise IncorrectFileType(value)
53
+ return value
54
+
55
+
56
+ def main():
57
+ parser = argparse.ArgumentParser(
58
+ description="Compile Qt UI (.ui) and resource (.qrc) files into Python modules.",
59
+ epilog="If no Qt library is specified, the first installed one from the list "
60
+ "(pyside6, pyqt6, pyqt5, pyside2) is used."
61
+ )
62
+ parser.add_argument('files', nargs='*', type=qtur_file,
63
+ help='.ui or .qrc files to compile')
64
+
65
+ libs_group = parser.add_mutually_exclusive_group()
66
+ libs_group.add_argument('--pyside6', action='store_const', const='pyside6', dest='qtlib',
67
+ help='Use PySide6')
68
+ libs_group.add_argument('--pyqt6', action='store_const', const='pyqt6', dest='qtlib',
69
+ help='Use PyQt6')
70
+ libs_group.add_argument('--pyqt5', action='store_const', const='pyqt5', dest='qtlib',
71
+ help='Use PyQt5')
72
+ libs_group.add_argument('--pyside2', action='store_const', const='pyside2', dest='qtlib',
73
+ help='Use PySide2')
74
+
75
+ try:
76
+ args = parser.parse_args()
77
+ qtlib = args.qtlib or get_qt_lib()
78
+ files = args.files
79
+
80
+ for file in files:
81
+ file: Path
82
+ root, ext = splitext(file)
83
+ filetype: FileType = ext[1:].lower() # type: ignore
84
+
85
+ if filetype == 'qrc' and qtlib == 'pyqt6': parser.error('Resources (.qrc) are not supported in PyQt6')
86
+
87
+ subprocess.run(
88
+ [get_compiler(filetype, qtlib), str(file), '-o', root + '.py'],
89
+ check=True, text=True
90
+ )
91
+
92
+ except Exception as error:
93
+ error_module = error.__class__.__module__
94
+ error_module = '' if error_module == '__main__' else error_module + '.'
95
+ parser.error(f"{error_module}{error.__class__.__name__}: {error}")
96
+
97
+
98
+ if __name__ == '__main__': main()
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+