[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.22-985-g3c00f00
cjerdonek at webkit.org
cjerdonek at webkit.org
Wed Mar 17 18:05:37 UTC 2010
The following commit has been merged in the webkit-1.1 branch:
commit a3b272a50684089a0982a6815e656582b2b48a73
Author: cjerdonek at webkit.org <cjerdonek at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Sat Feb 27 08:24:13 2010 +0000
Added Python style checking to check-webkit-style using
the third-party pep8 module (via autoinstall).
Reviewed by David Levin.
https://bugs.webkit.org/show_bug.cgi?id=33639
* Scripts/webkitpy/style/checker.py:
- Added PYTHON to FileType.
- Updated ProcessorDispatcher to return a PythonProcessor
for *.py files.
* Scripts/webkitpy/style/checker_unittest.py:
- Updated the ProcessorDispatcher unit tests for *.py files.
* Scripts/webkitpy/style/processors/python.py: Added.
- Added PythonProcessor class.
* Scripts/webkitpy/style/processors/python_unittest.py: Added.
- Added PythonProcessor unit tests.
* Scripts/webkitpy/style/processors/python_unittest_input.py: Added.
- Added a sample Python file to test the PythonProcessor.process()
code path (since pep8 accepts a file path).
* Scripts/webkitpy/style/unittests.py:
- Updated the style unit test file to import python_unittest.py.
* Scripts/webkitpy/style_references.py:
- Adjusted style references to import pep8.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@55350 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 54a8eea..de8c3c5 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,36 @@
+2010-02-27 Chris Jerdonek <cjerdonek at webkit.org>
+
+ Reviewed by David Levin.
+
+ Added Python style checking to check-webkit-style using
+ the third-party pep8 module (via autoinstall).
+
+ https://bugs.webkit.org/show_bug.cgi?id=33639
+
+ * Scripts/webkitpy/style/checker.py:
+ - Added PYTHON to FileType.
+ - Updated ProcessorDispatcher to return a PythonProcessor
+ for *.py files.
+
+ * Scripts/webkitpy/style/checker_unittest.py:
+ - Updated the ProcessorDispatcher unit tests for *.py files.
+
+ * Scripts/webkitpy/style/processors/python.py: Added.
+ - Added PythonProcessor class.
+
+ * Scripts/webkitpy/style/processors/python_unittest.py: Added.
+ - Added PythonProcessor unit tests.
+
+ * Scripts/webkitpy/style/processors/python_unittest_input.py: Added.
+ - Added a sample Python file to test the PythonProcessor.process()
+ code path (since pep8 accepts a file path).
+
+ * Scripts/webkitpy/style/unittests.py:
+ - Updated the style unit test file to import python_unittest.py.
+
+ * Scripts/webkitpy/style_references.py:
+ - Adjusted style references to import pep8.
+
2010-02-26 Chris Jerdonek <cjerdonek at webkit.org>
Reviewed by David Levin.
diff --git a/WebKitTools/Scripts/webkitpy/style/checker.py b/WebKitTools/Scripts/webkitpy/style/checker.py
index 9c66b97..fe65f74 100644
--- a/WebKitTools/Scripts/webkitpy/style/checker.py
+++ b/WebKitTools/Scripts/webkitpy/style/checker.py
@@ -42,6 +42,7 @@ from optparser import DefaultCommandOptionValues
from processors.common import check_no_carriage_return
from processors.common import categories as CommonCategories
from processors.cpp import CppProcessor
+from processors.python import PythonProcessor
from processors.text import TextProcessor
@@ -209,7 +210,8 @@ class FileType:
NONE = 1
# Alphabetize remaining types
CPP = 2
- TEXT = 3
+ PYTHON = 3
+ TEXT = 4
class ProcessorDispatcher(object):
@@ -230,7 +232,6 @@ class ProcessorDispatcher(object):
'mm',
'php',
'pm',
- 'py',
'txt',
)
@@ -264,6 +265,8 @@ class ProcessorDispatcher(object):
# reading from stdin, cpp_style tests should not rely on
# the extension.
return FileType.CPP
+ elif file_extension == "py":
+ return FileType.PYTHON
elif ("ChangeLog" in file_path
or "WebKitTools/Scripts/" in file_path
or file_extension in self.text_file_extensions):
@@ -278,6 +281,8 @@ class ProcessorDispatcher(object):
elif file_type == FileType.CPP:
file_extension = self._file_extension(file_path)
processor = CppProcessor(file_path, file_extension, handle_style_error, verbosity)
+ elif file_type == FileType.PYTHON:
+ processor = PythonProcessor(file_path, handle_style_error)
elif file_type == FileType.TEXT:
processor = TextProcessor(file_path, handle_style_error)
else:
diff --git a/WebKitTools/Scripts/webkitpy/style/checker_unittest.py b/WebKitTools/Scripts/webkitpy/style/checker_unittest.py
index 1a54cec..ba82670 100755
--- a/WebKitTools/Scripts/webkitpy/style/checker_unittest.py
+++ b/WebKitTools/Scripts/webkitpy/style/checker_unittest.py
@@ -51,6 +51,7 @@ from filter import FilterConfiguration
from optparser import ArgumentParser
from optparser import CommandOptionValues
from processors.cpp import CppProcessor
+from processors.python import PythonProcessor
from processors.text import TextProcessor
@@ -241,6 +242,10 @@ class ProcessorDispatcherDispatchTest(unittest.TestCase):
"""Assert that the dispatched processor is a CppProcessor."""
self.assert_processor(file_path, CppProcessor)
+ def assert_processor_python(self, file_path):
+ """Assert that the dispatched processor is a PythonProcessor."""
+ self.assert_processor(file_path, PythonProcessor)
+
def assert_processor_text(self, file_path):
"""Assert that the dispatched processor is a TextProcessor."""
self.assert_processor(file_path, TextProcessor)
@@ -276,6 +281,26 @@ class ProcessorDispatcherDispatchTest(unittest.TestCase):
self.assertEquals(processor.file_extension, file_extension)
self.assertEquals(processor.file_path, file_path)
+ def test_python_paths(self):
+ """Test paths that should be checked as Python."""
+ paths = [
+ "foo.py",
+ "WebKitTools/Scripts/modules/text_style.py",
+ ]
+
+ for path in paths:
+ self.assert_processor_python(path)
+
+ # Check processor attributes on a typical input.
+ file_base = "foo"
+ file_extension = "css"
+ file_path = file_base + "." + file_extension
+ self.assert_processor_text(file_path)
+ processor = self.dispatch_processor(file_path)
+ self.assertEquals(processor.file_path, file_path)
+ self.assertEquals(processor.handle_style_error,
+ self.mock_handle_style_error)
+
def test_text_paths(self):
"""Test paths that should be checked as text."""
paths = [
@@ -287,14 +312,12 @@ class ProcessorDispatcherDispatchTest(unittest.TestCase):
"foo.mm",
"foo.php",
"foo.pm",
- "foo.py",
"foo.txt",
"FooChangeLog.bak",
"WebCore/ChangeLog",
"WebCore/inspector/front-end/inspector.js",
- "WebKitTools/Scripts/check-webkit=style",
- "WebKitTools/Scripts/modules/text_style.py",
- ]
+ "WebKitTools/Scripts/check-webkit-style",
+ ]
for path in paths:
self.assert_processor_text(path)
diff --git a/WebKitTools/Scripts/webkitpy/style/processors/python.py b/WebKitTools/Scripts/webkitpy/style/processors/python.py
new file mode 100644
index 0000000..8ab936d
--- /dev/null
+++ b/WebKitTools/Scripts/webkitpy/style/processors/python.py
@@ -0,0 +1,56 @@
+# Copyright (C) 2010 Chris Jerdonek (cjerdonek at webkit.org)
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""Supports checking WebKit style in Python files."""
+
+from ...style_references import pep8
+
+
+class PythonProcessor(object):
+
+ """Processes text lines for checking style."""
+
+ def __init__(self, file_path, handle_style_error):
+ self._file_path = file_path
+ self._handle_style_error = handle_style_error
+
+ def process(self, lines):
+ # Initialize pep8.options, which is necessary for
+ # Checker.check_all() to execute.
+ pep8.process_options(arglist=[self._file_path])
+
+ checker = pep8.Checker(self._file_path)
+
+ def _pep8_handle_error(line_number, offset, text, check):
+ # FIXME: Incorporate the character offset into the error output.
+ # This will require updating the error handler __call__
+ # signature to include an optional "offset" parameter.
+ pep8_code = text[:4]
+ pep8_message = text[5:]
+
+ category = "pep8/" + pep8_code
+
+ self._handle_style_error(line_number, category, 5, pep8_message)
+
+ checker.report_error = _pep8_handle_error
+
+ errors = checker.check_all()
diff --git a/WebKitTools/Scripts/webkitpy/style/processors/python_unittest.py b/WebKitTools/Scripts/webkitpy/style/processors/python_unittest.py
new file mode 100644
index 0000000..3ce3311
--- /dev/null
+++ b/WebKitTools/Scripts/webkitpy/style/processors/python_unittest.py
@@ -0,0 +1,62 @@
+# Copyright (C) 2010 Chris Jerdonek (cjerdonek at webkit.org)
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""Unit tests for python.py."""
+
+import os
+import unittest
+
+from python import PythonProcessor
+
+
+class PythonProcessorTest(unittest.TestCase):
+
+ """Tests the PythonProcessor class."""
+
+ def test_init(self):
+ """Test __init__() method."""
+ def _mock_handle_style_error(self):
+ pass
+
+ processor = PythonProcessor("foo.txt", _mock_handle_style_error)
+ self.assertEquals(processor._file_path, "foo.txt")
+ self.assertEquals(processor._handle_style_error,
+ _mock_handle_style_error)
+
+ def test_process(self):
+ """Test process() method."""
+ errors = []
+
+ def _mock_handle_style_error(line_number, category, confidence,
+ message):
+ error = (line_number, category, confidence, message)
+ errors.append(error)
+
+ current_dir = os.path.dirname(__file__)
+ file_path = os.path.join(current_dir, "python_unittest_input.py")
+
+ processor = PythonProcessor(file_path, _mock_handle_style_error)
+ processor.process(lines=[])
+
+ self.assertEquals(len(errors), 1)
+ self.assertEquals(errors[0],
+ (2, "pep8/W291", 5, "trailing whitespace"))
diff --git a/WebKitTools/Scripts/webkitpy/style/processors/python_unittest_input.py b/WebKitTools/Scripts/webkitpy/style/processors/python_unittest_input.py
new file mode 100644
index 0000000..9f1d118
--- /dev/null
+++ b/WebKitTools/Scripts/webkitpy/style/processors/python_unittest_input.py
@@ -0,0 +1,2 @@
+# This file is sample input for python_unittest.py and includes a single
+# error which is an extra space at the end of this line.
diff --git a/WebKitTools/Scripts/webkitpy/style/unittests.py b/WebKitTools/Scripts/webkitpy/style/unittests.py
index 62615ab..1a28987 100644
--- a/WebKitTools/Scripts/webkitpy/style/unittests.py
+++ b/WebKitTools/Scripts/webkitpy/style/unittests.py
@@ -41,4 +41,5 @@ from filter_unittest import *
from optparser_unittest import *
from processors.common_unittest import *
from processors.cpp_unittest import *
+from processors.python_unittest import *
from processors.text_unittest import *
diff --git a/WebKitTools/Scripts/webkitpy/style_references.py b/WebKitTools/Scripts/webkitpy/style_references.py
index 2528c4d..b3b7f76 100644
--- a/WebKitTools/Scripts/webkitpy/style_references.py
+++ b/WebKitTools/Scripts/webkitpy/style_references.py
@@ -42,7 +42,7 @@ import os
from diff_parser import DiffParser
from scm import detect_scm_system
-
+from thirdparty.autoinstalled import pep8
def parse_patch(patch_string):
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list