Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Add arguments in mypy_runner.py to specify a list of directories to r…
Browse files Browse the repository at this point in the history
…un mypy on (#463)

* Add args in mypy_runner to specify directories to run on

* Raise FileNotFoundError

* Update CHANGELOG.md
  • Loading branch information
Shruthi42 authored May 21, 2021
1 parent 55120d7 commit 2af8c60
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
37 changes: 30 additions & 7 deletions mypy_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2af8c60

Please sign in to comment.