devstats: rename html.py, it shadowed stdlib
Some checks are pending
file length / file-length (push) Waiting to run
kuhy_credit drift / drift (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run

Bug-class-check: devstats/tests/test_no_stdlib_shadow.py

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-11-27 19:20:47 +01:00
parent a41f3c6847
commit 593283d240
7 changed files with 31 additions and 7 deletions

View File

@ -14,7 +14,7 @@ from typing import TextIO
from devstats import article as A from devstats import article as A
from devstats.aggregate import DAY, RepoData, Window, dedup, window_totals from devstats.aggregate import DAY, RepoData, Window, dedup, window_totals
from devstats.discover import Repo, discover from devstats.discover import Repo, discover
from devstats.html import page from devstats.report_html import page
from devstats.numstat import read_commits from devstats.numstat import read_commits
from devstats.refs import list_refs, resolve, tag_times from devstats.refs import list_refs, resolve, tag_times
from devstats.render import by_repo, document, report from devstats.render import by_repo, document, report

View File

@ -1,7 +1,7 @@
"""Tables of kuhy beside the article, plus the optional per-repo breakdown. """Tables of kuhy beside the article, plus the optional per-repo breakdown.
The `*_rows` builders return (head, rows) of plain cell strings; the markdown The `*_rows` builders return (head, rows) of plain cell strings; the markdown
here and the HTML page in `devstats.html` both render those, so the page and here and the HTML page in `devstats.report_html` both render those, so the page and
the terminal always show the same numbers. the terminal always show the same numbers.
""" """

View File

@ -49,7 +49,7 @@ check_python() {
# Capped (2 GiB, 10 % CPU, idle IO) when kuhy's capped.sh exists, plain otherwise. # Capped (2 GiB, 10 % CPU, idle IO) when kuhy's capped.sh exists, plain otherwise.
run_devstats() { run_devstats() {
local cmd=(env "PYTHONPATH=$REPO_ROOT${PYTHONPATH:+:$PYTHONPATH}" python3 -m devstats compare "$@") local cmd=(env "PYTHONPATH=$REPO_ROOT${PYTHONPATH:+:$PYTHONPATH}" python3 -P -m devstats compare "$@")
if [[ -x "$CAPPED" ]]; then if [[ -x "$CAPPED" ]]; then
"$CAPPED" "${cmd[@]}" "$CAPPED" "${cmd[@]}"
else else

View File

@ -0,0 +1,17 @@
"""No devstats module may share a stdlib module's name.
`python -m devstats` run from inside `devstats/` puts that dir first on
sys.path, so a `devstats/html.py` replaced the stdlib `html` for every import.
"""
from __future__ import annotations
import sys
from pathlib import Path
PACKAGE = Path(__file__).resolve().parents[1]
def test_no_module_shadows_the_stdlib() -> None:
clashes = sorted(p.name for p in PACKAGE.glob("*.py") if p.stem in sys.stdlib_module_names)
assert clashes == []

View File

@ -6,7 +6,7 @@ import re
from html import unescape from html import unescape
from devstats.aggregate import Window from devstats.aggregate import Window
from devstats.html import CMDR, KUHY, chart, page from devstats.report_html import CMDR, KUHY, chart, page
from devstats.render import report from devstats.render import report

View File

@ -23,12 +23,12 @@ RUN_SH = Path(__file__).resolve().parents[1] / "run.sh"
BASE_TOOLS = ("bash", "realpath", "dirname", "mkdir", "cat", "setsid", "env") BASE_TOOLS = ("bash", "realpath", "dirname", "mkdir", "cat", "setsid", "env")
def run_sh(*args: str, path: str | None = None) -> subprocess.CompletedProcess[str]: def run_sh(*args: str, path: str | None = None, cwd: Path | str = "/") -> subprocess.CompletedProcess[str]:
"""Run run.sh from an unrelated cwd, optionally with a replaced PATH.""" """Run run.sh from an unrelated cwd (or `cwd`), optionally with a replaced PATH."""
env = dict(os.environ) env = dict(os.environ)
if path is not None: if path is not None:
env["PATH"] = path env["PATH"] = path
return subprocess.run([str(RUN_SH), *args], cwd="/", env=env, capture_output=True, text=True, return subprocess.run([str(RUN_SH), *args], cwd=cwd, env=env, capture_output=True, text=True,
check=False, timeout=50) check=False, timeout=50)
@ -56,6 +56,13 @@ def test_run_prints_tables_writes_report_and_no_warnings(src: Path) -> None:
assert 'class="chart"' in page assert 'class="chart"' in page
def test_run_from_inside_the_package_dir(src: Path) -> None:
"""`python -m` from devstats/ must not let a package module shadow the stdlib."""
proc = run_sh("--no-open", "--root", str(src), cwd=RUN_SH.parent)
assert proc.returncode == 0, proc.stderr
assert report_path().read_text().startswith("<!doctype html>")
def test_empty_root_exits_2_and_writes_no_report(tmp_path: Path) -> None: def test_empty_root_exits_2_and_writes_no_report(tmp_path: Path) -> None:
empty = tmp_path / "empty" empty = tmp_path / "empty"
empty.mkdir() empty.mkdir()