Skip to content

Commit 8c52570

Browse files
hkJerryLeungTomKaltofen
authored andcommitted
fix: allow optional customize fields to keep defaults
1 parent b8127f4 commit 8c52570

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

bin/customize.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ done
139139

140140
echo "==> Checking for stale 'placeholder' references"
141141
STALE="$(grep -rn 'placeholder' "$PACKAGE" pyproject.toml .releaserc.yaml || true)"
142+
# The author/email and description options are intentionally optional. When a
143+
# caller omits one of them, the corresponding template default remains until
144+
# the generated plugin is edited; those expected defaults are not stale paths.
145+
if [[ -z "$AUTHOR" || -z "$EMAIL" ]]; then
146+
STALE="$(printf '%s\n' "$STALE" | grep -vE 'pyproject\.toml:[0-9]+:authors =' || true)"
147+
fi
148+
if [[ -z "$DESCRIPTION" ]]; then
149+
STALE="$(printf '%s\n' "$STALE" | grep -vE 'pyproject\.toml:[0-9]+:description =' || true)"
150+
fi
142151
if [[ -n "$STALE" ]]; then
143152
echo "Error: stale 'placeholder' references found in customized files:" >&2
144153
printf '%s\n' "$STALE" >&2

tests/test_customize_script.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""End-to-end tests for the template customization script."""
2+
3+
from __future__ import annotations
4+
5+
import shutil
6+
import subprocess
7+
from pathlib import Path
8+
9+
10+
REPO_ROOT = Path(__file__).resolve().parent.parent
11+
12+
13+
def _make_scaffold(tmp_path: Path, extra_pyproject: str = "") -> Path:
14+
root = tmp_path / "scaffold"
15+
(root / "bin").mkdir(parents=True)
16+
(root / "placeholder").mkdir()
17+
(root / "placeholder" / "module.py").write_text(
18+
"from placeholder.feature_groups import manifest\n", encoding="utf-8"
19+
)
20+
shutil.copy2(REPO_ROOT / "bin" / "customize.sh", root / "bin" / "customize.sh")
21+
shutil.copy2(REPO_ROOT / "pyproject.toml", root / "pyproject.toml")
22+
shutil.copy2(REPO_ROOT / ".releaserc.yaml", root / ".releaserc.yaml")
23+
if extra_pyproject:
24+
pyproject = root / "pyproject.toml"
25+
pyproject.write_text(
26+
pyproject.read_text(encoding="utf-8") + extra_pyproject,
27+
encoding="utf-8",
28+
)
29+
return root
30+
31+
32+
def _run_customize(root: Path, *args: str) -> subprocess.CompletedProcess[str]:
33+
return subprocess.run(
34+
["bash", "bin/customize.sh", *args],
35+
cwd=root,
36+
capture_output=True,
37+
check=False,
38+
text=True,
39+
)
40+
41+
42+
def test_optional_fields_can_be_left_for_manual_editing(tmp_path: Path) -> None:
43+
"""Omitting optional flags does not make the scaffold command fail."""
44+
root = _make_scaffold(tmp_path)
45+
46+
result = _run_customize(root, "acme")
47+
48+
assert result.returncode == 0, result.stdout + result.stderr
49+
assert (root / "acme").is_dir()
50+
51+
52+
def test_unexpected_entry_point_placeholder_still_fails(tmp_path: Path) -> None:
53+
"""The stale-reference check still rejects a missed entry-point rename."""
54+
root = _make_scaffold(
55+
tmp_path,
56+
'\n[project.entry-points."mloda.feature_groups.extra"]\nleftover = "placeholder.unrelated:FEATURE_GROUPS"\n',
57+
)
58+
59+
result = _run_customize(root, "acme")
60+
61+
assert result.returncode == 1
62+
assert "stale 'placeholder' references" in result.stderr

0 commit comments

Comments
 (0)