From 1eab6ca02dd8e91a1eb5b38b8c95cab9945562cd Mon Sep 17 00:00:00 2001 From: askeing Date: Sun, 17 Apr 2016 02:00:13 +0900 Subject: [PATCH 1/8] Add dependency on flake8 base on python/requirements.txt --- python/tidy/setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/tidy/setup.py b/python/tidy/setup.py index 81b788e6c14..f3525a3c07d 100644 --- a/python/tidy/setup.py +++ b/python/tidy/setup.py @@ -14,6 +14,7 @@ from setuptools import setup, find_packages VERSION = '0.0.1' install_requires = [ + "flake8==2.4.1", ] here = os.path.dirname(os.path.abspath(__file__)) From c723ac64013ec78bd03414da0d5d10e589e048d7 Mon Sep 17 00:00:00 2001 From: askeing Date: Sun, 17 Apr 2016 02:12:28 +0900 Subject: [PATCH 2/8] Add dependency on toml base on python/requirements.txt --- python/tidy/setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/tidy/setup.py b/python/tidy/setup.py index f3525a3c07d..958e5dd55c5 100644 --- a/python/tidy/setup.py +++ b/python/tidy/setup.py @@ -15,6 +15,7 @@ VERSION = '0.0.1' install_requires = [ "flake8==2.4.1", + "toml==0.9.1", ] here = os.path.dirname(os.path.abspath(__file__)) From 922840852a016e454f1834833a35a365ef475805 Mon Sep 17 00:00:00 2001 From: askeing Date: Sun, 17 Apr 2016 02:58:01 +0900 Subject: [PATCH 3/8] Add "servo-tidy" entry point - also update requriements "pyflakes" from 0.8 to 0.8.1 due to following issue ``` Traceback (most recent call last): File "/Users/Askeing/software/servo/python/_virtualenv/bin/servo-tidy", line 5, in from pkg_resources import load_entry_point File "/Users/Askeing/software/servo/python/_virtualenv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3084, in @_call_aside File "/Users/Askeing/software/servo/python/_virtualenv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3070, in _call_aside f(*args, **kwargs) File "/Users/Askeing/software/servo/python/_virtualenv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3097, in _initialize_master_working_set working_set = WorkingSet._build_master() File "/Users/Askeing/software/servo/python/_virtualenv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 653, in _build_master return cls._build_from_requirements(__requires__) File "/Users/Askeing/software/servo/python/_virtualenv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 666, in _build_from_requirements dists = ws.resolve(reqs, Environment()) File "/Users/Askeing/software/servo/python/_virtualenv/lib/python2.7/site-packages/pkg_resources/__init__.py", line 839, in resolve raise DistributionNotFound(req, requirers) pkg_resources.DistributionNotFound: The 'pyflakes==0.8.1' distribution was not found and is required by servo-tidy ``` --- python/requirements.txt | 2 +- python/tidy/setup.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/python/requirements.txt b/python/requirements.txt index 58726e8f5ca..4a2d9bbd480 100644 --- a/python/requirements.txt +++ b/python/requirements.txt @@ -9,7 +9,7 @@ toml == 0.9.1 # For Python linting flake8 == 2.4.1 pep8 == 1.5.7 -pyflakes == 0.8.0 +pyflakes == 0.8.1 # For test-webidl ply == 3.8 diff --git a/python/tidy/setup.py b/python/tidy/setup.py index 958e5dd55c5..5b280fb21a4 100644 --- a/python/tidy/setup.py +++ b/python/tidy/setup.py @@ -49,4 +49,9 @@ if __name__ == '__main__': package_data={}, install_requires=install_requires, zip_safe=False, + entry_points={ + 'console_scripts': [ + 'servo-tidy=servo_tidy.tidy:scan' + ], + }, ) From 88c94f285eca66c62678b8f847d6a4f38ea53e3c Mon Sep 17 00:00:00 2001 From: askeing Date: Sun, 17 Apr 2016 03:27:50 +0900 Subject: [PATCH 4/8] Check the "tests/wpt/web-platform-tests" folder before loading "tools.lint" module --- python/tidy/servo_tidy/tidy.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/python/tidy/servo_tidy/tidy.py b/python/tidy/servo_tidy/tidy.py index 43c4eb6dc69..56c07aeae6b 100644 --- a/python/tidy/servo_tidy/tidy.py +++ b/python/tidy/servo_tidy/tidy.py @@ -601,11 +601,12 @@ def get_wpt_files(only_changed_files, progress): def check_wpt_lint_errors(files): wpt_working_dir = os.path.abspath(os.path.join(".", "tests", "wpt", "web-platform-tests")) - site.addsitedir(wpt_working_dir) - from tools.lint import lint - returncode = lint.lint(files) - if returncode: - yield ("WPT Lint Tool", "", "lint error(s) in Web Platform Tests: exit status {0}".format(returncode)) + if os.path.isdir(wpt_working_dir): + site.addsitedir(wpt_working_dir) + from tools.lint import lint + returncode = lint.lint(files) + if returncode: + yield ("WPT Lint Tool", "", "lint error(s) in Web Platform Tests: exit status {0}".format(returncode)) def get_file_list(directory, only_changed_files=False, exclude_dirs=[]): From 22d991d4e0b39dd0cb8d05215e181ac8ef957aab Mon Sep 17 00:00:00 2001 From: Maciej Skrzypkowski Date: Wed, 13 Apr 2016 12:18:13 +0200 Subject: [PATCH 5/8] Test for check_spec function, for tidy.py #9152 --- python/tidy/servo_tidy/tidy.py | 7 ++++--- python/tidy/servo_tidy_tests/test_tidy.py | 5 +++++ python/tidy_self_test/speclink.rs | 9 +++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 python/tidy_self_test/speclink.rs diff --git a/python/tidy/servo_tidy/tidy.py b/python/tidy/servo_tidy/tidy.py index 56c07aeae6b..206346675e2 100644 --- a/python/tidy/servo_tidy/tidy.py +++ b/python/tidy/servo_tidy/tidy.py @@ -69,6 +69,8 @@ ignored_dirs = [ os.path.join(".", "."), ] +spec_base_path = "components/script/dom/" + def is_iter_empty(iterator): try: @@ -525,10 +527,9 @@ def check_json(filename, contents): def check_spec(file_name, lines): - base_path = "components/script/dom/" - if base_path not in file_name: + if spec_base_path not in file_name: raise StopIteration - file_name = os.path.relpath(os.path.splitext(file_name)[0], base_path) + file_name = os.path.relpath(os.path.splitext(file_name)[0], spec_base_path) patt = re.compile("^\s*\/\/.+") # Pattern representing a line with a macro diff --git a/python/tidy/servo_tidy_tests/test_tidy.py b/python/tidy/servo_tidy_tests/test_tidy.py index d0e19daafb1..a183e6a798d 100644 --- a/python/tidy/servo_tidy_tests/test_tidy.py +++ b/python/tidy/servo_tidy_tests/test_tidy.py @@ -61,6 +61,11 @@ class CheckTidiness(unittest.TestCase): self.assertEqual('use &[T] instead of &Vec', errors.next()[2]) self.assertEqual('use &str instead of &String', errors.next()[2]) + def test_spec_link(self): + tidy.spec_base_path = "python/tidy_self_test/" + errors = tidy.collect_errors_for_files(iterFile('speclink.rs'), [], [tidy.check_spec]) + self.assertEqual('method declared in webidl is missing a comment with a specification link', errors.next()[2]) + def test_webidl(self): errors = tidy.collect_errors_for_files(iterFile('spec.webidl'), [tidy.check_webidl_spec], []) self.assertEqual('No specification link found.', errors.next()[2]) diff --git a/python/tidy_self_test/speclink.rs b/python/tidy_self_test/speclink.rs new file mode 100644 index 00000000000..6c27a70a7d0 --- /dev/null +++ b/python/tidy_self_test/speclink.rs @@ -0,0 +1,9 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +impl SpecLinkMethods for SpecLink { + fn Test(&self) -> f32 { + 0 + } +} From 27bac667b21a89a717408b36b14c78d0bdd19a9c Mon Sep 17 00:00:00 2001 From: askeing Date: Sun, 17 Apr 2016 04:20:24 +0900 Subject: [PATCH 6/8] Modified test_spec_link of test_tidy for packaged tidy --- python/tidy/servo_tidy_tests/test_tidy.py | 7 +- .../tidy/servo_tidy_tests/tidy_self_test.py | 78 ------------------- 2 files changed, 4 insertions(+), 81 deletions(-) delete mode 100644 python/tidy/servo_tidy_tests/tidy_self_test.py diff --git a/python/tidy/servo_tidy_tests/test_tidy.py b/python/tidy/servo_tidy_tests/test_tidy.py index a183e6a798d..031e0873a56 100644 --- a/python/tidy/servo_tidy_tests/test_tidy.py +++ b/python/tidy/servo_tidy_tests/test_tidy.py @@ -11,10 +11,11 @@ import os import unittest from servo_tidy import tidy +base_path = 'servo_tidy_tests/' if os.path.exists('servo_tidy_tests/') else 'python/tidy/servo_tidy_tests/' + def iterFile(name): - path = 'servo_tidy_tests/' if os.path.exists('servo_tidy_tests/') else 'python/tidy/servo_tidy_tests/' - return iter([os.path.join(path, name)]) + return iter([os.path.join(base_path, name)]) class CheckTidiness(unittest.TestCase): @@ -62,7 +63,7 @@ class CheckTidiness(unittest.TestCase): self.assertEqual('use &str instead of &String', errors.next()[2]) def test_spec_link(self): - tidy.spec_base_path = "python/tidy_self_test/" + tidy.spec_base_path = base_path errors = tidy.collect_errors_for_files(iterFile('speclink.rs'), [], [tidy.check_spec]) self.assertEqual('method declared in webidl is missing a comment with a specification link', errors.next()[2]) diff --git a/python/tidy/servo_tidy_tests/tidy_self_test.py b/python/tidy/servo_tidy_tests/tidy_self_test.py deleted file mode 100644 index e2a49f71a65..00000000000 --- a/python/tidy/servo_tidy_tests/tidy_self_test.py +++ /dev/null @@ -1,78 +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 or the MIT license -# , at your -# option. This file may not be copied, modified, or distributed -# except according to those terms. - -import unittest -import tidy - - -def iterFile(name): - return iter(['python/tidy_self_test/' + name]) - - -class CheckTidiness(unittest.TestCase): - def test_spaces_correctnes(self): - errors = tidy.collect_errors_for_files(iterFile('wrong_space.rs'), [], [tidy.check_by_line]) - self.assertEqual('trailing whitespace', errors.next()[2]) - self.assertEqual('no newline at EOF', errors.next()[2]) - self.assertEqual('tab on line', errors.next()[2]) - self.assertEqual('CR on line', errors.next()[2]) - - def test_long_line(self): - errors = tidy.collect_errors_for_files(iterFile('long_line.rs'), [], [tidy.check_by_line]) - self.assertEqual('Line is longer than 120 characters', errors.next()[2]) - - def test_whatwg_link(self): - errors = tidy.collect_errors_for_files(iterFile('whatwg_link.rs'), [], [tidy.check_by_line]) - self.assertTrue('link to WHATWG may break in the future, use this format instead:' in errors.next()[2]) - self.assertTrue('links to WHATWG single-page url, change to multi page:' in errors.next()[2]) - - def test_licence(self): - errors = tidy.collect_errors_for_files(iterFile('incorrect_license.rs'), [], [tidy.check_license]) - self.assertEqual('incorrect license', errors.next()[2]) - - def test_rust(self): - errors = tidy.collect_errors_for_files(iterFile('rust_tidy.rs'), [], [tidy.check_rust]) - self.assertEqual('use statement spans multiple lines', errors.next()[2]) - self.assertEqual('missing space before }', errors.next()[2]) - self.assertTrue('use statement is not in alphabetical order' in errors.next()[2]) - self.assertEqual('encountered whitespace following a use statement', errors.next()[2]) - self.assertTrue('mod declaration is not in alphabetical order' in errors.next()[2]) - self.assertEqual('mod declaration spans multiple lines', errors.next()[2]) - self.assertTrue('extern crate declaration is not in alphabetical order' in errors.next()[2]) - self.assertEqual('missing space before ->', errors.next()[2]) - self.assertEqual('missing space after ->', errors.next()[2]) - self.assertEqual('missing space after :', errors.next()[2]) - self.assertEqual('missing space before {', errors.next()[2]) - self.assertEqual('missing space before =', errors.next()[2]) - self.assertEqual('missing space after =', errors.next()[2]) - self.assertEqual('missing space before -', errors.next()[2]) - self.assertEqual('missing space before *', errors.next()[2]) - self.assertEqual('missing space after =>', errors.next()[2]) - self.assertEqual('extra space before :', errors.next()[2]) - self.assertEqual('extra space before :', errors.next()[2]) - self.assertEqual('use &[T] instead of &Vec', errors.next()[2]) - self.assertEqual('use &str instead of &String', errors.next()[2]) - - def test_spec_link(self): - tidy.spec_base_path = "python/tidy_self_test/" - errors = tidy.collect_errors_for_files(iterFile('speclink.rs'), [], [tidy.check_spec]) - self.assertEqual('method declared in webidl is missing a comment with a specification link', errors.next()[2]) - - def test_webidl(self): - errors = tidy.collect_errors_for_files(iterFile('spec.webidl'), [tidy.check_webidl_spec], []) - self.assertEqual('No specification link found.', errors.next()[2]) - - def test_toml(self): - errors = tidy.collect_errors_for_files(iterFile('test.toml'), [tidy.check_toml], []) - self.assertEqual('found asterisk instead of minimum version number', errors.next()[2]) - - -def do_tests(): - suite = unittest.TestLoader().loadTestsFromTestCase(CheckTidiness) - unittest.TextTestRunner(verbosity=2).run(suite) From eb9a7e5c110f0a494859c3285f234680aa5ea1ca Mon Sep 17 00:00:00 2001 From: askeing Date: Sun, 17 Apr 2016 04:33:24 +0900 Subject: [PATCH 7/8] bump the minor version of servo_tidy - and add clean folder into Makefile --- python/tidy/HISTORY.rst | 4 ++++ python/tidy/Makefile | 3 +-- python/tidy/setup.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/python/tidy/HISTORY.rst b/python/tidy/HISTORY.rst index 13cc05fe665..1e02962afa0 100644 --- a/python/tidy/HISTORY.rst +++ b/python/tidy/HISTORY.rst @@ -1,6 +1,10 @@ Release History --------------- +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 index 33f3b499fc8..9637aa10d98 100644 --- a/python/tidy/Makefile +++ b/python/tidy/Makefile @@ -22,5 +22,4 @@ test: dev-env .PHONY: clean clean: find . -name "*.pyc" -type f -delete - - + rm -rf $(VENV) diff --git a/python/tidy/setup.py b/python/tidy/setup.py index 5b280fb21a4..86aae654b3c 100644 --- a/python/tidy/setup.py +++ b/python/tidy/setup.py @@ -11,7 +11,7 @@ import os from setuptools import setup, find_packages -VERSION = '0.0.1' +VERSION = '0.0.2' install_requires = [ "flake8==2.4.1", From f5754b102c3abf2f7f4259f937353ebf972c9553 Mon Sep 17 00:00:00 2001 From: askeing Date: Sun, 17 Apr 2016 04:44:28 +0900 Subject: [PATCH 8/8] Remove "python/tidy_self_test/speclink.rs" - it already move to "python/tidy/servo_tidy_tests/speclink.rs" --- python/tidy_self_test/speclink.rs | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 python/tidy_self_test/speclink.rs diff --git a/python/tidy_self_test/speclink.rs b/python/tidy_self_test/speclink.rs deleted file mode 100644 index 6c27a70a7d0..00000000000 --- a/python/tidy_self_test/speclink.rs +++ /dev/null @@ -1,9 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -impl SpecLinkMethods for SpecLink { - fn Test(&self) -> f32 { - 0 - } -}