Skip to content

Commit

Permalink
BI-4969: allow execute_mypy_multi to be run without targets_file param
Browse files Browse the repository at this point in the history
  • Loading branch information
thenno committed Oct 17, 2023
1 parent e1d822d commit f1aef55
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions terrarium/bi_ci/bi_ci/execute_mypy_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
import subprocess
import sys
from typing import Optional, Iterable

import clize
import tomlkit
Expand All @@ -21,21 +22,30 @@ def get_mypy_targets(pkg_dir: Path) -> list[str]:
return [pkg_dir.name]


def main(root: Path, targets_file: Path) -> None:
targets: list[str] = json.load(open(targets_file))
def get_targets(root: Path) -> Iterable[str]:
for path in root.rglob("*/pyproject.toml"):
yield str(path.parent)


def main(root: Path, targets_file: Path = None) -> None: # type: ignore
# clize can't recognize type annotation "Optional"
if targets_file is not None:
paths: Iterable[str] = json.load(open(targets_file))
else:
paths: Iterable[str] = get_targets(root)
failed_list: list[str] = []
mypy_cache_dir = Path("/tmp/mypy_cache")
mypy_cache_dir.mkdir(exist_ok=True)
for target in targets:
pkg_dir = root / target
for path in paths:
pkg_dir = root / path
run_args = ["mypy", f"--cache-dir={mypy_cache_dir}"]
targets = get_mypy_targets(pkg_dir)
print(f"Cmd: {run_args}; cwd={pkg_dir}")
if len(targets) > 0:
run_args.extend(targets)
run_exit_code = subprocess.run(" ".join(run_args), shell=True, cwd=str(pkg_dir)).returncode
if run_exit_code != 0:
failed_list.append(target)
failed_list.append(path)
else:
print(f"mypy config not found in {pkg_dir}/pyproject.toml, skipped")

Expand Down

0 comments on commit f1aef55

Please sign in to comment.