mirror of
https://github.com/github/spec-kit.git
synced 2026-08-03 06:26:30 +08:00
* feat(scripts): port create-new-feature, setup-plan and setup-tasks to Python Ports the three core workflow scripts to Python as part of #3280, following the check-prerequisites PoC pattern from #3302. Adds resolve_template() to the shared common.py module and parity tests that run bash and Python side by side. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(tests): treat only None env as unset in parity run helper Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): fall back to directory scan on any registry error, skip hidden preset dirs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * feat(templates): add py: lines for setup_plan and setup_tasks Ships with the scripts they reference; the remaining templates got their py: lines in #3403. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: support py variant in skills placeholder resolver resolve_skill_placeholders only accepted sh/ps, so a py init option fell into the fallback path and {SCRIPT} rendered without an interpreter prefix. Accept py and prefix the resolved interpreter, matching process_template. Also guard ps_cmd against a missing PowerShell with a clear assert. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * test: pin clean-error behavior for invalid --number Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * docs(scripts): reword unused-arg comment to match implementation The loop accepts and silently ignores extra positional args (it doesn't build a collected list); match the wording to what the code and setup-plan.sh actually do. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: fall back when configured script variant is missing from frontmatter Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): reject signed/whitespace --number values to match bash 10# parity The bash twin uses $((10#$BRANCH_NUMBER)), which rejects signed and whitespace-padded values. Python's int() accepted them (e.g. -1), producing a malformed -01-... prefix that sequential scans ignore. Restrict --number to unsigned decimal digits before conversion, and pin the parity with a bash-comparison test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): complete Python port installation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(integrations): fall back for missing script variants Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * test: make Python script checks platform-aware Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix Windows Python command invocation parity Use PowerShell's call operator for spaced Python interpreter paths and align setup-tasks missing-template errors across script variants. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): preserve cross-platform Python parity Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: reject signed PowerShell feature numbers Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): align feature number range Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): reject exhausted feature numbers Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): complete create feature parity Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): align create feature outputs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): harden cross-platform parity Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): keep truncation JSON clean Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): align setup failure parity Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): close parity edge cases Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): propagate PowerShell setup errors Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): harden fallback resolution Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): stabilize PowerShell fallbacks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): complete setup-plan parity Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(cli): require runnable script fallbacks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(cli): preserve shell fallback without preference Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): restore help and symlink parity - setup-tasks.ps1: check -Help before unknown-argument validation so '-Help --bogus' exits 0 like the Bash/Python variants - common.py: strip the repo root prefix lexically in persist_feature_json instead of resolve(), so a symlinked specs/ still persists the relative 'specs/NNN-name' path the Bash/PowerShell helpers store Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(scripts): align persist-hint quoting with shlex.quote - create-new-feature.sh: replace printf %q with a shell_quote helper that emits shlex.quote-identical output, so the persistence hints stay byte-identical between the Bash and Python variants (printf %q output also varies between bash versions) - promote the negative --number test to an all-variants parity test now that Bash and PowerShell reject signed values consistently - add a spaced-repo-path parity test for the persistence hints Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
87 lines
2.7 KiB
Python
87 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Setup implementation plan for a feature."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import shutil
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
try:
|
|
from common import get_feature_paths, resolve_template
|
|
except ImportError: # pragma: no cover - direct execution from unusual cwd
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
from common import get_feature_paths, resolve_template
|
|
|
|
|
|
def _json_line(payload: object) -> str:
|
|
return json.dumps(payload, ensure_ascii=False, separators=(",", ":")) + "\n"
|
|
|
|
|
|
def _help_text(argv0: str) -> str:
|
|
return f"""Usage: {argv0} [--json]
|
|
--json Output results in JSON format
|
|
--help Show this help message
|
|
"""
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
args = list(argv if argv is not None else sys.argv[1:])
|
|
json_mode = False
|
|
for arg in args:
|
|
if arg == "--json":
|
|
json_mode = True
|
|
elif arg in {"--help", "-h"}:
|
|
sys.stdout.write(_help_text(sys.argv[0]))
|
|
return 0
|
|
# Other arguments are accepted and silently ignored, matching setup-plan.sh.
|
|
|
|
try:
|
|
paths = get_feature_paths(script_file=Path(__file__))
|
|
except SystemExit as exc:
|
|
if exc.code == 0:
|
|
return 0
|
|
print("ERROR: Failed to resolve feature paths", file=sys.stderr)
|
|
return int(exc.code) if isinstance(exc.code, int) else 1
|
|
|
|
paths.feature_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Status messages go to stderr in JSON mode so stdout stays pure JSON.
|
|
status_stream = sys.stderr if json_mode else sys.stdout
|
|
if paths.impl_plan.is_file():
|
|
print(
|
|
f"Plan already exists at {paths.impl_plan}, skipping template copy",
|
|
file=status_stream,
|
|
)
|
|
else:
|
|
template = resolve_template("plan-template", paths.repo_root)
|
|
if template is not None and template.is_file():
|
|
shutil.copy(template, paths.impl_plan)
|
|
print(f"Copied plan template to {paths.impl_plan}", file=status_stream)
|
|
else:
|
|
print("Warning: Plan template not found", file=status_stream)
|
|
paths.impl_plan.touch()
|
|
|
|
if json_mode:
|
|
sys.stdout.write(
|
|
_json_line(
|
|
{
|
|
"FEATURE_SPEC": str(paths.feature_spec),
|
|
"IMPL_PLAN": str(paths.impl_plan),
|
|
"SPECS_DIR": str(paths.feature_dir),
|
|
"BRANCH": paths.current_branch,
|
|
}
|
|
)
|
|
)
|
|
else:
|
|
print(f"FEATURE_SPEC: {paths.feature_spec}")
|
|
print(f"IMPL_PLAN: {paths.impl_plan}")
|
|
print(f"SPECS_DIR: {paths.feature_dir}")
|
|
print(f"BRANCH: {paths.current_branch}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|