Skip to content

Commit 6780f7d

Browse files
committed
build: add lint, style and format commands
The `format` command is useful because the `cpplint` code does not conform to any tight style. If we can remove all the `pylint` and `flake8` violations we can develop a `yapf` configuration that formats to that style
1 parent 61b5f13 commit 6780f7d

File tree

6 files changed

+152
-3
lines changed

6 files changed

+152
-3
lines changed

.flake8

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[flake8]
2+
ignore =
3+
# indentation is not a multiple of four,
4+
E111,E114,
5+
# visually indented line with same indent as next logical line,
6+
E129,
7+
# line too long
8+
E501,
9+
# expected 2 blank lines, found 1
10+
E302,E305,
11+
# closing bracket does not match indentation of opening bracket's line
12+
E123,
13+
# multiple spaces before operator
14+
E221,
15+
# line break before binary operator
16+
W503,
17+
# line break after binary operator
18+
W504,
19+
# multiple statements on one line
20+
E701,
21+
# continuation line under-indented for hanging indent
22+
E121,
23+
# closing bracket does not match visual indentation
24+
E124,
25+
# continuation line with same indent as next logical line
26+
E125,
27+
# continuation line over-indented for visual indent
28+
E127,
29+
# continuation line under-indented for visual indent
30+
E128,
31+
# unexpected indentation
32+
E116,
33+
# too many blank lines
34+
E303,
35+
# missing whitespace around arithmetic operator
36+
E226,
37+
# test for membership should be 'not in'
38+
E713,
39+
max-line-length=80

.pylintrc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[BASIC]
2+
include-naming-hint=yes
3+
method-rgx=[A-Z_][A-Za-z0-9]{2,49}$
4+
function-rgx=[A-Z_][A-Za-z0-9]{2,49}$|main|unicode_escape_decode
5+
const-rgx=[a-zA-Z_][A-Za-z0-9_]{2,49}$
6+
variable-rgx=[a-z_][a-z0-9_]{0,49}$
7+
argument-rgx=[a-z_][a-z0-9_]{0,49}$
8+
class-rgx=[A-Z_][a-zA-Z0-9]+$|basestring|unicode|long|xrange
9+
10+
[MESSAGES CONTROL]
11+
disable=global-statement,multiple-statements,missing-docstring,no-else-return,no-self-use,consider-merging-isinstance,bad-indentation,bad-continuation,fixme,bad-option-value,anomalous-unicode-escape-in-string,unused-argument,useless-object-inheritance,consider-using-dict-comprehension,consider-using-in
12+
13+
[REPORTS]
14+
output-format=colorized
15+
reports=no
16+
score=no
17+
18+
[FORMAT]
19+
indent-string=' '
20+
indent-after-paren=4
21+
max-module-lines=10000
22+
23+
[DESIGN]
24+
max-locals=25
25+
max-line-length=100
26+
max-attributes=10
27+
max-branches=30
28+
max-args=20
29+
max-statements=75
30+
max-returns=10
31+
min-public-methods=0
32+
max-bool-expr=10

.style.yapf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[style]
2+
based_on_style = chromium
3+
dedent_closing_brackets = True
4+
coalesce_brackets = True
5+
continuation_indent_width = 2

README.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ The modifications in this branch are minor fixes and cosmetic changes:
4040
* Support ``#pragma once`` as an alternative to header include guards
4141
* Add quiet option to suppress non error-related output
4242

43+
Development
44+
-----------
45+
46+
.. code-block:: bash
47+
48+
pip install --user -e .[dev]
49+
./setup.py lint
50+
./setup.py style
51+
./setup.py test
52+
./setup.py ci # all the above
53+
4354
Maintaining
4455
-----------
4556

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[aliases]
2+
style = flake8
3+
ci = lint style test
4+

setup.py

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,59 @@
11
#! /usr/bin/env python
22

3-
from setuptools import setup
3+
from setuptools import setup, Command
4+
from setuptools.command.test import test as TestCommand
5+
from subprocess import check_call
6+
from multiprocessing import cpu_count
7+
from distutils.spawn import find_executable
8+
9+
10+
class Test(TestCommand):
11+
def run_tests(self):
12+
check_call(('./cpplint_unittest.py'))
13+
check_call(('./cpplint_clitest.py'))
14+
15+
16+
class Cmd(Command):
17+
user_options = [
18+
('executable', 'e', 'The executable to use for the command')
19+
]
20+
21+
def initialize_options(self):
22+
self.executable = find_executable(self.executable)
23+
24+
def finalize_options(self):
25+
pass
26+
27+
def execute(self, *k):
28+
check_call((self.executable,) + k)
29+
30+
31+
class Lint(Cmd):
32+
description = 'Run linting of the code'
33+
user_options = Cmd.user_options + [
34+
('jobs', 'j', 'Use multiple processes to speed up the linting')
35+
]
36+
executable = 'pylint'
37+
38+
def initialize_options(self):
39+
self.jobs = cpu_count()
40+
41+
def finalize_options(self):
42+
self.jobs = int(self.jobs)
43+
if self.jobs < 1:
44+
raise ValueError('Jobs must be one or larger')
45+
46+
def run(self):
47+
self.execute('-j', str(self.jobs), 'cpplint.py')
48+
49+
50+
class Format(Cmd):
51+
description = 'Formats the code'
52+
executable = 'yapf'
53+
54+
def run(self):
55+
self.execute('--parallel', '--in-place', 'cpplint.py')
56+
457

558
setup(name='cpplint',
659
version='1.3.0',
@@ -15,8 +68,8 @@
1568
url='http://en.wikipedia.org/wiki/Cpplint',
1669
download_url='https://github.com/cpplint/cpplint',
1770
keywords=['lint', 'python', 'c++'],
18-
maintainer = 'cpplint Developers',
19-
maintainer_email = 'see_github@nospam.com',
71+
maintainer='cpplint Developers',
72+
maintainer_email='see_github@nospam.com',
2073
classifiers=['Programming Language :: Python',
2174
'Programming Language :: Python :: 2',
2275
'Programming Language :: Python :: 2.7',
@@ -38,4 +91,9 @@
3891
'flake8',
3992
'yapf',
4093
]
94+
},
95+
cmdclass={
96+
'test': Test,
97+
'lint': Lint,
98+
'format': Format
4199
})

0 commit comments

Comments
 (0)