diff --git a/.gitignore b/.gitignore index 0f046b6dbcd2..786d217d8120 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,6 @@ coverage.xml # Regression test environment variables. regression/local_test_setup + +# Make sure a generated file isn't accidentally committed. +pylintrc_reduced diff --git a/pylintrc_default b/pylintrc_default index 38d7b97eb2de..84293654d3aa 100644 --- a/pylintrc_default +++ b/pylintrc_default @@ -24,11 +24,7 @@ ignore = datastore_v1_pb2.py [MESSAGES CONTROL] disable = I, protected-access, maybe-no-member, no-member, redefined-builtin, star-args, missing-format-attribute, - similarities, arguments-differ, - - - - + similarities, arguments-differ [REPORTS] reports = no diff --git a/pylintrc_reduced b/pylintrc_reduced deleted file mode 100644 index 3342430ab6f2..000000000000 --- a/pylintrc_reduced +++ /dev/null @@ -1,37 +0,0 @@ -# This config is intended to be used for test code -# and other non-production code, like demos. - -[BASIC] -good-names = i, j, k, ex, Run, _, pb, id, - _get_protobuf_attribute_and_value - -[DESIGN] -max-args = 10 -max-public-methods = 30 - -[FORMAT] -# NOTE: By default pylint ignores whitespace checks around the -# constructs "dict-separator" (cases like {1:2}) and "trailing-comma" -# (cases like {1: 2, }). By setting "no-space-check" to empty -# whitespace checks will be enforced around both constructs. -no-space-check = - -[MASTER] -# NOTE: This path must be relative due to the use of -# os.walk in astroid.modutils.get_module_files. -ignore = datastore_v1_pb2.py - -[MESSAGES CONTROL] -disable = I, protected-access, maybe-no-member, no-member, - redefined-builtin, star-args, missing-format-attribute, - similarities, cyclic-import, arguments-differ, - invalid-name, missing-docstring, too-many-public-methods, - too-few-public-methods, attribute-defined-outside-init, - unbalanced-tuple-unpacking, too-many-locals, exec-used, - no-init, no-self-use - -[REPORTS] -reports = no - -[VARIABLES] -dummy-variables-rgx = _$|dummy|^unused_ diff --git a/run_pylint.py b/run_pylint.py index 21560f318112..14299046f86a 100644 --- a/run_pylint.py +++ b/run_pylint.py @@ -7,6 +7,8 @@ violations (hence it has a reduced number of style checks). """ +import ConfigParser +import copy import subprocess import sys @@ -18,6 +20,52 @@ ] PRODUCTION_RC = 'pylintrc_default' TEST_RC = 'pylintrc_reduced' +TEST_DISABLED_MESSAGES = [ + 'invalid-name', + 'missing-docstring', + 'too-many-public-methods', + 'too-few-public-methods', + 'attribute-defined-outside-init', + 'unbalanced-tuple-unpacking', + 'too-many-locals', + 'exec-used', + 'no-init', + 'no-self-use', +] +TEST_RC_ADDITIONS = { + 'MESSAGES CONTROL': { + 'disable': ', '.join(TEST_DISABLED_MESSAGES), + }, +} + + +def read_config(filename): + """Reads pylintrc config onto native ConfigParser object.""" + config = ConfigParser.ConfigParser() + with open(filename, 'r') as file_obj: + config.readfp(file_obj) + return config + + +def make_test_rc(base_rc_filename, additions_dict, target_filename): + """Combines a base rc and test additions into single file.""" + main_cfg = read_config(base_rc_filename) + + # Create fresh config for test, which must extend production. + test_cfg = ConfigParser.ConfigParser() + test_cfg._sections = copy.deepcopy(main_cfg._sections) + + for section, opts in additions_dict.items(): + curr_section = test_cfg._sections.setdefault( + section, test_cfg._dict()) + for opt, opt_val in opts.items(): + curr_val = curr_section.get(opt) + if curr_val is None: + raise KeyError('Expected to be adding to existing option.') + curr_section[opt] = '%s, %s' % (curr_val, opt_val) + + with open(target_filename, 'w') as file_obj: + test_cfg.write(file_obj) def valid_filename(filename): @@ -74,6 +122,7 @@ def lint_fileset(filenames, rcfile, description): def main(): """Script entry point. Lints both sets of files.""" + make_test_rc(PRODUCTION_RC, TEST_RC_ADDITIONS, TEST_RC) library_files, non_library_files = get_python_files() lint_fileset(library_files, PRODUCTION_RC, 'library code') lint_fileset(non_library_files, TEST_RC, 'test and demo code')