Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bin/customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ done

echo "==> Checking for stale 'placeholder' references"
STALE="$(grep -rn 'placeholder' "$PACKAGE" pyproject.toml .releaserc.yaml || true)"
# The author/email and description options are intentionally optional. When a
# caller omits one of them, the corresponding template default remains until
# the generated plugin is edited; those expected defaults are not stale paths.
if [[ -z "$AUTHOR" || -z "$EMAIL" ]]; then
STALE="$(printf '%s\n' "$STALE" | grep -vE 'pyproject\.toml:[0-9]+:authors =' || true)"
fi
if [[ -z "$DESCRIPTION" ]]; then
STALE="$(printf '%s\n' "$STALE" | grep -vE 'pyproject\.toml:[0-9]+:description =' || true)"
fi
if [[ -n "$STALE" ]]; then
echo "Error: stale 'placeholder' references found in customized files:" >&2
printf '%s\n' "$STALE" >&2
Expand Down
62 changes: 62 additions & 0 deletions tests/test_customize_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""End-to-end tests for the template customization script."""

from __future__ import annotations

import shutil
import subprocess
from pathlib import Path


REPO_ROOT = Path(__file__).resolve().parent.parent


def _make_scaffold(tmp_path: Path, extra_pyproject: str = "") -> Path:
root = tmp_path / "scaffold"
(root / "bin").mkdir(parents=True)
(root / "placeholder").mkdir()
(root / "placeholder" / "module.py").write_text(
"from placeholder.feature_groups import manifest\n", encoding="utf-8"
)
shutil.copy2(REPO_ROOT / "bin" / "customize.sh", root / "bin" / "customize.sh")
shutil.copy2(REPO_ROOT / "pyproject.toml", root / "pyproject.toml")
shutil.copy2(REPO_ROOT / ".releaserc.yaml", root / ".releaserc.yaml")
if extra_pyproject:
pyproject = root / "pyproject.toml"
pyproject.write_text(
pyproject.read_text(encoding="utf-8") + extra_pyproject,
encoding="utf-8",
)
return root


def _run_customize(root: Path, *args: str) -> subprocess.CompletedProcess[str]:
return subprocess.run(
["bash", "bin/customize.sh", *args],
cwd=root,
capture_output=True,
check=False,
text=True,
)


def test_optional_fields_can_be_left_for_manual_editing(tmp_path: Path) -> None:
"""Omitting optional flags does not make the scaffold command fail."""
root = _make_scaffold(tmp_path)

result = _run_customize(root, "acme")

assert result.returncode == 0, result.stdout + result.stderr
assert (root / "acme").is_dir()


def test_unexpected_entry_point_placeholder_still_fails(tmp_path: Path) -> None:
"""The stale-reference check still rejects a missed entry-point rename."""
root = _make_scaffold(
tmp_path,
'\n[project.entry-points."mloda.feature_groups.extra"]\nleftover = "placeholder.unrelated:FEATURE_GROUPS"\n',
)

result = _run_customize(root, "acme")

assert result.returncode == 1
assert "stale 'placeholder' references" in result.stderr
Loading