Skip to content

armgit / Soup

Public Imported from GitHub
0

Fine-tune LLMs from one YAML. Layer streaming trains an 8B model on a 4 GB laptop GPU.

feat(cli): add eager --version option (#2101) (#2105)

Nariman Abdikarim4dc0bc38b33d
diff --git a/changelog.d/0.76.0/2105.added.md b/changelog.d/0.76.0/2105.added.md
new file mode 100644
index 00000000..771163f9
--- /dev/null
+++ b/changelog.d/0.76.0/2105.added.md
@@ -0,0 +1 @@
+- Add eager `--version` option to the root CLI, printing package version and repository URL without importing heavy dependencies (#2101, #2105 by @Nari-Ab).
diff --git a/docs/cli-reference.md b/docs/cli-reference.md
index 62978cf2..563c2edc 100644
--- a/docs/cli-reference.md
+++ b/docs/cli-reference.md
@@ -34,6 +34,7 @@ Usage: `soup [OPTIONS] <command> [ARGS]...`
| Name | Type | Default | Required | Help |
|---|---|---|---|---|
+| `--version` | flag | off | | Show Soup CLI version. |
| `--verbose`, `-V` | flag | off | | Show full traceback on errors |
| `--log-level` | text | `normal` | | Logging tier: quiet \| normal \| verbose \| debug |
| `--no-audit-log` | flag | off | | Disable the local HIPAA/SOC2 audit log for this invocation (also via SOUP_NO_AUDIT_LOG=1). Default: a one-line record per command under \~/.soup/audit.jsonl. v0.71.3. |
diff --git a/docs/commands.md b/docs/commands.md
index 86296a11..a37a1285 100644
--- a/docs/commands.md
+++ b/docs/commands.md
@@ -381,6 +381,7 @@ soup train # task in {sft,tts} + train_router_only=true [+moe_lora] Freeze MoE
soup train # quantization='bitnet_1.58' BitNet 1.58 training is not implemented; config load refuses it
soup export --model ./output --format bitnet|tq1_0 BitNet 1.58 TQ1_0 ternary GGUF via llama.cpp — LIVE (v0.71.20)
soup version [--full] [--json] Show version (--full: system info, --json: JSON output)
+soup --version Show version (prints the same text as soup version)
soup --verbose <command> Full traceback on errors
```
diff --git a/src/soup_cli/cli.py b/src/soup_cli/cli.py
index 49db2d2d..e09f580f 100644
--- a/src/soup_cli/cli.py
+++ b/src/soup_cli/cli.py
@@ -737,9 +737,23 @@ def _installed_extras() -> list[str]:
return sorted(installed)
+def version_callback(value: bool) -> None:
+ if value:
+ console.print(f"[bold green]soup[/] v{__version__}")
+ console.print(f"[dim]{GITHUB_URL}[/]")
+ raise typer.Exit(code=0)
+
+
@app.callback(invoke_without_command=True)
def main(
ctx: typer.Context,
+ version: bool = typer.Option(
+ False,
+ "--version",
+ help="Show Soup CLI version.",
+ callback=version_callback,
+ is_eager=True,
+ ),
verbose: bool = typer.Option(
False,
"--verbose",
diff --git a/tests/test_cli_startup_is_light.py b/tests/test_cli_startup_is_light.py
index 15b822cd..57d7e78a 100644
--- a/tests/test_cli_startup_is_light.py
+++ b/tests/test_cli_startup_is_light.py
@@ -159,6 +159,7 @@ def test_every_command_module_is_imported_at_startup():
# module lazily at call time -- which the startup assertion cannot see.
LIGHT_INVOCATIONS = [
["version"],
+ ["--version"],
["--help"],
["recipes", "list"],
["recipes", "search", "llama"],
diff --git a/tests/test_cli_version_flag.py b/tests/test_cli_version_flag.py
new file mode 100644
index 00000000..803a1ae1
--- /dev/null
+++ b/tests/test_cli_version_flag.py
@@ -0,0 +1,46 @@
+"""Tests for eager `soup --version` CLI flag (#2101)."""
+
+from __future__ import annotations
+
+import json
+
+from typer.testing import CliRunner
+
+from soup_cli import __version__
+from soup_cli.cli import app
+from soup_cli.utils.constants import GITHUB_URL
+from tests.conftest import strip_ansi
+
+
+def _plain(text: str) -> str:
+ """Whitespace-collapsed, ANSI-stripped output."""
+ return " ".join(strip_ansi(text).split())
+
+
+class TestVersionFlag:
+ def test_soup_version_flag_exits_zero_and_prints_version(self):
+ result = CliRunner().invoke(app, ["--version"])
+ assert result.exit_code == 0, (result.output, repr(result.exception))
+ output = _plain(result.output)
+ assert f"soup v{__version__}" in output
+ assert GITHUB_URL in output
+
+ def test_soup_version_flag_matches_version_subcommand_output(self):
+ flag_result = CliRunner().invoke(app, ["--version"])
+ cmd_result = CliRunner().invoke(app, ["version"])
+ assert flag_result.exit_code == 0, (flag_result.output, repr(flag_result.exception))
+ assert cmd_result.exit_code == 0, (cmd_result.output, repr(cmd_result.exception))
+ assert _plain(flag_result.output) == _plain(cmd_result.output)
+
+ def test_soup_version_flag_is_eager_over_help(self):
+ result = CliRunner().invoke(app, ["--version", "--help"])
+ assert result.exit_code == 0, (result.output, repr(result.exception))
+ output = _plain(result.output)
+ assert f"soup v{__version__}" in output
+ assert "Usage" not in output
+
+ def test_version_subcommand_remains_functional(self):
+ json_result = CliRunner().invoke(app, ["version", "--json"])
+ assert json_result.exit_code == 0, (json_result.output, repr(json_result.exception))
+ data = json.loads(json_result.output)
+ assert data["version"] == __version__