Skip to content

Commit adcd6a3

Browse files
committed
fix(offline): error out if --offline fails instead of falling back to network
- _locate_core_pack() docstring now accurately describes that it only finds wheel-bundled core_pack/; source-checkout fallback lives in callers - init() --offline + no bundled assets now exits with a clear error (previously printed a warning and silently fell back to GitHub download) - init() scaffold failure under --offline now exits with an error instead of retrying via download_and_extract_template Addresses reviewer comment: github#1803
1 parent ecd7fba commit adcd6a3

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

src/specify_cli/__init__.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -988,12 +988,14 @@ def download_and_extract_template(project_path: Path, ai_assistant: str, script_
988988

989989

990990
def _locate_core_pack() -> Path | None:
991-
"""Return the filesystem path to the bundled core_pack directory.
991+
"""Return the filesystem path to the bundled core_pack directory, or None.
992992
993-
Works for wheel installs (hatchling force-include puts the directory next to
994-
__init__.py as specify_cli/core_pack/) and for source-checkout / editable
995-
installs (falls back to the repo-root templates/ and scripts/ trees).
996-
Returns None only when neither location exists.
993+
Only present in wheel installs: hatchling's force-include copies
994+
templates/, scripts/ etc. into specify_cli/core_pack/ at build time.
995+
996+
Source-checkout and editable installs do NOT have this directory.
997+
Callers that need to work in both environments must check the repo-root
998+
trees (templates/, scripts/) as a fallback when this returns None.
997999
"""
9981000
# Wheel install: core_pack is a sibling directory of this file
9991001
candidate = Path(__file__).parent / "core_pack"
@@ -1740,7 +1742,13 @@ def init(
17401742
_has_bundled = (_core is not None) or _repo_commands.is_dir()
17411743

17421744
if offline and not _has_bundled:
1743-
console.print("[yellow]Warning:[/yellow] --offline requested but no bundled assets found; falling back to GitHub download")
1745+
console.print(
1746+
"\n[red]Error:[/red] --offline was specified but no bundled assets were found.\n"
1747+
" • Wheel install: reinstall the specify-cli wheel (core_pack/ must be present).\n"
1748+
" • Source checkout: run from the repo root so templates/ and scripts/ are accessible.\n"
1749+
"Remove --offline to attempt a GitHub download instead."
1750+
)
1751+
raise typer.Exit(1)
17441752

17451753
use_github = not (offline and _has_bundled)
17461754

@@ -1785,7 +1793,15 @@ def init(
17851793
else:
17861794
scaffold_ok = scaffold_from_core_pack(project_path, selected_ai, selected_script, here, tracker=tracker)
17871795
if not scaffold_ok:
1788-
# Unexpected failure — fall back to GitHub download
1796+
if offline:
1797+
# --offline explicitly requested: never attempt a network download
1798+
console.print(
1799+
"\n[red]Error:[/red] --offline was specified but scaffolding from bundled assets failed.\n"
1800+
"Ensure the specify-cli wheel was installed correctly (it must include core_pack/).\n"
1801+
"Remove --offline to attempt a GitHub download instead."
1802+
)
1803+
raise typer.Exit(1)
1804+
# No explicit offline flag — fall back to GitHub download
17891805
for key, label in [
17901806
("fetch", "Fetch latest release"),
17911807
("download", "Download template"),

0 commit comments

Comments
 (0)