diff --git a/CHANGELOG.md b/CHANGELOG.md index 199d1de1..36f8c94e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,6 +85,8 @@ console for easier diagnostics. `TrainHelloContainer`. A pytest marker `after_training_hello_container` has been added to run tests after training is finished in the `TrainHelloContainer` job. - ([#456](https://github.com/microsoft/InnerEye-DeepLearning/pull/456)) Adding configs to train Covid detection models. +- ([#463](https://github.com/microsoft/InnerEye-DeepLearning/pull/463)) Add arguments `dirs_recursive` and + `dirs_non_recursive` to `mypy_runner.py` to let users specify a list of directories to run mypy on. ### Changed diff --git a/mypy_runner.py b/mypy_runner.py index 5a4e31e6..e2427947 100644 --- a/mypy_runner.py +++ b/mypy_runner.py @@ -50,17 +50,40 @@ def main() -> int: """ parser = ArgumentParser() parser.add_argument("-f", "--files", type=str, nargs='+', required=False, default=None, - help="List of files to run mypy on. If not provided, run on current directory") + help="List of files to run mypy on. " + "Can be used along with `dirs_recursive` and `dirs_non_recursive`. " + "If none of `files`, `dirs_recursive` or `dirs_non_recursive` are provided, " + "run on the default set of files for the InnerEye repository") + parser.add_argument("-D", "--dirs_recursive", type=str, nargs='+', required=False, default=None, + help="List of directories to run mypy on (recursively). " + "Can be used along with `files` and `dirs_non_recursive`. " + "If none of `files`, `dirs_recursive` or `dirs_non_recursive` are provided, " + "run on the default set of files for the InnerEye repository") + parser.add_argument("-d", "--dirs_non_recursive", type=str, nargs='+', required=False, default=None, + help="Look for python files in these directories (non-recursive) to run mypy on. " + "Can be used along with `files` and `dirs_recursive`. " + "If none of `files`, `dirs_recursive` or `dirs_non_recursive` are provided, " + "run on the default set of files for the InnerEye repository") parser.add_argument("-m", "--mypy", type=str, required=False, default=None, help="Path to mypy executable. If not provided, autodetect mypy executable.") args = parser.parse_args() - current_dir = Path(".") + + file_list = [] + if args.files: - file_list = args.files - else: - file_list = list(str(f) for f in current_dir.glob('*.py')) - for dir in ["InnerEye", "Tests", "TestsOutsidePackage", "TestSubmodule"]: - file_list.append(dir) + file_list.extend(args.files) + if args.dirs_recursive: + file_list.extend(args.dirs_recursive) + if args.dirs_non_recursive: + for dir in args.dirs_non_recursive: + dir = Path(dir) + if not dir.exists(): + raise FileNotFoundError(f"Could not find directory {dir}.") + file_list.extend([str(f) for f in dir.glob('*.py')]) + if not file_list: + current_dir = Path(".") + file_list = [str(f) for f in current_dir.glob('*.py')] + file_list.extend(["InnerEye", "Tests", "TestsOutsidePackage", "TestSubmodule"]) mypy = args.mypy or which("mypy") if not mypy: