|
| 1 | +"""Run basedmypy, so that uses `numpy-stubs` instead of numpy's own stubs.""" |
| 2 | + |
| 3 | +# ruff: noqa: T201, S603, S404, D103, DOC201 |
| 4 | + |
| 5 | +import subprocess |
| 6 | +import sys |
| 7 | +from pathlib import Path |
| 8 | + |
| 9 | +PROJECT_PATH = Path(__file__).parent.parent.resolve() |
| 10 | + |
| 11 | + |
| 12 | +def _call_static(args: list[str], *base_cmd: str) -> int: |
| 13 | + if not args or all(arg.startswith("-") for arg in args): # noqa: SIM108 |
| 14 | + cmd = [*base_cmd, *args, "static"] |
| 15 | + else: |
| 16 | + cmd = [*base_cmd, *args] |
| 17 | + |
| 18 | + print(*cmd) |
| 19 | + return subprocess.call(cmd) |
| 20 | + |
| 21 | + |
| 22 | +def _static_bmp(args: list[str], /) -> int: |
| 23 | + return _call_static( |
| 24 | + args, |
| 25 | + "mypy", |
| 26 | + "--explicit-package-bases", |
| 27 | + "--hide-error-context", |
| 28 | + "--hide-error-code-links", |
| 29 | + "--no-pretty", |
| 30 | + "--tb", |
| 31 | + "--config-file=../pyproject.toml", |
| 32 | + ) |
| 33 | + |
| 34 | + |
| 35 | +def _static_bpr(args: list[str], /) -> int: |
| 36 | + return _call_static(args, "basedpyright", "--project=../") |
| 37 | + |
| 38 | + |
| 39 | +def static(args: list[str] | None = None, /) -> int: |
| 40 | + if args is None: |
| 41 | + args = sys.argv[1:] |
| 42 | + if args: |
| 43 | + if args[0] == "all": |
| 44 | + return _static_bpr(args[1:]) or _static_bmp(args[1:]) |
| 45 | + if args[0] == "bpr": |
| 46 | + return _static_bpr(args[1:]) |
| 47 | + if args[0] == "bmp": |
| 48 | + return _static_bmp(args[1:]) |
| 49 | + |
| 50 | + print("Usage: uv run test static [<COMMAND> [OPTIONS]]") |
| 51 | + print() |
| 52 | + print("Commands:") |
| 53 | + print(" all", "Run all static tests", sep="\t") |
| 54 | + print(" bpr", "Run basedpyright", sep="\t") |
| 55 | + print(" bmp", "Run basedmypy", sep="\t") |
| 56 | + return 1 |
| 57 | + |
| 58 | + |
| 59 | +def main(args: list[str] | None = None, /) -> int: |
| 60 | + if args is None: |
| 61 | + args = sys.argv[1:] |
| 62 | + if not args or args[0] != "static": |
| 63 | + print("Usage: uv run test <COMMAND>") |
| 64 | + print() |
| 65 | + print("Commands:") |
| 66 | + print(" static", "Static type-testing", sep="\t") |
| 67 | + return 1 |
| 68 | + |
| 69 | + return static(args[1:]) |
| 70 | + |
| 71 | + |
| 72 | +if __name__ == "__main__": |
| 73 | + sys.exit(main(sys.argv[1:])) |
0 commit comments