diff options
author | Martin Robinson <mrobinson@igalia.com> | 2023-06-15 12:34:27 +0200 |
---|---|---|
committer | Martin Robinson <mrobinson@igalia.com> | 2023-06-15 13:10:06 +0200 |
commit | 81433a8684d078ae629ba24f30f877028e361136 (patch) | |
tree | c974ac6f5741138f4926e02ca6a3f35abfc46738 /python | |
parent | fa266abd29688833e1ffa5995230e5a6c30161f6 (diff) | |
download | servo-81433a8684d078ae629ba24f30f877028e361136.tar.gz servo-81433a8684d078ae629ba24f30f877028e361136.zip |
Convert tidy to a non-egg Python package
It seems that servo-tidy is only used by webrender in my GitHub
searches. WebRender could simply use `rustfmt` and the tidy on pypi
hasn't been updated since 2018. Converting tidy to a normal Python
package removes the maintenance burden of continually fixing the easy
install configuration.
Fixes #29094.
Fixes #29334.
Diffstat (limited to 'python')
-rw-r--r-- | python/mach_bootstrap.py | 1 | ||||
-rw-r--r-- | python/requirements.txt | 4 | ||||
-rw-r--r-- | python/servo/lints/wpt_lint.py | 45 | ||||
-rw-r--r-- | python/servo/testing_commands.py | 6 | ||||
-rw-r--r-- | python/tidy/HISTORY.rst | 31 | ||||
-rw-r--r-- | python/tidy/Makefile | 25 | ||||
-rw-r--r-- | python/tidy/README.rst | 26 | ||||
-rw-r--r-- | python/tidy/__init__.py (renamed from python/tidy/servo_tidy_tests/__init__.py) | 3 | ||||
-rw-r--r-- | python/tidy/licenseck.py (renamed from python/tidy/servo_tidy/licenseck.py) | 0 | ||||
-rw-r--r-- | python/tidy/setup.py | 60 | ||||
-rw-r--r-- | python/tidy/test.py (renamed from python/tidy/servo_tidy_tests/test_tidy.py) | 58 | ||||
-rw-r--r-- | python/tidy/tests/Cargo.toml (renamed from python/tidy/servo_tidy_tests/Cargo.toml) | 0 | ||||
-rw-r--r-- | python/tidy/tests/__init__.py (renamed from python/tidy/servo_tidy/__init__.py) | 0 | ||||
-rw-r--r-- | python/tidy/tests/apache2_license.rs (renamed from python/tidy/servo_tidy_tests/apache2_license.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tests/ban-domrefcell.rs (renamed from python/tidy/servo_tidy_tests/ban-domrefcell.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tests/ban.rs (renamed from python/tidy/servo_tidy_tests/ban.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tests/blocked_package.lock (renamed from python/tidy/servo_tidy_tests/blocked_package.lock) | 0 | ||||
-rw-r--r-- | python/tidy/tests/dir_check/only_webidl/test.webidl (renamed from python/tidy/servo_tidy_tests/dir_check/only_webidl/test.webidl) | 0 | ||||
-rw-r--r-- | python/tidy/tests/dir_check/webidl_plus/test.rs (renamed from python/tidy/servo_tidy_tests/dir_check/webidl_plus/test.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tests/dir_check/webidl_plus/test.test (renamed from python/tidy/servo_tidy_tests/dir_check/webidl_plus/test.test) | 0 | ||||
-rw-r--r-- | python/tidy/tests/dir_check/webidl_plus/test.webidl (renamed from python/tidy/servo_tidy_tests/dir_check/webidl_plus/test.webidl) | 0 | ||||
-rw-r--r-- | python/tidy/tests/dir_check/webidl_plus/test2.rs (renamed from python/tidy/servo_tidy_tests/dir_check/webidl_plus/test2.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tests/duplicate_key.json (renamed from python/tidy/servo_tidy_tests/duplicate_key.json) | 0 | ||||
-rw-r--r-- | python/tidy/tests/duplicate_keys_buildbot_steps.yml (renamed from python/tidy/servo_tidy_tests/duplicate_keys_buildbot_steps.yml) | 0 | ||||
-rw-r--r-- | python/tidy/tests/duplicated_package.lock (renamed from python/tidy/servo_tidy_tests/duplicated_package.lock) | 0 | ||||
-rw-r--r-- | python/tidy/tests/empty_file.rs (renamed from python/tidy/servo_tidy_tests/empty_file.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tests/incorrect_license.rs (renamed from python/tidy/servo_tidy_tests/incorrect_license.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tests/lib.rs (renamed from python/tidy/servo_tidy_tests/lib.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tests/lints/invalid_error_tuple.py (renamed from python/tidy/servo_tidy_tests/lints/invalid_error_tuple.py) | 0 | ||||
-rw-r--r-- | python/tidy/tests/lints/no_lint.py (renamed from python/tidy/servo_tidy_tests/lints/no_lint.py) | 0 | ||||
-rw-r--r-- | python/tidy/tests/lints/no_run.py (renamed from python/tidy/servo_tidy_tests/lints/no_run.py) | 0 | ||||
-rw-r--r-- | python/tidy/tests/lints/not_inherited.py (renamed from python/tidy/servo_tidy_tests/lints/not_inherited.py) | 0 | ||||
-rw-r--r-- | python/tidy/tests/lints/not_script (renamed from python/tidy/servo_tidy_tests/lints/not_script) | 0 | ||||
-rw-r--r-- | python/tidy/tests/lints/proper_file.py (renamed from python/tidy/servo_tidy_tests/lints/proper_file.py) | 0 | ||||
-rw-r--r-- | python/tidy/tests/long_line.rs (renamed from python/tidy/servo_tidy_tests/long_line.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tests/malformed_json.json (renamed from python/tidy/servo_tidy_tests/malformed_json.json) | 0 | ||||
-rw-r--r-- | python/tidy/tests/manifest-include.ini (renamed from python/tidy/servo_tidy_tests/manifest-include.ini) | 0 | ||||
-rw-r--r-- | python/tidy/tests/modeline.txt (renamed from python/tidy/servo_tidy_tests/modeline.txt) | 0 | ||||
-rw-r--r-- | python/tidy/tests/multiline_string.rs (renamed from python/tidy/servo_tidy_tests/multiline_string.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tests/non_list_mapping_buildbot_steps.yml (renamed from python/tidy/servo_tidy_tests/non_list_mapping_buildbot_steps.yml) | 0 | ||||
-rw-r--r-- | python/tidy/tests/non_string_list_buildbot_steps.yml (renamed from python/tidy/servo_tidy_tests/non_string_list_buildbot_steps.yml) | 0 | ||||
-rw-r--r-- | python/tidy/tests/rust_tidy.rs (renamed from python/tidy/servo_tidy_tests/rust_tidy.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tests/servo-tidy.toml (renamed from python/tidy/servo_tidy_tests/servo-tidy.toml) | 0 | ||||
-rw-r--r-- | python/tidy/tests/shebang_license.py (renamed from python/tidy/servo_tidy_tests/shebang_license.py) | 0 | ||||
-rw-r--r-- | python/tidy/tests/shell_tidy.sh (renamed from python/tidy/servo_tidy_tests/shell_tidy.sh) | 0 | ||||
-rw-r--r-- | python/tidy/tests/spec.webidl (renamed from python/tidy/servo_tidy_tests/spec.webidl) | 0 | ||||
-rw-r--r-- | python/tidy/tests/speclink.rs (renamed from python/tidy/servo_tidy_tests/speclink.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tests/test_ignored/whee/foo/bar.rs (renamed from python/tidy/servo_tidy_tests/test_ignored/whee/foo/bar.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tests/test_ignored/whee/test.rs (renamed from python/tidy/servo_tidy_tests/test_ignored/whee/test.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tests/unordered_key.json (renamed from python/tidy/servo_tidy_tests/unordered_key.json) | 0 | ||||
-rw-r--r-- | python/tidy/tests/whatwg_link.rs (renamed from python/tidy/servo_tidy_tests/whatwg_link.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tests/wrong_space.rs (renamed from python/tidy/servo_tidy_tests/wrong_space.rs) | 0 | ||||
-rw-r--r-- | python/tidy/tidy.py (renamed from python/tidy/servo_tidy/tidy.py) | 70 |
53 files changed, 65 insertions, 264 deletions
diff --git a/python/mach_bootstrap.py b/python/mach_bootstrap.py index 06d5377aa84..dec54260839 100644 --- a/python/mach_bootstrap.py +++ b/python/mach_bootstrap.py @@ -14,7 +14,6 @@ from subprocess import Popen from tempfile import TemporaryFile SEARCH_PATHS = [ - os.path.join("python", "tidy"), os.path.join("python", "mach"), ] diff --git a/python/requirements.txt b/python/requirements.txt index bbf19513285..f172613fc1e 100644 --- a/python/requirements.txt +++ b/python/requirements.txt @@ -39,4 +39,6 @@ notify-py == 0.3.42 # For formatting C++ files. clang-format ~= 16.0.0 --e python/tidy +# A few more requirements for tidy. +voluptuous == 0.12.1 +PyYAML == 5.4 diff --git a/python/servo/lints/wpt_lint.py b/python/servo/lints/wpt_lint.py deleted file mode 100644 index ada03b65a99..00000000000 --- a/python/servo/lints/wpt_lint.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2013 The Servo Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution. -# -# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -from __future__ import print_function - -import os -import sys - -from servo_tidy.tidy import LintRunner, filter_file - -WPT_PATH = os.path.join(".", "tests", "wpt") -SUITES = ["web-platform-tests", os.path.join("mozilla", "tests")] - - -class Lint(LintRunner): - def _get_wpt_files(self, suite): - working_dir = os.path.join(WPT_PATH, suite, '') - file_iter = self.get_files(working_dir, exclude_dirs=[]) - print('\nRunning the WPT lint on %s...' % working_dir) - for f in file_iter: - if filter_file(f): - yield f[len(working_dir):] - - def run(self): - if self.stylo or self.no_wpt: - return - - wpt_working_dir = os.path.abspath(os.path.join(WPT_PATH, "web-platform-tests")) - for suite in SUITES: - files = list(self._get_wpt_files(suite)) - if not files: - continue - sys.path.insert(0, wpt_working_dir) - from tools.lint import lint - file_dir = os.path.abspath(os.path.join(WPT_PATH, suite)) - returncode = lint.lint(file_dir, files, output_format="json") - sys.path.remove(wpt_working_dir) - if returncode: - yield ("WPT Lint Tool", "", "lint error(s) in Web Platform Tests: exit status %s" % returncode) diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py index 6ed56465ecc..291a00b15c0 100644 --- a/python/servo/testing_commands.py +++ b/python/servo/testing_commands.py @@ -31,14 +31,12 @@ from mach.decorators import ( CommandProvider, Command, ) +import tidy -from servo_tidy import tidy from servo.command_base import ( CommandBase, call, check_call, check_output, ) -from servo_tidy_tests import test_tidy - from servo.util import delete from distutils.dir_util import copy_tree @@ -298,7 +296,7 @@ class MachCommands(CommandBase): help="Only handle files in the stylo tree") def test_tidy(self, all_files, no_progress, self_test, stylo, force_cpp=False, no_wpt=False): if self_test: - return test_tidy.do_tests() + return tidy.do_tests() else: if no_wpt: manifest_dirty = False diff --git a/python/tidy/HISTORY.rst b/python/tidy/HISTORY.rst deleted file mode 100644 index e2330d8ad33..00000000000 --- a/python/tidy/HISTORY.rst +++ /dev/null @@ -1,31 +0,0 @@ -Release History ---------------- - -0.3.0 (2017-02-24) -++++++++++++++++++ - -- Added checking for blocked packages -- Added checking for alphabetical order for JSON keys and ``#![feature(...)]`` -- Improved duplicated packages checking -- Improved ordering ``use`` statements -- Allow tidy to run custom project-specific lints -- And many other improvements - -0.2.0 (2016-08-09) -++++++++++++++++++ - -- Improve license checking to disregard comments and line breaks -- License checking verifies that COPYRIGHT is specified when apache2 is used - -0.0.3 (2016-04-19) -++++++++++++++++++ - -- Add alternate wording of apache2 license - -0.0.2 (2016-04-17) -++++++++++++++++++ -- Cleanup Tidy to work on external deps - -0.0.1 (2016-04-12) -++++++++++++++++++ -- Package Tidy diff --git a/python/tidy/Makefile b/python/tidy/Makefile deleted file mode 100644 index 9637aa10d98..00000000000 --- a/python/tidy/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -PYTHON := python -VENV := env-$(PYTHON) - -# for travis - -$(VENV)/bin/python: - [ -d $(VENV) ] || $(PYTHON) -m virtualenv $(VENV) || virtualenv $(VENV) - $(VENV)/bin/pip install --upgrade setuptools - $(VENV)/bin/python setup.py develop - - -.PHONY: dev-env -dev-env: $(VENV)/bin/python - - -# for testing -.PHONY: test -test: dev-env - $(VENV)/bin/python -m unittest discover -s servo_tidy_tests -v - - -.PHONY: clean -clean: - find . -name "*.pyc" -type f -delete - rm -rf $(VENV) diff --git a/python/tidy/README.rst b/python/tidy/README.rst deleted file mode 100644 index 06c0bc71309..00000000000 --- a/python/tidy/README.rst +++ /dev/null @@ -1,26 +0,0 @@ -servo_tidy -========== - -Servo's code and license checker. - -Installation -++++++++++++ - -Install from PyPI: - -:: - - pip install servo-tidy - -or from git: - -:: - - pip install -e git+https://github.com/servo/servo.git#egg=servo_tidy&subdirectory=python/tidy - -To run the tests -++++++++++++++++ - -:: - - ./mach test-tidy --self-test diff --git a/python/tidy/servo_tidy_tests/__init__.py b/python/tidy/__init__.py index 6b6351ddd2b..74a15acad8f 100644 --- a/python/tidy/servo_tidy_tests/__init__.py +++ b/python/tidy/__init__.py @@ -6,3 +6,6 @@ # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your # option. This file may not be copied, modified, or distributed # except according to those terms. + +from .tidy import scan # noqa +from .test import do_tests # noqa diff --git a/python/tidy/servo_tidy/licenseck.py b/python/tidy/licenseck.py index deeaeb55333..deeaeb55333 100644 --- a/python/tidy/servo_tidy/licenseck.py +++ b/python/tidy/licenseck.py diff --git a/python/tidy/setup.py b/python/tidy/setup.py deleted file mode 100644 index 17c6172acbc..00000000000 --- a/python/tidy/setup.py +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright 2013 The Servo Project Developers. See the COPYRIGHT -# file at the top-level directory of this distribution. -# -# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -import os -from setuptools import setup, find_packages - - -VERSION = '0.3.0' - -install_requires = [ - "flake8==3.8.3", - "toml==0.9.2", - "colorama==0.3.7", - "voluptuous==0.12.1", - "PyYAML==5.4", -] - -here = os.path.dirname(os.path.abspath(__file__)) -# get documentation from the README and HISTORY -try: - with open(os.path.join(here, 'README.rst')) as doc: - readme = doc.read() -except Exception: - readme = '' - -try: - with open(os.path.join(here, 'HISTORY.rst')) as doc: - history = doc.read() -except Exception: - history = '' - -long_description = readme + '\n\n' + history - -if __name__ == '__main__': - setup( - name='servo_tidy', - version=VERSION, - description='The servo-tidy is used to check licenses, ' - 'line lengths, whitespace, flake8 on Python files, lock file versions, and more.', - long_description=long_description, - keywords='mozilla servo tidy ', - author='The Servo Project Developers', - author_email='dev-servo@lists.mozilla.org', - url='https://github.com/servo/servo', - packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), - package_data={}, - install_requires=install_requires, - zip_safe=False, - entry_points={ - 'console_scripts': [ - 'servo-tidy=servo_tidy.tidy:scan', - ], - }, - ) diff --git a/python/tidy/servo_tidy_tests/test_tidy.py b/python/tidy/test.py index 6138320cc35..49c83579c93 100644 --- a/python/tidy/servo_tidy_tests/test_tidy.py +++ b/python/tidy/test.py @@ -10,13 +10,14 @@ import os import unittest -from servo_tidy import tidy +from . import tidy -base_path = 'servo_tidy_tests/' if os.path.exists('servo_tidy_tests/') else 'python/tidy/servo_tidy_tests/' + +BASE_PATH = 'python/tidy/tests/' def iterFile(name): - return iter([os.path.join(base_path, name)]) + return iter([os.path.join(BASE_PATH, name)]) class CheckTidiness(unittest.TestCase): @@ -25,7 +26,7 @@ class CheckTidiness(unittest.TestCase): next(errors) def test_tidy_config(self): - errors = tidy.check_config_file(os.path.join(base_path, 'servo-tidy.toml'), print_text=False) + errors = tidy.check_config_file(os.path.join(BASE_PATH, 'servo-tidy.toml'), print_text=False) self.assertEqual("invalid config key 'key-outside'", next(errors)[2]) self.assertEqual("invalid config key 'wrong-key'", next(errors)[2]) self.assertEqual('invalid config table [wrong]', next(errors)[2]) @@ -38,17 +39,17 @@ class CheckTidiness(unittest.TestCase): errors = tidy.check_manifest_dirs(wrong_path, print_text=False) self.assertEqual("%s manifest file is required but was not found" % wrong_path, next(errors)[2]) self.assertNoMoreErrors(errors) - errors = tidy.check_manifest_dirs(os.path.join(base_path, 'manifest-include.ini'), print_text=False) + errors = tidy.check_manifest_dirs(os.path.join(BASE_PATH, 'manifest-include.ini'), print_text=False) self.assertTrue(next(errors)[2].endswith("never_going_to_exist")) self.assertNoMoreErrors(errors) def test_directory_checks(self): dirs = { - os.path.join(base_path, "dir_check/webidl_plus"): ['webidl', 'test'], - os.path.join(base_path, "dir_check/only_webidl"): ['webidl'] - } + os.path.join(BASE_PATH, "dir_check/webidl_plus"): ['webidl', 'test'], + os.path.join(BASE_PATH, "dir_check/only_webidl"): ['webidl'] + } errors = tidy.check_directory_files(dirs) - error_dir = os.path.join(base_path, "dir_check/webidl_plus") + error_dir = os.path.join(BASE_PATH, "dir_check/webidl_plus") self.assertEqual("Unexpected extension found for test.rs. We only expect files with webidl, test extensions in {0}".format(error_dir), next(errors)[2]) self.assertEqual("Unexpected extension found for test2.rs. We only expect files with webidl, test extensions in {0}".format(error_dir), next(errors)[2]) self.assertNoMoreErrors(errors) @@ -136,7 +137,7 @@ class CheckTidiness(unittest.TestCase): self.assertNoMoreErrors(ban_errors) def test_spec_link(self): - tidy.SPEC_BASE_PATH = base_path + tidy.SPEC_BASE_PATH = BASE_PATH errors = tidy.collect_errors_for_files(iterFile('speclink.rs'), [], [tidy.check_spec], print_text=False) self.assertEqual('method declared in webidl is missing a comment with a specification link', next(errors)[2]) self.assertEqual('method declared in webidl is missing a comment with a specification link', next(errors)[2]) @@ -173,7 +174,7 @@ class CheckTidiness(unittest.TestCase): self.assertNoMoreErrors(errors) def test_json_with_unordered_keys(self): - tidy.config["check-ordered-json-keys"].append('python/tidy/servo_tidy_tests/unordered_key.json') + tidy.config["check-ordered-json-keys"].append('python/tidy/tests/unordered_key.json') errors = tidy.collect_errors_for_files(iterFile('unordered_key.json'), [tidy.check_json], [], print_text=False) self.assertEqual('Unordered key (found b before a)', next(errors)[2]) self.assertNoMoreErrors(errors) @@ -246,38 +247,15 @@ class CheckTidiness(unittest.TestCase): # needed to not raise errors in other test cases tidy.config["blocked-packages"]["rand"] = [] - def test_lint_runner(self): - test_path = base_path + 'lints/' - runner = tidy.LintRunner(only_changed_files=False, progress=False) - runner.path = test_path + 'some-fictional-file' - self.assertEqual([(runner.path, 0, "file does not exist")], list(runner.check())) - runner.path = test_path + 'not_script' - self.assertEqual([(runner.path, 0, "lint should be a python script")], - list(runner.check())) - runner.path = test_path + 'not_inherited.py' - self.assertEqual([(runner.path, 1, "class 'Lint' should inherit from 'LintRunner'")], - list(runner.check())) - runner.path = test_path + 'no_lint.py' - self.assertEqual([(runner.path, 1, "script should contain a class named 'Lint'")], - list(runner.check())) - runner.path = test_path + 'no_run.py' - self.assertEqual([(runner.path, 0, "class 'Lint' should implement 'run' method")], - list(runner.check())) - runner.path = test_path + 'invalid_error_tuple.py' - self.assertEqual([(runner.path, 1, "errors should be a tuple of (path, line, reason)")], - list(runner.check())) - runner.path = test_path + 'proper_file.py' - self.assertEqual([('path', 0, "foobar")], list(runner.check())) - def test_file_list(self): - base_path='./python/tidy/servo_tidy_tests/test_ignored' - file_list = tidy.FileList(base_path, only_changed_files=False, exclude_dirs=[]) + file_path = os.path.join(BASE_PATH, 'test_ignored') + file_list = tidy.FileList(file_path, only_changed_files=False, exclude_dirs=[]) lst = list(file_list) - self.assertEqual([os.path.join(base_path, 'whee', 'test.rs'), os.path.join(base_path, 'whee', 'foo', 'bar.rs')], lst) - file_list = tidy.FileList(base_path, only_changed_files=False, - exclude_dirs=[os.path.join(base_path, 'whee', 'foo')]) + self.assertEqual([os.path.join(file_path, 'whee', 'test.rs'), os.path.join(file_path, 'whee', 'foo', 'bar.rs')], lst) + file_list = tidy.FileList(file_path, only_changed_files=False, + exclude_dirs=[os.path.join(file_path, 'whee', 'foo')]) lst = list(file_list) - self.assertEqual([os.path.join(base_path, 'whee', 'test.rs')], lst) + self.assertEqual([os.path.join(file_path, 'whee', 'test.rs')], lst) def test_multiline_string(self): errors = tidy.collect_errors_for_files(iterFile('multiline_string.rs'), [], [tidy.check_rust], print_text=True) diff --git a/python/tidy/servo_tidy_tests/Cargo.toml b/python/tidy/tests/Cargo.toml index c664352e45f..c664352e45f 100644 --- a/python/tidy/servo_tidy_tests/Cargo.toml +++ b/python/tidy/tests/Cargo.toml diff --git a/python/tidy/servo_tidy/__init__.py b/python/tidy/tests/__init__.py index 6b6351ddd2b..6b6351ddd2b 100644 --- a/python/tidy/servo_tidy/__init__.py +++ b/python/tidy/tests/__init__.py diff --git a/python/tidy/servo_tidy_tests/apache2_license.rs b/python/tidy/tests/apache2_license.rs index c9fed89cf73..c9fed89cf73 100644 --- a/python/tidy/servo_tidy_tests/apache2_license.rs +++ b/python/tidy/tests/apache2_license.rs diff --git a/python/tidy/servo_tidy_tests/ban-domrefcell.rs b/python/tidy/tests/ban-domrefcell.rs index 9bfc9ba8938..9bfc9ba8938 100644 --- a/python/tidy/servo_tidy_tests/ban-domrefcell.rs +++ b/python/tidy/tests/ban-domrefcell.rs diff --git a/python/tidy/servo_tidy_tests/ban.rs b/python/tidy/tests/ban.rs index 9da46d2ee53..9da46d2ee53 100644 --- a/python/tidy/servo_tidy_tests/ban.rs +++ b/python/tidy/tests/ban.rs diff --git a/python/tidy/servo_tidy_tests/blocked_package.lock b/python/tidy/tests/blocked_package.lock index 521fdfcfb74..521fdfcfb74 100644 --- a/python/tidy/servo_tidy_tests/blocked_package.lock +++ b/python/tidy/tests/blocked_package.lock diff --git a/python/tidy/servo_tidy_tests/dir_check/only_webidl/test.webidl b/python/tidy/tests/dir_check/only_webidl/test.webidl index e69de29bb2d..e69de29bb2d 100644 --- a/python/tidy/servo_tidy_tests/dir_check/only_webidl/test.webidl +++ b/python/tidy/tests/dir_check/only_webidl/test.webidl diff --git a/python/tidy/servo_tidy_tests/dir_check/webidl_plus/test.rs b/python/tidy/tests/dir_check/webidl_plus/test.rs index e69de29bb2d..e69de29bb2d 100644 --- a/python/tidy/servo_tidy_tests/dir_check/webidl_plus/test.rs +++ b/python/tidy/tests/dir_check/webidl_plus/test.rs diff --git a/python/tidy/servo_tidy_tests/dir_check/webidl_plus/test.test b/python/tidy/tests/dir_check/webidl_plus/test.test index e69de29bb2d..e69de29bb2d 100644 --- a/python/tidy/servo_tidy_tests/dir_check/webidl_plus/test.test +++ b/python/tidy/tests/dir_check/webidl_plus/test.test diff --git a/python/tidy/servo_tidy_tests/dir_check/webidl_plus/test.webidl b/python/tidy/tests/dir_check/webidl_plus/test.webidl index e69de29bb2d..e69de29bb2d 100644 --- a/python/tidy/servo_tidy_tests/dir_check/webidl_plus/test.webidl +++ b/python/tidy/tests/dir_check/webidl_plus/test.webidl diff --git a/python/tidy/servo_tidy_tests/dir_check/webidl_plus/test2.rs b/python/tidy/tests/dir_check/webidl_plus/test2.rs index e69de29bb2d..e69de29bb2d 100644 --- a/python/tidy/servo_tidy_tests/dir_check/webidl_plus/test2.rs +++ b/python/tidy/tests/dir_check/webidl_plus/test2.rs diff --git a/python/tidy/servo_tidy_tests/duplicate_key.json b/python/tidy/tests/duplicate_key.json index 6998c789ac9..6998c789ac9 100644 --- a/python/tidy/servo_tidy_tests/duplicate_key.json +++ b/python/tidy/tests/duplicate_key.json diff --git a/python/tidy/servo_tidy_tests/duplicate_keys_buildbot_steps.yml b/python/tidy/tests/duplicate_keys_buildbot_steps.yml index ed5d046095f..ed5d046095f 100644 --- a/python/tidy/servo_tidy_tests/duplicate_keys_buildbot_steps.yml +++ b/python/tidy/tests/duplicate_keys_buildbot_steps.yml diff --git a/python/tidy/servo_tidy_tests/duplicated_package.lock b/python/tidy/tests/duplicated_package.lock index 22acce4257c..22acce4257c 100644 --- a/python/tidy/servo_tidy_tests/duplicated_package.lock +++ b/python/tidy/tests/duplicated_package.lock diff --git a/python/tidy/servo_tidy_tests/empty_file.rs b/python/tidy/tests/empty_file.rs index e69de29bb2d..e69de29bb2d 100644 --- a/python/tidy/servo_tidy_tests/empty_file.rs +++ b/python/tidy/tests/empty_file.rs diff --git a/python/tidy/servo_tidy_tests/incorrect_license.rs b/python/tidy/tests/incorrect_license.rs index cf85f0e2623..cf85f0e2623 100644 --- a/python/tidy/servo_tidy_tests/incorrect_license.rs +++ b/python/tidy/tests/incorrect_license.rs diff --git a/python/tidy/servo_tidy_tests/lib.rs b/python/tidy/tests/lib.rs index 5fea057b5c5..5fea057b5c5 100644 --- a/python/tidy/servo_tidy_tests/lib.rs +++ b/python/tidy/tests/lib.rs diff --git a/python/tidy/servo_tidy_tests/lints/invalid_error_tuple.py b/python/tidy/tests/lints/invalid_error_tuple.py index 4851cdf402c..4851cdf402c 100644 --- a/python/tidy/servo_tidy_tests/lints/invalid_error_tuple.py +++ b/python/tidy/tests/lints/invalid_error_tuple.py diff --git a/python/tidy/servo_tidy_tests/lints/no_lint.py b/python/tidy/tests/lints/no_lint.py index e9f84aa9f3c..e9f84aa9f3c 100644 --- a/python/tidy/servo_tidy_tests/lints/no_lint.py +++ b/python/tidy/tests/lints/no_lint.py diff --git a/python/tidy/servo_tidy_tests/lints/no_run.py b/python/tidy/tests/lints/no_run.py index 2acd5db1fee..2acd5db1fee 100644 --- a/python/tidy/servo_tidy_tests/lints/no_run.py +++ b/python/tidy/tests/lints/no_run.py diff --git a/python/tidy/servo_tidy_tests/lints/not_inherited.py b/python/tidy/tests/lints/not_inherited.py index fc38dff2c58..fc38dff2c58 100644 --- a/python/tidy/servo_tidy_tests/lints/not_inherited.py +++ b/python/tidy/tests/lints/not_inherited.py diff --git a/python/tidy/servo_tidy_tests/lints/not_script b/python/tidy/tests/lints/not_script index e69de29bb2d..e69de29bb2d 100644 --- a/python/tidy/servo_tidy_tests/lints/not_script +++ b/python/tidy/tests/lints/not_script diff --git a/python/tidy/servo_tidy_tests/lints/proper_file.py b/python/tidy/tests/lints/proper_file.py index acecb82abd4..acecb82abd4 100644 --- a/python/tidy/servo_tidy_tests/lints/proper_file.py +++ b/python/tidy/tests/lints/proper_file.py diff --git a/python/tidy/servo_tidy_tests/long_line.rs b/python/tidy/tests/long_line.rs index 6427aa50878..6427aa50878 100644 --- a/python/tidy/servo_tidy_tests/long_line.rs +++ b/python/tidy/tests/long_line.rs diff --git a/python/tidy/servo_tidy_tests/malformed_json.json b/python/tidy/tests/malformed_json.json index 9b1cf7cbd88..9b1cf7cbd88 100644 --- a/python/tidy/servo_tidy_tests/malformed_json.json +++ b/python/tidy/tests/malformed_json.json diff --git a/python/tidy/servo_tidy_tests/manifest-include.ini b/python/tidy/tests/manifest-include.ini index ade00f2fa31..ade00f2fa31 100644 --- a/python/tidy/servo_tidy_tests/manifest-include.ini +++ b/python/tidy/tests/manifest-include.ini diff --git a/python/tidy/servo_tidy_tests/modeline.txt b/python/tidy/tests/modeline.txt index 2a3416953ce..2a3416953ce 100644 --- a/python/tidy/servo_tidy_tests/modeline.txt +++ b/python/tidy/tests/modeline.txt diff --git a/python/tidy/servo_tidy_tests/multiline_string.rs b/python/tidy/tests/multiline_string.rs index 0a4d2fa87ee..0a4d2fa87ee 100644 --- a/python/tidy/servo_tidy_tests/multiline_string.rs +++ b/python/tidy/tests/multiline_string.rs diff --git a/python/tidy/servo_tidy_tests/non_list_mapping_buildbot_steps.yml b/python/tidy/tests/non_list_mapping_buildbot_steps.yml index 2581aa21d88..2581aa21d88 100644 --- a/python/tidy/servo_tidy_tests/non_list_mapping_buildbot_steps.yml +++ b/python/tidy/tests/non_list_mapping_buildbot_steps.yml diff --git a/python/tidy/servo_tidy_tests/non_string_list_buildbot_steps.yml b/python/tidy/tests/non_string_list_buildbot_steps.yml index d9255e7cfe5..d9255e7cfe5 100644 --- a/python/tidy/servo_tidy_tests/non_string_list_buildbot_steps.yml +++ b/python/tidy/tests/non_string_list_buildbot_steps.yml diff --git a/python/tidy/servo_tidy_tests/rust_tidy.rs b/python/tidy/tests/rust_tidy.rs index abd533d5807..abd533d5807 100644 --- a/python/tidy/servo_tidy_tests/rust_tidy.rs +++ b/python/tidy/tests/rust_tidy.rs diff --git a/python/tidy/servo_tidy_tests/servo-tidy.toml b/python/tidy/tests/servo-tidy.toml index 690098b0e44..690098b0e44 100644 --- a/python/tidy/servo_tidy_tests/servo-tidy.toml +++ b/python/tidy/tests/servo-tidy.toml diff --git a/python/tidy/servo_tidy_tests/shebang_license.py b/python/tidy/tests/shebang_license.py index f913d5ee1e4..f913d5ee1e4 100644 --- a/python/tidy/servo_tidy_tests/shebang_license.py +++ b/python/tidy/tests/shebang_license.py diff --git a/python/tidy/servo_tidy_tests/shell_tidy.sh b/python/tidy/tests/shell_tidy.sh index e38358fc3b6..e38358fc3b6 100644 --- a/python/tidy/servo_tidy_tests/shell_tidy.sh +++ b/python/tidy/tests/shell_tidy.sh diff --git a/python/tidy/servo_tidy_tests/spec.webidl b/python/tidy/tests/spec.webidl index 83ce8f935c3..83ce8f935c3 100644 --- a/python/tidy/servo_tidy_tests/spec.webidl +++ b/python/tidy/tests/spec.webidl diff --git a/python/tidy/servo_tidy_tests/speclink.rs b/python/tidy/tests/speclink.rs index 499953e7bda..499953e7bda 100644 --- a/python/tidy/servo_tidy_tests/speclink.rs +++ b/python/tidy/tests/speclink.rs diff --git a/python/tidy/servo_tidy_tests/test_ignored/whee/foo/bar.rs b/python/tidy/tests/test_ignored/whee/foo/bar.rs index e69de29bb2d..e69de29bb2d 100644 --- a/python/tidy/servo_tidy_tests/test_ignored/whee/foo/bar.rs +++ b/python/tidy/tests/test_ignored/whee/foo/bar.rs diff --git a/python/tidy/servo_tidy_tests/test_ignored/whee/test.rs b/python/tidy/tests/test_ignored/whee/test.rs index e69de29bb2d..e69de29bb2d 100644 --- a/python/tidy/servo_tidy_tests/test_ignored/whee/test.rs +++ b/python/tidy/tests/test_ignored/whee/test.rs diff --git a/python/tidy/servo_tidy_tests/unordered_key.json b/python/tidy/tests/unordered_key.json index 36f0a13f9c2..36f0a13f9c2 100644 --- a/python/tidy/servo_tidy_tests/unordered_key.json +++ b/python/tidy/tests/unordered_key.json diff --git a/python/tidy/servo_tidy_tests/whatwg_link.rs b/python/tidy/tests/whatwg_link.rs index d6ed712450a..d6ed712450a 100644 --- a/python/tidy/servo_tidy_tests/whatwg_link.rs +++ b/python/tidy/tests/whatwg_link.rs diff --git a/python/tidy/servo_tidy_tests/wrong_space.rs b/python/tidy/tests/wrong_space.rs index be735e2d463..be735e2d463 100644 --- a/python/tidy/servo_tidy_tests/wrong_space.rs +++ b/python/tidy/tests/wrong_space.rs diff --git a/python/tidy/servo_tidy/tidy.py b/python/tidy/tidy.py index 7c45bb63d93..1e5de4080c0 100644 --- a/python/tidy/servo_tidy/tidy.py +++ b/python/tidy/tidy.py @@ -7,11 +7,8 @@ # option. This file may not be copied, modified, or distributed # except according to those terms. -from __future__ import print_function - import fnmatch import glob -import imp import itertools import json import os @@ -23,13 +20,16 @@ import colorama import toml import voluptuous import yaml + from .licenseck import OLD_MPL, MPL, APACHE, COPYRIGHT, licenses_toml, licenses_dep_toml -topdir = os.path.abspath(os.path.dirname(sys.argv[0])) -wpt = os.path.join(topdir, "tests", "wpt") + +TOPDIR = os.path.abspath(os.path.dirname(sys.argv[0])) +WPT_PATH = os.path.join(".", "tests", "wpt") +SUITES = ["web-platform-tests", os.path.join("mozilla", "tests")] def wpt_path(*args): - return os.path.join(wpt, *args) + return os.path.join(WPT_PATH, *args) CONFIG_FILE_PATH = os.path.join(".", "servo-tidy.toml") @@ -1084,27 +1084,10 @@ class LintRunner(object): self.stylo = stylo self.no_wpt = no_wpt - def check(self): - if not os.path.exists(self.path): - yield (self.path, 0, "file does not exist") - return - if not self.path.endswith('.py'): - yield (self.path, 0, "lint should be a python script") - return - dir_name, filename = os.path.split(self.path) - sys.path.append(dir_name) - module = imp.load_source(filename[:-3], self.path) - sys.path.remove(dir_name) - if not hasattr(module, 'Lint'): - yield (self.path, 1, "script should contain a class named 'Lint'") - return - - if not issubclass(module.Lint, LintRunner): - yield (self.path, 1, "class 'Lint' should inherit from 'LintRunner'") - return - - lint = module.Lint(self.path, self.only_changed_files, - self.exclude_dirs, self.progress, stylo=self.stylo, no_wpt=self.no_wpt) + def check(self, lint_cls): + lint = lint_cls(self.path, self.only_changed_files, + self.exclude_dirs, self.progress, + stylo=self.stylo, no_wpt=self.no_wpt) for error in lint.run(): if type(error) is not tuple or (type(error) is tuple and len(error) != 3): yield (self.path, 1, "errors should be a tuple of (path, line, reason)") @@ -1122,10 +1105,8 @@ class LintRunner(object): def run_lint_scripts(only_changed_files=False, progress=True, stylo=False, no_wpt=False): runner = LintRunner(only_changed_files=only_changed_files, progress=progress, stylo=stylo, no_wpt=no_wpt) - for path in config['lint-scripts']: - runner.path = path - for error in runner.check(): - yield error + for error in runner.check(WPTLint): + yield error def scan(only_changed_files=False, progress=True, stylo=False, no_wpt=False): @@ -1162,3 +1143,30 @@ def scan(only_changed_files=False, progress=True, stylo=False, no_wpt=False): print("\033[92mtidy reported no errors.\033[0m") return int(error is not None) + + +class WPTLint(LintRunner): + def _get_wpt_files(self, suite): + working_dir = os.path.join(WPT_PATH, suite, '') + file_iter = self.get_files(working_dir, exclude_dirs=[]) + print('\nRunning the WPT lint on %s...' % working_dir) + for f in file_iter: + if filter_file(f): + yield f[len(working_dir):] + + def run(self): + if self.stylo or self.no_wpt: + return + + wpt_working_dir = os.path.abspath(os.path.join(WPT_PATH, "web-platform-tests")) + for suite in SUITES: + files = list(self._get_wpt_files(suite)) + if not files: + continue + sys.path.insert(0, wpt_working_dir) + from tools.lint import lint + file_dir = os.path.abspath(os.path.join(WPT_PATH, suite)) + returncode = lint.lint(file_dir, files, output_format="json") + sys.path.remove(wpt_working_dir) + if returncode: + yield ("WPT Lint Tool", "", "lint error(s) in Web Platform Tests: exit status %s" % returncode) |