summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2022-06-17 16:42:21 +0200
committerFlorian Bruhin <me@the-compiler.org>2022-06-22 17:41:12 +0200
commitc2d04c1e6a5eb1872ce7d2624f3fde45b5002e13 (patch)
tree031965724241e8da5e7a273fcb6ab43f6e6efd3b
parentc4022c35e9b6d5b2c25778592172427054ac3a35 (diff)
downloadqutebrowser-c2d04c1e6a5eb1872ce7d2624f3fde45b5002e13.tar.gz
qutebrowser-c2d04c1e6a5eb1872ce7d2624f3fde45b5002e13.zip
scripts: Add check for direct PyQt imports
-rw-r--r--scripts/dev/misc_checks.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/dev/misc_checks.py b/scripts/dev/misc_checks.py
index d6a2b0b12..0e015e03d 100644
--- a/scripts/dev/misc_checks.py
+++ b/scripts/dev/misc_checks.py
@@ -285,6 +285,38 @@ def check_spelling(args: argparse.Namespace) -> Optional[bool]:
return None
+def check_pyqt_imports(args: argparse.Namespace) -> Optional[bool]:
+ """Check for direct PyQt imports."""
+ ignored = [
+ pathlib.Path("qutebrowser", "qt"),
+ # FIXME:qt6 fix those too?
+ pathlib.Path("misc", "userscripts"),
+ pathlib.Path("scripts"),
+ ]
+ patterns = [
+ (
+ re.compile(r"from PyQt.* import"),
+ "Use 'from qutebrowser.qt.MODULE import ...' instead",
+ ),
+ (
+ re.compile(r"import PyQt.*"),
+ "Use 'import qutebrowser.qt.MODULE' instead",
+ )
+ ]
+ # FIXME:qt6 unify this with check_spelling somehow?
+ try:
+ ok = True
+ for path in _get_files(verbose=args.verbose, ignored=ignored):
+ with tokenize.open(str(path)) as f:
+ if not _check_spelling_file(path, f, patterns):
+ ok = False
+ print()
+ return ok
+ except Exception:
+ traceback.print_exc()
+ return None
+
+
def check_vcs_conflict(args: argparse.Namespace) -> Optional[bool]:
"""Check VCS conflict markers."""
try:
@@ -372,6 +404,7 @@ def main() -> int:
'git': check_git,
'vcs': check_vcs_conflict,
'spelling': check_spelling,
+ 'pyqt-imports': check_pyqt_imports,
'userscript-descriptions': check_userscripts_descriptions,
'userscript-shebangs': check_userscript_shebangs,
'changelog-urls': check_changelog_urls,