Files
stack/tests/dev/test_pkg_inventory.py
kert 7445d097fd
Some checks failed
CI / lint (push) Failing after 33s
Deploy / notebooks (push) Has been skipped
Deploy / zotero (push) Has been skipped
Deploy / docs (push) Has been skipped
Deploy / api (push) Has been skipped
Deploy / mc (push) Has been skipped
Deploy / report (push) Successful in 11s
CI / test (push) Successful in 25m55s
fix(ci): pkg_inventory parser drops inline comments cleanly
The pyproject dep parser did chained `.strip().strip(",").strip('"')`
which left trailing junk on lines with inline comments. The line:
    "pymupdf>=1.24",     # AGPL-3.0 — flag if shipping outside …
became the spec `pymupdf>=1.24",` — pip rejected it and the
pkg-supply-chain workflow failed on every push (#400-403).

Replace the four duplicated chained-strip blocks with a single
`_extract_dep_specs` helper that pulls the first quoted string from
each non-comment line. Same call from prod/dev/optional/build-system.

Manifest pypi count: 62 → 66 (parser was previously dropping a few
specs entirely, not just mangling pymupdf).

Add tests/dev/test_pkg_inventory.py with 4 regression tests covering
inline comments, blank/comment lines, single-quoted strings, and a
full pyproject excerpt with the bug pattern.

Closes the noise from #400-403.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 18:07:07 -04:00

76 lines
2.3 KiB
Python

"""Regression tests for dev/scripts/pkg_inventory.py.
Specifically guards the inline-comment bug that caused pkg-supply-chain
to fail on every push (issue #400-403): the previous parser did
``line.strip().strip(",").strip('"')`` which left trailing junk when a
dep line had an inline ``# comment``, producing invalid pip specs like
``pymupdf>=1.24",`` that broke the downstream PyPI mirror sync.
"""
from __future__ import annotations
import importlib.util
import sys
from pathlib import Path
# Load the script as a module — it lives outside the src/ tree.
_SCRIPT = Path(__file__).resolve().parents[2] / "dev" / "scripts" / "pkg_inventory.py"
_spec = importlib.util.spec_from_file_location("_pkg_inventory", _SCRIPT)
assert _spec and _spec.loader
_pkg_inventory = importlib.util.module_from_spec(_spec)
sys.modules["_pkg_inventory"] = _pkg_inventory
_spec.loader.exec_module(_pkg_inventory)
def test_extract_dep_specs_strips_inline_comments():
block = """
"pymupdf>=1.24", # AGPL-3.0 — flag if shipping outside internal use
"python-docx>=1.1",
"ruff>=0.11.0", # linter
"no-comment>=2.0",
"""
specs = _pkg_inventory._extract_dep_specs(block)
assert specs == [
"pymupdf>=1.24",
"python-docx>=1.1",
"ruff>=0.11.0",
"no-comment>=2.0",
]
def test_extract_dep_specs_skips_blank_and_comment_lines():
block = """
# this whole line is a comment
"pkg>=1.0",
# indented comment
"""
assert _pkg_inventory._extract_dep_specs(block) == ["pkg>=1.0"]
def test_extract_dep_specs_handles_single_quotes():
block = """
'singlequoted>=1.0',
"doublequoted>=2.0",
"""
assert _pkg_inventory._extract_dep_specs(block) == [
"singlequoted>=1.0",
"doublequoted>=2.0",
]
def test_parse_pyproject_deps_real_pymupdf_line():
"""Full integration — parse a small pyproject excerpt with the bug pattern."""
text = """[project]
name = "test"
dependencies = [
"pymupdf>=1.24", # AGPL-3.0 — flag if shipping outside internal use
"python-docx>=1.1",
]
"""
prod, _dev = _pkg_inventory._parse_pyproject_deps(text)
names = sorted(p["name"] for p in prod)
assert names == ["pymupdf", "python-docx"]
versions = {p["name"]: p["version"] for p in prod}
assert versions["pymupdf"] == ">=1.24" # NOT '>=1.24",'