Skip to content

Commit feb45de

Browse files
committed
Cleanup generation
1 parent 76d1d94 commit feb45de

8 files changed

Lines changed: 151 additions & 126 deletions

File tree

MODULE.bazel.lock

Lines changed: 14 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bazel_common/score_python.MODULE.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
1313
bazel_dep(name = "rules_python", version = "1.8.3")
14-
bazel_dep(name = "aspect_rules_py", version = "1.4.0")
14+
bazel_dep(name = "aspect_rules_py", version = "1.5.2")
1515

1616
PYTHON_VERSION = "3.12"
1717

@@ -29,7 +29,6 @@ pip.parse(
2929
requirements_lock = "//feature_integration_tests/test_cases:requirements.txt.lock",
3030
)
3131
use_repo(pip, "pip_score_venv_test")
32-
3332
pip.parse(
3433
envsubst = ["PIP_INDEX_URL"],
3534
extra_pip_args = ["--index-url=${PIP_INDEX_URL:-https://pypi.org/simple/}"],

scripts/tooling/cli/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************

scripts/tooling/cli/main.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
113
import argparse
214
import sys
315

@@ -7,7 +19,10 @@ def main() -> None:
719
subparsers = parser.add_subparsers(dest="group", metavar="GROUP")
820
subparsers.required = True
921

10-
from scripts.tooling.cli.misc import register as _register_misc
22+
try:
23+
from scripts.tooling.cli.misc import register as _register_misc
24+
except ImportError:
25+
from cli.misc import register as _register_misc # type: ignore[no-redef]
1126

1227
_register_misc(subparsers)
1328

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
113
import argparse
214

315

@@ -6,6 +18,9 @@ def register(subparsers: argparse._SubParsersAction) -> None:
618
misc_sub = misc_parser.add_subparsers(dest="command", metavar="COMMAND")
719
misc_sub.required = True
820

9-
from scripts.tooling.cli.misc.html_report import register as _register_html_report
21+
try:
22+
from scripts.tooling.cli.misc.html_report import register as _register_html_report
23+
except ImportError:
24+
from cli.misc.html_report import register as _register_html_report # type: ignore[no-redef]
1025

1126
_register_html_report(misc_sub)

scripts/tooling/cli/misc/html_report.py

Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
from __future__ import annotations
14+
115
import argparse
16+
import json
17+
import logging
218
import os
319
import sys
420
from pathlib import Path
21+
from typing import Any, Optional
22+
23+
from jinja2 import Environment, FileSystemLoader, select_autoescape
24+
25+
try:
26+
from scripts.tooling.lib.github import fetch_compare
27+
from scripts.tooling.lib.known_good import KnownGood, load_known_good
28+
except ImportError:
29+
from lib.github import fetch_compare # type: ignore[no-redef]
30+
from lib.known_good import KnownGood, load_known_good # type: ignore[no-redef]
31+
32+
_LOG = logging.getLogger(__name__)
533

634
TEMPLATE_DIR = Path(__file__).parent / "assets"
735

@@ -22,8 +50,69 @@ def _resolve_path_from_bazel(path: Path) -> Path:
2250
return path.resolve()
2351

2452

53+
def _collect_entries(known_good: KnownGood) -> list[dict[str, Any]]:
54+
entries = []
55+
for group_name, group_modules in known_good.modules.items():
56+
for module in group_modules.values():
57+
try:
58+
owner_repo = module.owner_repo
59+
except ValueError:
60+
owner_repo = None
61+
entries.append(
62+
{
63+
"name": module.name,
64+
"group": group_name,
65+
"repo": module.repo,
66+
"owner_repo": owner_repo,
67+
"hash": module.hash,
68+
"version": module.version,
69+
"branch": module.branch,
70+
"current_hash": None,
71+
"behind_by": None,
72+
"compare_status": None,
73+
}
74+
)
75+
return entries
76+
77+
78+
def _enrich_with_compare_data(entries: list[dict[str, Any]], token: str) -> None:
79+
for entry in entries:
80+
if not entry.get("owner_repo") or not entry.get("hash") or entry.get("version"):
81+
continue
82+
result = fetch_compare(entry["owner_repo"], entry["hash"], entry["branch"], token)
83+
if result:
84+
entry["current_hash"] = result.head_sha
85+
entry["behind_by"] = result.ahead_by
86+
entry["compare_status"] = result.status
87+
else:
88+
_LOG.warning(
89+
"Could not fetch compare data for %s@%s", entry["owner_repo"], entry["branch"]
90+
)
91+
92+
93+
def generate_report(known_good: KnownGood, token: Optional[str] = None) -> str:
94+
entries = _collect_entries(known_good)
95+
if token:
96+
_enrich_with_compare_data(entries, token)
97+
env = Environment(
98+
loader=FileSystemLoader(TEMPLATE_DIR),
99+
autoescape=select_autoescape(["html"]),
100+
)
101+
tmpl = env.get_template("report_template.html")
102+
return tmpl.render(
103+
modules_json=json.dumps(entries, indent=2),
104+
timestamp=known_good.timestamp,
105+
)
106+
107+
108+
def write_report(known_good: KnownGood, output_path: Path, token: Optional[str] = None) -> None:
109+
Path(output_path).write_text(generate_report(known_good, token), encoding="utf-8")
110+
111+
25112
def register(subparsers: argparse._SubParsersAction) -> None:
26-
parser = subparsers.add_parser("html_report", help="Generate an HTML status report from known_good.json")
113+
parser = subparsers.add_parser(
114+
"html_report", help="Generate an HTML status report from known_good.json"
115+
)
27116
parser.add_argument(
28117
"--known_good",
29118
metavar="PATH",
@@ -40,9 +129,6 @@ def register(subparsers: argparse._SubParsersAction) -> None:
40129

41130

42131
def _run(args: argparse.Namespace) -> int:
43-
from scripts.tooling.lib.html_report import write_report
44-
from scripts.tooling.lib.known_good import load_known_good
45-
46132
known_good_path = Path(args.known_good) / "known_good.json"
47133
try:
48134
known_good = load_known_good(known_good_path)
@@ -52,7 +138,7 @@ def _run(args: argparse.Namespace) -> int:
52138

53139
token = os.environ.get("GITHUB_TOKEN")
54140
output = _resolve_path_from_bazel(Path(args.output))
55-
write_report(known_good, output, TEMPLATE_DIR, token=token)
141+
write_report(known_good, output, token=token)
56142
if token:
57143
print(f"Report written to {output} (current hashes fetched from GitHub)")
58144
else:

scripts/tooling/lib/html_report.py

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)