aboutsummaryrefslogtreecommitdiffstats
path: root/python/tidy
diff options
context:
space:
mode:
Diffstat (limited to 'python/tidy')
-rw-r--r--python/tidy/HISTORY.rst4
-rw-r--r--python/tidy/Makefile3
-rw-r--r--python/tidy/servo_tidy/tidy.py18
-rw-r--r--python/tidy/servo_tidy_tests/test_tidy.py10
-rw-r--r--python/tidy/servo_tidy_tests/tidy_self_test.py78
-rw-r--r--python/tidy/setup.py9
6 files changed, 31 insertions, 91 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/servo_tidy/tidy.py b/python/tidy/servo_tidy/tidy.py
index 43c4eb6dc69..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
@@ -601,11 +602,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=[]):
diff --git a/python/tidy/servo_tidy_tests/test_tidy.py b/python/tidy/servo_tidy_tests/test_tidy.py
index d0e19daafb1..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):
@@ -61,6 +62,11 @@ class CheckTidiness(unittest.TestCase):
self.assertEqual('use &[T] instead of &Vec<T>', errors.next()[2])
self.assertEqual('use &str instead of &String', errors.next()[2])
+ def test_spec_link(self):
+ 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])
+
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/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 <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 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<T>', 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)
diff --git a/python/tidy/setup.py b/python/tidy/setup.py
index 81b788e6c14..86aae654b3c 100644
--- a/python/tidy/setup.py
+++ b/python/tidy/setup.py
@@ -11,9 +11,11 @@ import os
from setuptools import setup, find_packages
-VERSION = '0.0.1'
+VERSION = '0.0.2'
install_requires = [
+ "flake8==2.4.1",
+ "toml==0.9.1",
]
here = os.path.dirname(os.path.abspath(__file__))
@@ -47,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'
+ ],
+ },
)