diff options
Diffstat (limited to 'python')
-rw-r--r-- | python/README.md | 2 | ||||
-rw-r--r-- | python/requirements.txt | 6 | ||||
-rw-r--r-- | python/tidy/tidy.py | 24 | ||||
-rw-r--r-- | python/tox.ini | 3 |
4 files changed, 15 insertions, 20 deletions
diff --git a/python/README.md b/python/README.md index b79a4b2e8ea..d97dc6d6ddd 100644 --- a/python/README.md +++ b/python/README.md @@ -8,7 +8,7 @@ is the canonical repository for this code. # `tidy` -servo-tidy is used to check licenses, line lengths, whitespace, flake8 on +servo-tidy is used to check licenses, line lengths, whitespace, ruff on Python files, lock file versions, and more. # `wpt` diff --git a/python/requirements.txt b/python/requirements.txt index d64f33add3c..c5e1a0c9bbb 100644 --- a/python/requirements.txt +++ b/python/requirements.txt @@ -8,10 +8,8 @@ mozlog == 8.0.0 setuptools == 78.1.1 toml == 0.9.2 -# For Python linting -flake8 == 7.0.0 -pep8 == 1.5.7 -pyflakes == 3.2.0 +# For Python linting and formatting +ruff == 0.11.10 # For test-webidl ply == 3.8 diff --git a/python/tidy/tidy.py b/python/tidy/tidy.py index fe44be23df8..98062e77683 100644 --- a/python/tidy/tidy.py +++ b/python/tidy/tidy.py @@ -356,19 +356,18 @@ def check_by_line(file_name: str, lines: list[bytes]): yield error -def check_flake8(file_name, contents): - if not file_name.endswith(".py"): - return - - output = "" +def check_ruff_lints(): try: - args = ["flake8", file_name] + args = ["ruff", "check", "--output-format", "json"] subprocess.check_output(args, universal_newlines=True) except subprocess.CalledProcessError as e: - output = e.output - for error in output.splitlines(): - _, line_num, _, message = error.split(":", 3) - yield line_num, message.strip() + for error in json.loads(e.output): + yield ( + os.path.join(".", os.path.relpath(error["filename"])), + error["location"]["row"], + f"[{error['code']}] {error['message']} ({error['url']})", + ) + def run_cargo_deny_lints(): @@ -976,17 +975,18 @@ def scan(only_changed_files=False, progress=False): directory_errors = check_directory_files(config['check_ext']) # standard checks files_to_check = filter_files('.', only_changed_files, progress) - checking_functions = (check_flake8, check_webidl_spec) + checking_functions = (check_webidl_spec,) line_checking_functions = (check_license, check_by_line, check_toml, check_shell, check_rust, check_spec, check_modeline) file_errors = collect_errors_for_files(files_to_check, checking_functions, line_checking_functions) + python_errors = check_ruff_lints() cargo_lock_errors = run_cargo_deny_lints() wpt_errors = run_wpt_lints(only_changed_files) # chain all the iterators errors = itertools.chain(config_errors, directory_errors, file_errors, - wpt_errors, cargo_lock_errors) + python_errors, wpt_errors, cargo_lock_errors) colorama.init() error = None diff --git a/python/tox.ini b/python/tox.ini deleted file mode 100644 index e684cc63d8b..00000000000 --- a/python/tox.ini +++ /dev/null @@ -1,3 +0,0 @@ -[flake8] -filename = *.py -max-line-length = 120 |