From d48d85324effb28b032781065b7649ec7dc06be6 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 28 Jun 2023 22:37:28 +0200 Subject: qt6: Reduce duplicate misc_checks.py code --- scripts/dev/misc_checks.py | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/scripts/dev/misc_checks.py b/scripts/dev/misc_checks.py index db4137dff..215a1cfa0 100644 --- a/scripts/dev/misc_checks.py +++ b/scripts/dev/misc_checks.py @@ -27,7 +27,7 @@ import subprocess import tokenize import traceback import pathlib -from typing import List, Iterator, Optional +from typing import List, Iterator, Optional, Tuple REPO_ROOT = pathlib.Path(__file__).resolve().parents[2] sys.path.insert(0, str(REPO_ROOT)) @@ -152,6 +152,24 @@ def _check_spelling_file(path, fobj, patterns): return ok +def _check_spelling_all( + args: argparse.Namespace, + ignored: List[pathlib.Path], + patterns: List[Tuple[re.Pattern, str]], +) -> Optional[bool]: + 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_spelling(args: argparse.Namespace) -> Optional[bool]: """Check commonly misspelled words.""" # Words which I often misspell @@ -273,18 +291,7 @@ def check_spelling(args: argparse.Namespace) -> Optional[bool]: hint_data / 'ace' / 'ace.js', hint_data / 'bootstrap' / 'bootstrap.css', ] - - try: - ok = True - for path in _get_files(verbose=args.verbose, ignored=ignored): - with tokenize.open(path) as f: - if not _check_spelling_file(path, f, patterns): - ok = False - print() - return ok - except Exception: - traceback.print_exc() - return None + return _check_spelling_all(args=args, ignored=ignored, patterns=patterns) def check_pyqt_imports(args: argparse.Namespace) -> Optional[bool]: @@ -304,18 +311,7 @@ def check_pyqt_imports(args: argparse.Namespace) -> Optional[bool]: "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 + return _check_spelling_all(args=args, ignored=ignored, patterns=patterns) def check_vcs_conflict(args: argparse.Namespace) -> Optional[bool]: -- cgit v1.2.3-54-g00ecf