summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml13
-rw-r--r--Cython/Build/Dependencies.py2
-rw-r--r--Cython/Compiler/ModuleNode.py2
-rw-r--r--Demos/overflow_perf_run.py2
-rwxr-xr-xruntests.py22
-rw-r--r--test-requirements.txt1
-rw-r--r--tox.ini6
7 files changed, 43 insertions, 5 deletions
diff --git a/.travis.yml b/.travis.yml
index 693a19e93..8424682ed 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -47,6 +47,10 @@ matrix:
- python: 3.7
dist: xenial # Required for Python 3.7
sudo: required # travis-ci/travis-ci#9069
+ env: TEST_CODE_STYLE=1
+ - python: 3.7
+ dist: xenial # Required for Python 3.7
+ sudo: required # travis-ci/travis-ci#9069
env: BACKEND=c
- python: 3.7
dist: xenial # Required for Python 3.7
@@ -144,9 +148,14 @@ install:
before_script: ccache -s || true
script:
+ - if [ "$TEST_CODE_STYLE" = "1" ]; then
+ STYLE_ARGS="--no-unit --no-doctest --no-file --no-pyregr --no-examples";
+ else
+ STYLE_ARGS=--no-code-style;
+ fi
- PYTHON_DBG="python$( python -c 'import sys; print("%d.%d" % sys.version_info[:2])' )-dbg"
- - if $PYTHON_DBG -V >&2; then CFLAGS="-O0 -ggdb" $PYTHON_DBG runtests.py -vv Debugger --backends=$BACKEND; fi
+ - if $PYTHON_DBG -V >&2; then CFLAGS="-O0 -ggdb" $PYTHON_DBG runtests.py -vv $STYLE_ARGS Debugger --backends=$BACKEND; fi
- if [ "$BACKEND" = "cpp" -a -n "${TRAVIS_PYTHON_VERSION##2.6*}" ]; then pip install pythran; fi
- if [ "$BACKEND" = "c" -a -n "${TRAVIS_PYTHON_VERSION##2*}" ]; then pip install mypy; fi
- CFLAGS="-O2 -ggdb -Wall -Wextra $(python -c 'import sys; print("-fno-strict-aliasing" if sys.version_info[0] == 2 else "")')" python setup.py build_ext -i
- - CFLAGS="-O0 -ggdb -Wall -Wextra" python runtests.py -vv -x Debugger --backends=$BACKEND -j7
+ - CFLAGS="-O0 -ggdb -Wall -Wextra" python runtests.py -vv $STYLE_ARGS -x Debugger --backends=$BACKEND -j7
diff --git a/Cython/Build/Dependencies.py b/Cython/Build/Dependencies.py
index ca1ec5a08..db434a584 100644
--- a/Cython/Build/Dependencies.py
+++ b/Cython/Build/Dependencies.py
@@ -230,7 +230,7 @@ class DistutilsInfo(object):
break
line = line[1:].lstrip()
kind = next((k for k in ("distutils:","cython:") if line.startswith(k)), None)
- if not kind is None:
+ if kind is not None:
key, _, value = [s.strip() for s in line[len(kind):].partition('=')]
type = distutils_settings.get(key, None)
if line.startswith("cython:") and type is None: continue
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
index 9bbccb86c..8a9186e01 100644
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -113,7 +113,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
env.doc = self.doc = None
elif Options.embed_pos_in_docstring:
env.doc = EncodedString(u'File: %s (starting at line %s)' % Nodes.relative_position(self.pos))
- if not self.doc is None:
+ if self.doc is not None:
env.doc = EncodedString(env.doc + u'\n' + self.doc)
env.doc.encoding = self.doc.encoding
else:
diff --git a/Demos/overflow_perf_run.py b/Demos/overflow_perf_run.py
index ce4036951..137f0c1cb 100644
--- a/Demos/overflow_perf_run.py
+++ b/Demos/overflow_perf_run.py
@@ -16,7 +16,7 @@ def run_tests(N):
print(func.__name__)
for type in ['int', 'unsigned int', 'long long', 'unsigned long long', 'object']:
if func == most_orthogonal:
- if type == 'object' or np == None:
+ if type == 'object' or np is None:
continue
type_map = {'int': 'int32', 'unsigned int': 'uint32', 'long long': 'int64', 'unsigned long long': 'uint64'}
shape = N, 3
diff --git a/runtests.py b/runtests.py
index 36653a1c7..f239d8789 100755
--- a/runtests.py
+++ b/runtests.py
@@ -1446,6 +1446,22 @@ class CythonPyregrTestCase(CythonRunTestCase):
run_forked_test(result, run_test, self.shortDescription(), self.fork)
+class TestCodeFormat(unittest.TestCase):
+
+ def __init__(self, cython_dir):
+ self.cython_dir = cython_dir
+ unittest.TestCase.__init__(self)
+
+ def runTest(self):
+ import pycodestyle
+ config_file = os.path.join(self.cython_dir, "tox.ini")
+ paths = glob.glob(os.path.join(self.cython_dir, "**/*.py"), recursive=True)
+ style = pycodestyle.StyleGuide(config_file=config_file)
+ print("") # Fix the first line of the report.
+ result = style.check_files(paths)
+ self.assertEqual(result.total_errors, 0, "Found code style errors.")
+
+
include_debugger = IS_CPYTHON
@@ -1868,6 +1884,9 @@ def main():
parser.add_option("--no-examples", dest="examples",
action="store_false", default=True,
help="Do not run the documentation tests in the examples directory.")
+ parser.add_option("--no-code-style", dest="code_style",
+ action="store_false", default=True,
+ help="Do not run the code style (PEP8) checks.")
parser.add_option("--cython-only", dest="cython_only",
action="store_true", default=False,
help="only compile pyx to c, do not run C compiler or run the tests")
@@ -2214,6 +2233,9 @@ def runtests(options, cmd_args, coverage=None):
sys.stderr.write("Including CPython regression tests in %s\n" % sys_pyregr_dir)
test_suite.addTest(filetests.handle_directory(sys_pyregr_dir, 'pyregr'))
+ if options.code_style and options.shard_num <= 0:
+ test_suite.addTest(TestCodeFormat(options.cython_dir))
+
if xml_output_dir:
from Cython.Tests.xmlrunner import XMLTestRunner
if not os.path.exists(xml_output_dir):
diff --git a/test-requirements.txt b/test-requirements.txt
index 4a22eaaae..6547302da 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1,3 +1,4 @@
numpy
jupyter
coverage
+pycodestyle
diff --git a/tox.ini b/tox.ini
index 5d47008ed..f7a96a320 100644
--- a/tox.ini
+++ b/tox.ini
@@ -10,3 +10,9 @@ envlist = py26, py27, py32, py33, py34, pypy
setenv = CFLAGS=-O0 -ggdb
commands =
{envpython} runtests.py -vv
+
+[pycodestyle]
+ignore = W, E
+select = E711, E714
+max-line-length = 300
+format = pylint