Skip to content

Commit 87cf71d

Browse files
committed
Merge pull request #302 from dhermes/remove-cyclic-twice
Remove cyclic import from ignored for tests.
2 parents 1237161 + d75091a commit 87cf71d

File tree

4 files changed

+53
-42
lines changed

4 files changed

+53
-42
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ coverage.xml
4545

4646
# Regression test environment variables.
4747
regression/local_test_setup
48+
49+
# Make sure a generated file isn't accidentally committed.
50+
pylintrc_reduced

pylintrc_default

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ ignore = datastore_v1_pb2.py
2424
[MESSAGES CONTROL]
2525
disable = I, protected-access, maybe-no-member, no-member,
2626
redefined-builtin, star-args, missing-format-attribute,
27-
similarities, arguments-differ,
28-
29-
30-
31-
27+
similarities, arguments-differ
3228

3329
[REPORTS]
3430
reports = no

pylintrc_reduced

Lines changed: 0 additions & 37 deletions
This file was deleted.

run_pylint.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
violations (hence it has a reduced number of style checks).
88
"""
99

10+
import ConfigParser
11+
import copy
1012
import subprocess
1113
import sys
1214

@@ -18,6 +20,52 @@
1820
]
1921
PRODUCTION_RC = 'pylintrc_default'
2022
TEST_RC = 'pylintrc_reduced'
23+
TEST_DISABLED_MESSAGES = [
24+
'invalid-name',
25+
'missing-docstring',
26+
'too-many-public-methods',
27+
'too-few-public-methods',
28+
'attribute-defined-outside-init',
29+
'unbalanced-tuple-unpacking',
30+
'too-many-locals',
31+
'exec-used',
32+
'no-init',
33+
'no-self-use',
34+
]
35+
TEST_RC_ADDITIONS = {
36+
'MESSAGES CONTROL': {
37+
'disable': ', '.join(TEST_DISABLED_MESSAGES),
38+
},
39+
}
40+
41+
42+
def read_config(filename):
43+
"""Reads pylintrc config onto native ConfigParser object."""
44+
config = ConfigParser.ConfigParser()
45+
with open(filename, 'r') as file_obj:
46+
config.readfp(file_obj)
47+
return config
48+
49+
50+
def make_test_rc(base_rc_filename, additions_dict, target_filename):
51+
"""Combines a base rc and test additions into single file."""
52+
main_cfg = read_config(base_rc_filename)
53+
54+
# Create fresh config for test, which must extend production.
55+
test_cfg = ConfigParser.ConfigParser()
56+
test_cfg._sections = copy.deepcopy(main_cfg._sections)
57+
58+
for section, opts in additions_dict.items():
59+
curr_section = test_cfg._sections.setdefault(
60+
section, test_cfg._dict())
61+
for opt, opt_val in opts.items():
62+
curr_val = curr_section.get(opt)
63+
if curr_val is None:
64+
raise KeyError('Expected to be adding to existing option.')
65+
curr_section[opt] = '%s, %s' % (curr_val, opt_val)
66+
67+
with open(target_filename, 'w') as file_obj:
68+
test_cfg.write(file_obj)
2169

2270

2371
def valid_filename(filename):
@@ -74,6 +122,7 @@ def lint_fileset(filenames, rcfile, description):
74122

75123
def main():
76124
"""Script entry point. Lints both sets of files."""
125+
make_test_rc(PRODUCTION_RC, TEST_RC_ADDITIONS, TEST_RC)
77126
library_files, non_library_files = get_python_files()
78127
lint_fileset(library_files, PRODUCTION_RC, 'library code')
79128
lint_fileset(non_library_files, TEST_RC, 'test and demo code')

0 commit comments

Comments
 (0)