-
Notifications
You must be signed in to change notification settings - Fork 10.2k
feat(cli): honor SPECIFY_INIT_DIR in the specify CLI project resolver #3186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PascalThuet
wants to merge
8
commits into
github:main
Choose a base branch
from
PascalThuet:feat/init-dir-python-cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+416
−7
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ce441cb
feat(cli): honor SPECIFY_INIT_DIR in the specify CLI project resolver
PascalThuet 33991d9
fix(cli): honor SPECIFY_INIT_DIR for bundle commands
PascalThuet 6520d56
fix(bundler): refuse symlinked .specify on the SPECIFY_INIT_DIR overr…
PascalThuet eb33446
fix(cli): keep SPECIFY_INIT_DIR strict for bundles
PascalThuet 8a426e7
docs(core): note symlinked .specify handling differs across CLI surfaces
PascalThuet 97c4720
docs(core): reframe symlinked .specify note around the override invar…
PascalThuet 80316e6
docs: address Copilot review on resolver docstrings
PascalThuet 066a191
docs(bundler): note require_project_root inherits the override raise …
PascalThuet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """Shared project-resolution helpers for the Specify CLI.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
|
|
||
| import typer | ||
|
|
||
| from ._console import console | ||
|
|
||
|
|
||
| def _resolve_init_dir_override() -> Path | None: | ||
| """Resolve the ``SPECIFY_INIT_DIR`` project override for the Python CLI. | ||
|
|
||
| Applies the same validation rules as the shell resolver | ||
| (``resolve_specify_init_dir`` in ``scripts/bash/common.sh``): the value names | ||
| the project root — the directory *containing* ``.specify/`` — and is strict. | ||
| Relative paths resolve against the current directory; the path must exist and | ||
| contain ``.specify/``, otherwise this hard-errors with no fallback to cwd | ||
| (which would silently operate on the wrong project's files). The error | ||
| messages mirror the shell resolver's wording (rendered here as a Rich | ||
| ``Error:`` line, plain ``ERROR:`` in the shell) so the two surfaces read | ||
| consistently. | ||
|
|
||
| Returns the validated absolute project root, or ``None`` when the variable is | ||
| unset/empty, in which case callers keep their existing cwd-based behavior. | ||
|
|
||
| Note: this canonicalizes symlinks via :meth:`Path.resolve` (physical path), | ||
| whereas the shell ``cd -- "$X" && pwd`` keeps the logical path. The two agree | ||
| for non-symlinked paths; a symlinked ``SPECIFY_INIT_DIR`` can resolve to | ||
| different strings across the surfaces. The canonical form is the safer choice | ||
| here (a stable project identity), so this is a deliberate, documented variance, | ||
| not a parity guarantee on the resolved string. | ||
| """ | ||
| raw = os.environ.get("SPECIFY_INIT_DIR", "") | ||
| if not raw: | ||
| return None | ||
| # Relative values resolve against cwd; an absolute value stands alone (Path's | ||
| # `/` drops the left operand when the right is absolute). resolve() also | ||
| # collapses a trailing slash and canonicalizes symlinks. | ||
| init_root = (Path.cwd() / raw).resolve() | ||
| if not init_root.is_dir(): | ||
| console.print( | ||
| f"[red]Error:[/red] SPECIFY_INIT_DIR does not point to an existing directory: {raw}" | ||
| ) | ||
| raise typer.Exit(1) | ||
| if not (init_root / ".specify").is_dir(): | ||
| console.print( | ||
| f"[red]Error:[/red] SPECIFY_INIT_DIR is not a Spec Kit project (no .specify/ directory): {init_root}" | ||
| ) | ||
| raise typer.Exit(1) | ||
| return init_root |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.