Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit adf7eb1

Browse files
committed
test: test Python scripts against different Qt dependencies
1 parent b1aec1e commit adf7eb1

File tree

17 files changed

+230
-111
lines changed

17 files changed

+230
-111
lines changed

python/.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ persistent=yes
8282

8383
# Minimum Python version to use for version dependent checks. Will default to
8484
# the version used to run pylint.
85-
py-version=3.9
85+
py-version=3.10
8686

8787
# Discover python modules and packages in the file system subtree.
8888
recursive=no

python/.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"[python]": {
99
"editor.defaultFormatter": "ms-python.python"
1010
},
11+
"python.analysis.autoImportCompletions": true,
1112
"python.formatting.provider": "black",
1213
"python.linting.enabled": true,
1314
"python.linting.pylintEnabled": true,

python/scripts/designer.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
# pylint: disable=import-error
1+
# pylint: disable=import-error,ungrouped-imports
22

33
import sys
44

5-
from utils import is_installed
5+
from utils import is_installed, parse_qt_dependency
66

77
if __name__ == "__main__":
8-
if is_installed("PySide6"):
8+
dep = parse_qt_dependency()
9+
if dep == "PySide6":
10+
from PySide6.scripts.pyside_tool import designer
11+
elif dep == "PySide2":
12+
from PySide2.scripts.pyside_tool import designer
13+
14+
elif is_installed("PySide6"):
915
from PySide6.scripts.pyside_tool import designer
1016
elif is_installed("PySide2"):
1117
from PySide2.scripts.pyside_tool import designer

python/scripts/lupdate.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
# pylint: disable=import-error
1+
# pylint: disable=import-error,ungrouped-imports
22

33
import sys
44

5-
from utils import is_installed
5+
from utils import is_installed, parse_qt_dependency
66

77
if __name__ == "__main__":
8-
if is_installed("PySide6"):
8+
dep = parse_qt_dependency()
9+
if dep == "PySide6":
10+
from PySide6.scripts.pyside_tool import lupdate
11+
elif dep == "PySide2":
12+
sys.argv[0] = "pyside2-lupdate"
13+
from PySide2.scripts.pyside_tool import main as lupdate
14+
elif dep == "PyQt6":
15+
from PyQt6.lupdate.pylupdate import main as lupdate
16+
elif dep == "PyQt5":
17+
from PyQt5.pylupdate_main import main as lupdate
18+
19+
elif is_installed("PySide6"):
920
from PySide6.scripts.pyside_tool import lupdate
1021
elif is_installed("PySide2"):
1122
sys.argv[0] = "pyside2-lupdate"

python/scripts/qml.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
# pylint: disable=import-error
1+
# pylint: disable=import-error,ungrouped-imports
22

33
import sys
44

5-
from utils import is_installed
5+
from utils import is_installed, parse_qt_dependency
66

77
if __name__ == "__main__":
8-
if is_installed("PySide6"):
8+
dep = parse_qt_dependency()
9+
if dep == "PySide6":
10+
from PySide6.scripts.pyside_tool import qml
11+
12+
elif is_installed("PySide6"):
913
from PySide6.scripts.pyside_tool import qml
1014
else:
1115
sys.exit("No pyside6-qml can be found in current Python environment.")

python/scripts/qmlls.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
import sys
44

5-
from utils import is_installed
5+
from utils import is_installed, parse_qt_dependency
66

77
if __name__ == "__main__":
8-
if is_installed("PySide6"):
8+
dep = parse_qt_dependency()
9+
if dep == "PySide6":
10+
from PySide6.scripts.pyside_tool import qmlls
11+
12+
elif is_installed("PySide6"):
913
from PySide6.scripts.pyside_tool import qmlls
1014
else:
1115
sys.exit("No qmlls can be found in current Python environment.")

python/scripts/rcc.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
# pylint: disable=import-error
1+
# pylint: disable=import-error,ungrouped-imports
22

33
import sys
44

5-
from utils import is_installed
5+
from utils import is_installed, parse_qt_dependency
66

77
if __name__ == "__main__":
8-
if is_installed("PySide6"):
8+
dep = parse_qt_dependency()
9+
if dep == "PySide6":
10+
from PySide6.scripts.pyside_tool import rcc
11+
elif dep == "PySide2":
12+
from PySide2.scripts.pyside_tool import rcc
13+
elif dep == "PyQt5":
14+
from PyQt5.pyrcc_main import main as rcc
15+
16+
elif is_installed("PySide6"):
917
from PySide6.scripts.pyside_tool import rcc
1018
elif is_installed("PySide2"):
1119
from PySide2.scripts.pyside_tool import rcc

python/scripts/uic.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
# pylint: disable=import-error
1+
# pylint: disable=import-error,ungrouped-imports
22

33
import sys
44

5-
from utils import is_installed
5+
from utils import is_installed, parse_qt_dependency
66

77
if __name__ == "__main__":
8-
if is_installed("PySide6"):
8+
dep = parse_qt_dependency()
9+
if dep == "PySide6":
10+
from PySide6.scripts.pyside_tool import uic
11+
elif dep == "PySide2":
12+
from PySide2.scripts.pyside_tool import uic
13+
elif dep == "PyQt6":
14+
from PyQt6.uic.pyuic import main as uic
15+
elif dep == "PyQt5":
16+
from PyQt5.uic.pyuic import main as uic
17+
18+
elif is_installed("PySide6"):
919
from PySide6.scripts.pyside_tool import uic
1020
elif is_installed("PySide2"):
1121
from PySide2.scripts.pyside_tool import uic

python/scripts/utils/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
1+
import argparse
12
import importlib.util
23
import sys
4+
import typing
5+
6+
QT_DEPENDENCY_ARG = "vscode_extension_qt_dependency"
7+
8+
SupportedQtDependencies = typing.Optional[
9+
typing.Literal["PySide6", "PySide2", "PyQt6", "PyQt5"]
10+
]
311

412

513
def is_installed(name: str) -> bool:
614
return name in sys.modules or importlib.util.find_spec(name) is not None
15+
16+
17+
def parse_qt_dependency() -> SupportedQtDependencies:
18+
parser = argparse.ArgumentParser(add_help=False)
19+
parser.add_argument(
20+
f"--{QT_DEPENDENCY_ARG}",
21+
required=False,
22+
)
23+
24+
if dep := vars(parser.parse_known_args()[0])[QT_DEPENDENCY_ARG]:
25+
sys.argv.remove(f"--{QT_DEPENDENCY_ARG}")
26+
sys.argv.remove(dep)
27+
28+
return dep
29+
return None

python/tests/__init__.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
11
import os
2+
import platform
3+
import subprocess
4+
import typing
5+
6+
from scripts.utils import QT_DEPENDENCY_ARG, SupportedQtDependencies
27

38
TESTS_DIR = os.path.dirname(os.path.realpath(__file__))
49

510
SCRIPTS_DIR = os.path.join(TESTS_DIR, os.pardir, "scripts")
611

712
ASSETS_DIR = os.path.join(TESTS_DIR, "assets")
13+
14+
SupportedScripts = typing.Literal["designer", "lupdate", "qml", "qmlls", "rcc", "uic"]
15+
16+
17+
def filter_available_qt_dependencies(
18+
deps: list[SupportedQtDependencies],
19+
) -> list[SupportedQtDependencies]:
20+
if platform.system() == "Darwin" and platform.machine() == "arm64":
21+
return [None] + list(filter(lambda d: d in ("PySide2", "PyQt5"), deps))
22+
return [None] + deps
23+
24+
25+
def invoke_script(
26+
name: SupportedScripts,
27+
args: list[str],
28+
qt_dependency: SupportedQtDependencies,
29+
):
30+
if qt_dependency is not None:
31+
args.append(f"--{QT_DEPENDENCY_ARG}")
32+
args.append(qt_dependency)
33+
34+
return subprocess.run(
35+
["poetry", "run", "python", f"{name}.py", *args],
36+
cwd=SCRIPTS_DIR,
37+
capture_output=True,
38+
check=False,
39+
)

0 commit comments

Comments
 (0)