Repository navigation
Expand file tree
/
Copy pathdev.py
More file actions
78 lines (53 loc) · 2.05 KB
/
Copy pathdev.py
File metadata and controls
78 lines (53 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
"""Local dev runner for uwidth-rs — stdlib Python driving cargo, no task runner.
The same `python dev.py check` gate as every nativelite package, so the muscle
memory is identical across languages. Here `check` is the zero-dependency guard
plus `cargo fmt --check` and `cargo test` (unit + doctests):
python dev.py check # guard + cargo fmt --check + cargo test
python dev.py test # cargo test
python dev.py build # cargo build --release
python dev.py fmt # cargo fmt --check
python dev.py guard # zero-dependency guard
python dev.py gen # regenerate src/tables.rs from tools/ucd
`gen` re-runs the table generator; it needs the UCD text files under
`tools/ucd/` (not vendored — download the four files named in tools/gen_tables.py
from unicode.org for the pinned release, then run `gen` and commit the diff).
"""
from __future__ import annotations
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent
PY = sys.executable
def run(*args: str) -> int:
print(f"$ {' '.join(args)}")
return subprocess.call(args, cwd=str(ROOT))
def test() -> int:
return run("cargo", "test", "--all-targets") or run("cargo", "test", "--doc")
def build() -> int:
return run("cargo", "build", "--release")
def fmt() -> int:
return run("cargo", "fmt", "--check")
def guard() -> int:
return run(PY, "tools/dep_guard.py")
def gen() -> int:
return run(PY, "tools/gen_tables.py", "tools/ucd", "src/tables.rs")
def check() -> int:
return guard() or fmt() or test()
COMMANDS = {
"test": test,
"build": build,
"fmt": fmt,
"guard": guard,
"gen": gen,
"check": check,
}
def main(argv: list[str]) -> int:
cmd = argv[1] if len(argv) > 1 else "check"
fn = COMMANDS.get(cmd)
if fn is None:
print(f"unknown command {cmd!r}; choose from: {', '.join(COMMANDS)}")
return 2
return fn()
if __name__ == "__main__":
raise SystemExit(main(sys.argv))