Add arguments in mypy_runner.py to specify a list of directories to run mypy on (#463)

* Add args in mypy_runner to specify directories to run on

* Raise FileNotFoundError

* Update CHANGELOG.md
This commit is contained in:
Shruthi42 2021-05-21 11:10:40 +01:00 коммит произвёл GitHub
Родитель 55120d7a6b
Коммит 2af8c6099c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 32 добавлений и 7 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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: