aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/tidy/HISTORY.rst6
-rw-r--r--python/tidy/Makefile28
-rw-r--r--python/tidy/README.rst12
-rw-r--r--python/tidy/servo_tidy/__init__.py (renamed from python/tidy/tidy_self_test/__init__.py)0
-rw-r--r--python/tidy/servo_tidy/licenseck.py62
-rw-r--r--python/tidy/servo_tidy/tidy.py (renamed from python/tidy/tidy.py)9
-rw-r--r--python/tidy/setup.py40
-rw-r--r--python/tidy/tests/__init__.py8
-rw-r--r--python/tidy/tests/incorrect_license.rs (renamed from python/tidy/tidy_self_test/incorrect_license.rs)0
-rw-r--r--python/tidy/tests/long_line.rs (renamed from python/tidy/tidy_self_test/long_line.rs)0
-rw-r--r--python/tidy/tests/rust_tidy.rs (renamed from python/tidy/tidy_self_test/rust_tidy.rs)0
-rw-r--r--python/tidy/tests/spec.webidl (renamed from python/tidy/tidy_self_test/spec.webidl)0
-rw-r--r--python/tidy/tests/speclink.rs (renamed from python/tidy/tidy_self_test/speclink.rs)0
-rw-r--r--python/tidy/tests/test.toml (renamed from python/tidy/tidy_self_test/test.toml)0
-rw-r--r--python/tidy/tests/test_tidy.py73
-rw-r--r--python/tidy/tests/tidy_self_test.py (renamed from python/tidy/tidy_self_test/tidy_self_test.py)0
-rw-r--r--python/tidy/tests/whatwg_link.rs (renamed from python/tidy/tidy_self_test/whatwg_link.rs)0
-rw-r--r--python/tidy/tests/wrong_space.rs (renamed from python/tidy/tidy_self_test/wrong_space.rs)0
18 files changed, 233 insertions, 5 deletions
diff --git a/python/tidy/HISTORY.rst b/python/tidy/HISTORY.rst
new file mode 100644
index 00000000000..13cc05fe665
--- /dev/null
+++ b/python/tidy/HISTORY.rst
@@ -0,0 +1,6 @@
+Release History
+---------------
+
+0.0.1 (2016-04-12)
+++++++++++++++++++
+- Package Tidy
diff --git a/python/tidy/Makefile b/python/tidy/Makefile
new file mode 100644
index 00000000000..b047dea9a8f
--- /dev/null
+++ b/python/tidy/Makefile
@@ -0,0 +1,28 @@
+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/pip install --upgrade funcsigs
+ $(VENV)/bin/pip install --upgrade mock
+ $(VENV)/bin/python -m unittest discover -s tests -v
+
+
+.PHONY: clean
+clean:
+ find . -name "*.pyc" -type f -delete
+
+
diff --git a/python/tidy/README.rst b/python/tidy/README.rst
new file mode 100644
index 00000000000..2d9f0e8f6e8
--- /dev/null
+++ b/python/tidy/README.rst
@@ -0,0 +1,12 @@
+servo_tidy
+==========
+
+Servo's code and license checker.
+
+Install from PyPI (coming soon) or
+
+```
+pip install -e git+https://github.com/servo/servo.git#egg=servo_tidy&subdirectory=python/tidy
+```
+
+
diff --git a/python/tidy/tidy_self_test/__init__.py b/python/tidy/servo_tidy/__init__.py
index 6b6351ddd2b..6b6351ddd2b 100644
--- a/python/tidy/tidy_self_test/__init__.py
+++ b/python/tidy/servo_tidy/__init__.py
diff --git a/python/tidy/servo_tidy/licenseck.py b/python/tidy/servo_tidy/licenseck.py
new file mode 100644
index 00000000000..705faf8bcb6
--- /dev/null
+++ b/python/tidy/servo_tidy/licenseck.py
@@ -0,0 +1,62 @@
+# 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.
+
+
+# These licenses are valid for use in Servo
+licenses = [
+
+"""\
+/* 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/. */
+""",
+
+"""\
+# 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/.
+""",
+
+"""\
+#!/usr/bin/env python
+
+# 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/.
+""",
+
+"""\
+// 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/.
+""",
+
+"""\
+// 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.
+""",
+
+"""\
+# 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.
+""",
+
+] # noqa: Indicate to flake8 that we do not want to check indentation here
diff --git a/python/tidy/tidy.py b/python/tidy/servo_tidy/tidy.py
index e12eeb33e49..6110a9ea4eb 100644
--- a/python/tidy/tidy.py
+++ b/python/tidy/servo_tidy/tidy.py
@@ -69,8 +69,6 @@ ignored_dirs = [
os.path.join(".", "."),
]
-spec_base_path = "components/script/dom/"
-
def is_iter_empty(iterator):
try:
@@ -223,7 +221,7 @@ def check_lock(file_name, contents):
raise StopIteration
# package names to be neglected (as named by cargo)
- exceptions = ["bitflags", "xml-rs"]
+ exceptions = ["bitflags", "xml-rs", "byteorder"]
import toml
content = toml.loads(contents)
@@ -527,9 +525,10 @@ def check_json(filename, contents):
def check_spec(file_name, lines):
- if spec_base_path not in file_name:
+ base_path = "components/script/dom/"
+ if base_path not in file_name:
raise StopIteration
- file_name = os.path.relpath(os.path.splitext(file_name)[0], spec_base_path)
+ file_name = os.path.relpath(os.path.splitext(file_name)[0], base_path)
patt = re.compile("^\s*\/\/.+")
# Pattern representing a line with a macro
diff --git a/python/tidy/setup.py b/python/tidy/setup.py
new file mode 100644
index 00000000000..7221e6c1463
--- /dev/null
+++ b/python/tidy/setup.py
@@ -0,0 +1,40 @@
+import os
+from setuptools import setup, find_packages
+
+
+VERSION = '0.0.1'
+
+install_requires = [
+]
+
+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:
+ readme = ''
+
+try:
+ with open(os.path.join(here, 'HISTORY.rst')) as doc:
+ history = doc.read()
+except:
+ history = ''
+
+long_description = readme + '\n\n' + history
+
+if __name__ == '__main__':
+ setup(
+ name='servo_tidy',
+ version=VERSION,
+ description='The tidy package of Servo',
+ 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_tindy',
+ packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
+ package_data={},
+ install_requires=install_requires,
+ zip_safe=False,
+ )
diff --git a/python/tidy/tests/__init__.py b/python/tidy/tests/__init__.py
new file mode 100644
index 00000000000..6b6351ddd2b
--- /dev/null
+++ b/python/tidy/tests/__init__.py
@@ -0,0 +1,8 @@
+# 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.
diff --git a/python/tidy/tidy_self_test/incorrect_license.rs b/python/tidy/tests/incorrect_license.rs
index cf85f0e2623..cf85f0e2623 100644
--- a/python/tidy/tidy_self_test/incorrect_license.rs
+++ b/python/tidy/tests/incorrect_license.rs
diff --git a/python/tidy/tidy_self_test/long_line.rs b/python/tidy/tests/long_line.rs
index cdc0b2045bc..cdc0b2045bc 100644
--- a/python/tidy/tidy_self_test/long_line.rs
+++ b/python/tidy/tests/long_line.rs
diff --git a/python/tidy/tidy_self_test/rust_tidy.rs b/python/tidy/tests/rust_tidy.rs
index 680b527f679..680b527f679 100644
--- a/python/tidy/tidy_self_test/rust_tidy.rs
+++ b/python/tidy/tests/rust_tidy.rs
diff --git a/python/tidy/tidy_self_test/spec.webidl b/python/tidy/tests/spec.webidl
index 51993ea0d41..51993ea0d41 100644
--- a/python/tidy/tidy_self_test/spec.webidl
+++ b/python/tidy/tests/spec.webidl
diff --git a/python/tidy/tidy_self_test/speclink.rs b/python/tidy/tests/speclink.rs
index 6c27a70a7d0..6c27a70a7d0 100644
--- a/python/tidy/tidy_self_test/speclink.rs
+++ b/python/tidy/tests/speclink.rs
diff --git a/python/tidy/tidy_self_test/test.toml b/python/tidy/tests/test.toml
index c979a5cbd34..c979a5cbd34 100644
--- a/python/tidy/tidy_self_test/test.toml
+++ b/python/tidy/tests/test.toml
diff --git a/python/tidy/tests/test_tidy.py b/python/tidy/tests/test_tidy.py
new file mode 100644
index 00000000000..b2dad4f0e54
--- /dev/null
+++ b/python/tidy/tests/test_tidy.py
@@ -0,0 +1,73 @@
+# 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
+from servo_tidy import tidy
+
+
+def iterFile(name):
+ return iter(['tests/' + 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_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/tidy_self_test/tidy_self_test.py b/python/tidy/tests/tidy_self_test.py
index e2a49f71a65..e2a49f71a65 100644
--- a/python/tidy/tidy_self_test/tidy_self_test.py
+++ b/python/tidy/tests/tidy_self_test.py
diff --git a/python/tidy/tidy_self_test/whatwg_link.rs b/python/tidy/tests/whatwg_link.rs
index e8edfbace49..e8edfbace49 100644
--- a/python/tidy/tidy_self_test/whatwg_link.rs
+++ b/python/tidy/tests/whatwg_link.rs
diff --git a/python/tidy/tidy_self_test/wrong_space.rs b/python/tidy/tests/wrong_space.rs
index 50ee5de75b4..50ee5de75b4 100644
--- a/python/tidy/tidy_self_test/wrong_space.rs
+++ b/python/tidy/tests/wrong_space.rs