def pylint_run(is_pr, version, dir): # Look for an environment variable # whose value is the name of a proper configuration file for pylint # (this file will then be expected to be found in the 'cfg/' folder). # If such an environment variable is not found, # it defaults to the standard configuration file. pylint_config_file = os.environ.get('PYLINT_CONFIG_FILE', 'travis_run_pylint.cfg') pylint_rcfile = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'cfg', pylint_config_file) pylint_rcfile_pr = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'cfg', "travis_run_pylint_pr.cfg") odoo_version = version_validate(version, dir) modules_cmd = get_modules_cmd(dir) beta_msgs = get_beta_msgs() branch_base = get_branch_base() extra_params_cmd = get_extra_params(odoo_version) extra_info = "extra_params_cmd %s " % extra_params_cmd print(extra_info) conf = ["--config-file=%s" % (pylint_rcfile)] cmd = conf + modules_cmd + extra_params_cmd real_errors = main(cmd, standalone_mode=False) res = dict((key, value) for key, value in (real_errors.get('by_msg') or {}).items() if key not in beta_msgs) count_errors = get_count_fails(real_errors, list(beta_msgs)) count_info = "count_errors %s" % count_errors print(count_info) if is_pr: print( travis_helpers.green( 'Starting lint check only for modules changed')) modules_changed = get_modules_changed(dir, branch_base) if not modules_changed: print( travis_helpers.green('There are not modules changed from ' '"git --git-dir=%s diff ..%s"' % (dir, branch_base))) return res modules_changed_cmd = [] for module_changed in modules_changed: modules_changed_cmd.extend(['--path', module_changed]) conf = ["--config-file=%s" % (pylint_rcfile_pr)] cmd = conf + modules_changed_cmd + extra_params_cmd pr_real_errors = main(cmd, standalone_mode=False) pr_stats = dict( (key, value) for key, value in (pr_real_errors.get('by_msg') or {}).items() if key not in beta_msgs) if pr_stats: pr_errors = get_count_fails(pr_real_errors, list(beta_msgs)) print( travis_helpers.yellow("Found %s errors in modules changed." % (pr_errors))) if pr_errors < 0: res = pr_stats else: new_dict = {} for val in res: new_dict[val] = (new_dict.get(val, 0) + res[val]) for val in pr_stats: new_dict[val] = (new_dict.get(val, 0) + pr_stats[val]) res = new_dict return res
def pylint_run(is_pr, version, dir): # Look for an environment variable # whose value is the name of a proper configuration file for pylint # (this file will then be expected to be found in the 'cfg/' folder). # If such an environment variable is not found, # it defaults to the standard configuration file. pylint_config_file = os.environ.get( 'PYLINT_CONFIG_FILE', 'travis_run_pylint.cfg') pylint_rcfile = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'cfg', pylint_config_file) pylint_rcfile_pr = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'cfg', "travis_run_pylint_pr.cfg") odoo_version = version_validate(version, dir) modules_cmd = get_modules_cmd(dir) beta_msgs = get_beta_msgs() branch_base = get_branch_base() extra_params_cmd = get_extra_params(odoo_version) extra_info = "extra_params_cmd %s " % extra_params_cmd print(extra_info) conf = ["--config-file=%s" % (pylint_rcfile)] cmd = conf + modules_cmd + extra_params_cmd real_errors = main(cmd, standalone_mode=False) res = dict( (key, value) for key, value in (real_errors.get( 'by_msg') or {}).items() if key not in beta_msgs) count_errors = get_count_fails(real_errors, list(beta_msgs)) count_info = "count_errors %s" % count_errors print(count_info) if is_pr: print(travis_helpers.green( 'Starting lint check only for modules changed')) modules_changed = get_modules_changed(dir, branch_base) if not modules_changed: print(travis_helpers.green( 'There are not modules changed from ' '"git --git-dir=%s diff ..%s"' % (dir, branch_base))) return res modules_changed_cmd = [] for module_changed in modules_changed: modules_changed_cmd.extend(['--path', module_changed]) conf = ["--config-file=%s" % (pylint_rcfile_pr)] cmd = conf + modules_changed_cmd + extra_params_cmd pr_real_errors = main(cmd, standalone_mode=False) pr_stats = dict( (key, value) for key, value in (pr_real_errors.get( 'by_msg') or {}).items() if key not in beta_msgs) if pr_stats: pr_errors = get_count_fails(pr_real_errors, list(beta_msgs)) print(travis_helpers.yellow( "Found %s errors in modules changed." % (pr_errors))) if pr_errors < 0: res = pr_stats else: new_dict = {} for val in res: new_dict[val] = (new_dict.get(val, 0) + res[val]) for val in pr_stats: new_dict[val] = (new_dict.get(val, 0) + pr_stats[val]) res = new_dict return res