Skip to content

Commit 0fb7d4c

Browse files
committed
Make entrypoint cleaner
1 parent f012938 commit 0fb7d4c

5 files changed

Lines changed: 57 additions & 700 deletions

File tree

scripts/tooling/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ py_binary(
4646
"cli/**/*.py",
4747
]),
4848
data = [
49-
"lib/assets/report_template.html",
49+
"cli/misc/assets/report_template.html",
5050
],
5151
main = "cli/main.py",
5252
visibility = ["//visibility:public"],
@@ -58,7 +58,7 @@ score_py_pytest(
5858
name = "tooling_tests",
5959
srcs = glob(["tests/**/*.py"]),
6060
data = [
61-
":lib/assets/report_template.html",
61+
":cli/misc/assets/report_template.html",
6262
],
6363
pytest_config = "//:pyproject.toml",
6464
deps = [

scripts/tooling/cli/main.py

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,17 @@
11
import argparse
2-
import os
32
import sys
4-
from pathlib import Path
5-
6-
7-
def _resolve_path_from_bazel(path: Path) -> Path:
8-
"""Resolve path relative to user's working directory when running via bazel run.
9-
10-
Bazel sets BUILD_WORKING_DIRECTORY to the directory where bazel was invoked.
11-
"""
12-
if not path.is_absolute():
13-
# When running via 'bazel run', resolve relative paths against the user's cwd
14-
build_working_dir = os.environ.get("BUILD_WORKING_DIRECTORY")
15-
if build_working_dir:
16-
return (Path(build_working_dir) / path).resolve()
17-
return path.resolve()
18-
19-
20-
def _find_repo_root() -> Path:
21-
"""Walk up from this file to find the repo root (contains known_good.json)."""
22-
candidate = Path(__file__).resolve()
23-
for parent in candidate.parents:
24-
if (parent / "known_good.json").exists():
25-
return parent
26-
return Path.cwd()
27-
28-
29-
def _cmd_html_report(args: argparse.Namespace) -> int:
30-
from scripts.tooling.lib.html_report import write_report
31-
from scripts.tooling.lib.known_good import load_known_good
32-
33-
known_good_path = Path(args.known_good) / "known_good.json"
34-
try:
35-
known_good = load_known_good(known_good_path)
36-
except (FileNotFoundError, ValueError) as exc:
37-
print(f"error: {exc}", file=sys.stderr)
38-
return 1
39-
40-
token = os.environ.get("GITHUB_TOKEN")
41-
output = _resolve_path_from_bazel(Path(args.output))
42-
write_report(known_good, output, token=token)
43-
if token:
44-
print(f"Report written to {output} (current hashes fetched from GitHub)")
45-
else:
46-
print(f"Report written to {output} (set GITHUB_TOKEN to embed current hashes)")
47-
return 0
483

494

505
def main() -> None:
516
parser = argparse.ArgumentParser(prog="tooling")
527
subparsers = parser.add_subparsers(dest="group", metavar="GROUP")
538
subparsers.required = True
549

55-
# --- misc group ---
56-
misc_parser = subparsers.add_parser("misc", help="Miscellaneous utilities")
57-
misc_sub = misc_parser.add_subparsers(dest="command", metavar="COMMAND")
58-
misc_sub.required = True
59-
60-
html_parser = misc_sub.add_parser("html_report", help="Generate an HTML status report from known_good.json")
61-
html_parser.add_argument(
62-
"--known_good",
63-
metavar="PATH",
64-
default=str(_find_repo_root()),
65-
help="Directory containing known_good.json (default: repo root)",
66-
)
67-
html_parser.add_argument(
68-
"--output",
69-
metavar="FILE",
70-
default="report.html",
71-
help="Output HTML file path (default: report.html)",
72-
)
10+
from scripts.tooling.cli.misc import register as _register_misc
11+
_register_misc(subparsers)
7312

7413
args = parser.parse_args()
75-
76-
if args.group == "misc" and args.command == "html_report":
77-
sys.exit(_cmd_html_report(args))
14+
sys.exit(args.func(args))
7815

7916

8017
if __name__ == "__main__":

0 commit comments

Comments
 (0)