From c2d04c1e6a5eb1872ce7d2624f3fde45b5002e13 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 17 Jun 2022 16:42:21 +0200 Subject: scripts: Add check for direct PyQt imports --- scripts/dev/misc_checks.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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, -- cgit v1.2.3-54-g00ecf