|
7 | 7 | violations (hence it has a reduced number of style checks). |
8 | 8 | """ |
9 | 9 |
|
| 10 | +import ConfigParser |
| 11 | +import copy |
10 | 12 | import subprocess |
11 | 13 | import sys |
12 | 14 |
|
|
18 | 20 | ] |
19 | 21 | PRODUCTION_RC = 'pylintrc_default' |
20 | 22 | 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) |
21 | 69 |
|
22 | 70 |
|
23 | 71 | def valid_filename(filename): |
@@ -74,6 +122,7 @@ def lint_fileset(filenames, rcfile, description): |
74 | 122 |
|
75 | 123 | def main(): |
76 | 124 | """Script entry point. Lints both sets of files.""" |
| 125 | + make_test_rc(PRODUCTION_RC, TEST_RC_ADDITIONS, TEST_RC) |
77 | 126 | library_files, non_library_files = get_python_files() |
78 | 127 | lint_fileset(library_files, PRODUCTION_RC, 'library code') |
79 | 128 | lint_fileset(non_library_files, TEST_RC, 'test and demo code') |
|
0 commit comments