diff options
author | David Bradford <david.bradford@mongodb.com> | 2020-04-29 15:25:17 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-05-06 13:35:43 +0000 |
commit | 1dc60902170fe8d69d50b32220b254ad681dfcf2 (patch) | |
tree | f1c31d70d1edeffa9cf0e93bc36f28c3c1c14f2d /buildscripts/pylinters.py | |
parent | d2274bb6e1f8b21d73121a2fcb20b6628f652bbe (diff) | |
download | mongo-1dc60902170fe8d69d50b32220b254ad681dfcf2.tar.gz |
SERVER-47796: Ensure linters run against enterprise modules
(cherry picked from commit 74ea6aa4dfd7b3b4acf090084d36891834a49385)
Diffstat (limited to 'buildscripts/pylinters.py')
-rwxr-xr-x | buildscripts/pylinters.py | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/buildscripts/pylinters.py b/buildscripts/pylinters.py index 705c1c5f0e4..aab4378d80e 100755 --- a/buildscripts/pylinters.py +++ b/buildscripts/pylinters.py @@ -5,22 +5,25 @@ import argparse import logging import os import sys -import threading -from abc import ABCMeta, abstractmethod -from typing import Any, Dict, List +from typing import Dict, List + +import structlog # Get relative imports to work when the package is not installed on the PYTHONPATH. if __name__ == "__main__" and __package__ is None: sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(os.path.realpath(__file__))))) -from buildscripts.linter import base # pylint: disable=wrong-import-position -from buildscripts.linter import git # pylint: disable=wrong-import-position -from buildscripts.linter import mypy # pylint: disable=wrong-import-position -from buildscripts.linter import parallel # pylint: disable=wrong-import-position -from buildscripts.linter import pydocstyle # pylint: disable=wrong-import-position -from buildscripts.linter import pylint # pylint: disable=wrong-import-position -from buildscripts.linter import runner # pylint: disable=wrong-import-position -from buildscripts.linter import yapf # pylint: disable=wrong-import-position +# pylint: disable=wrong-import-position +from buildscripts.linter.filediff import gather_changed_files_for_lint +from buildscripts.linter import base +from buildscripts.linter import git +from buildscripts.linter import mypy +from buildscripts.linter import parallel +from buildscripts.linter import pydocstyle +from buildscripts.linter import pylint +from buildscripts.linter import runner +from buildscripts.linter import yapf +# pylint: enable=wrong-import-position # List of supported linters _LINTERS = [ @@ -98,6 +101,16 @@ def lint_patch(linters, config_dict, file_name): _lint_files(linters, config_dict, file_names) +def lint_git_diff(linters, config_dict, _): + # type: (str, Dict[str, str], List[str]) -> None + """Lint git diff command entry point.""" + file_names = gather_changed_files_for_lint(is_interesting_file) + + # Patch may have files that we do not want to check which is fine + if file_names: + _lint_files(linters, config_dict, file_names) + + def lint(linters, config_dict, file_names): # type: (str, Dict[str, str], List[str]) -> None """Lint files command entry point.""" @@ -185,6 +198,11 @@ def main(): parser_lint_patch.add_argument("file_names", nargs="*", help="Globs of files to check") parser_lint_patch.set_defaults(func=lint_patch) + parser_lint_patch = sub.add_parser('lint-git-diff', + help='Lint the files since the last git commit') + parser_lint_patch.add_argument("file_names", nargs="*", help="Globs of files to check") + parser_lint_patch.set_defaults(func=lint_git_diff) + parser_fix = sub.add_parser('fix', help='Fix files if possible') parser_fix.add_argument("file_names", nargs="*", help="Globs of files to check") parser_fix.set_defaults(func=fix_func) @@ -201,6 +219,7 @@ def main(): if args.verbose: logging.basicConfig(level=logging.DEBUG) + structlog.configure(logger_factory=structlog.stdlib.LoggerFactory()) args.func(args.linters, config_dict, args.file_names) |