Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BI-4969: allow execute_mypy_multi to be run without targets_file param #25

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 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,10 @@
from pathlib import Path
import subprocess
import sys
from typing import (
Iterable,
Optional,
)

import clize
import tomlkit
Expand All @@ -21,21 +25,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
Loading