Commit 8b6595fc authored by Eric Duminil's avatar Eric Duminil
Browse files

Added --version

parent db9f4b15
......@@ -63,12 +63,12 @@ simstadt
# See help
simstadt --help
usage: simstadt [-h] [--gui] [--csv-export] [--install] [-d DESCRIPTION] [--destination DESTINATION] [-p PROJECT_PATH] [-f] [-s PATH] [-v] [template] [citygml]
usage: simstadt [-h] [--gui] [--csv-export] [--install] [-d DESCRIPTION] [--destination DESTINATION] [-p PROJECT_PATH] [-f] [-s PATH] [-v] [-V] [template] [citygml]
simstadt - Python library for SimStadt workflows.
positional arguments:
template Template name (from SIMSTADT_TEMPLATE_PATH) or path to a .flow directory.
template Template name (from SIMSTADT_TEMPLATE_PATH), path to a .flow directory, or a bundled template name.
citygml Path to the CityGML input file.
options:
......@@ -85,6 +85,10 @@ simstadt --help
-f, --files Show output files after the run.
-s PATH, --save PATH Save result DataFrame to a file (.csv or .json).
-v, --verbose Enable debug logging.
-V, --version Print the simstadtpy and SimStadt versions, then exit.
# Print the simstadtpy and SimStadt versions
simstadt --version
# Download and install the latest SimStadt release to ~/Desktop
simstadt --install
......
......@@ -50,6 +50,20 @@ def cmd_info(args: argparse.Namespace) -> None:
print("SimStadt version: unknown (could not parse version string)")
def cmd_version() -> None:
from importlib.metadata import version as pkg_version
from .runner import get_version_and_date
print(f"simstadtpy: {pkg_version('simstadt')}")
try:
version, date = get_version_and_date()
yyyy, mm, dd = date[:4], date[4:6], date[6:8]
print(f"SimStadt: {version} ({yyyy}-{mm}-{dd})")
except ValueError as e:
print(f"SimStadt: not found\n{e}", file=sys.stderr)
def cmd_run(args: argparse.Namespace) -> None:
logging.basicConfig(
level=logging.DEBUG if args.verbose else logging.WARNING,
......@@ -142,6 +156,12 @@ def build_parser() -> argparse.ArgumentParser:
parser.add_argument(
"-v", "--verbose", action="store_true", help="Enable debug logging."
)
parser.add_argument(
"-V",
"--version",
action="store_true",
help="Print the simstadtpy and SimStadt versions, then exit.",
)
return parser
......@@ -149,6 +169,10 @@ def simstadt_app() -> None:
parser = build_parser()
args = parser.parse_args()
if args.version:
cmd_version()
return
if args.install:
cmd_install()
......
......@@ -56,7 +56,10 @@ def find_simstadt(parent_folder: Path, simstadt_glob: str = SIMSTADT2_GLOB) -> P
def get_simstadt_folder() -> Path:
value = os.environ.get("SIMSTADT_FOLDER", "").strip()
if value:
return Path(value)
path = Path(value)
if not path.exists():
raise ValueError(f"SIMSTADT_FOLDER={value!r} does not exist.")
return path
return find_simstadt(Path.home() / "Desktop")
......
......@@ -66,6 +66,35 @@ def test_parser_all_flags():
assert args.save == Path("out.csv")
# ---------------------------------------------------------------------------
# cmd_version
# ---------------------------------------------------------------------------
def test_version_prints_package_version(run_cli, capsys):
out, _ = run_cli(capsys, "--version")
assert "simstadtpy: " in out
def test_version_prints_simstadt_version(monkeypatch, run_cli, capsys):
monkeypatch.setattr(
"simstadt.runner.get_version_and_date", lambda: ("1.2.3", "20260101")
)
out, err = run_cli(capsys, "-V")
assert "SimStadt: 1.2.3 (2026-01-01)" in out
assert err == ""
def test_version_reports_simstadt_not_found(monkeypatch, run_cli, capsys):
def _not_found():
raise ValueError("SimStadt not found")
monkeypatch.setattr("simstadt.runner.get_version_and_date", _not_found)
out, err = run_cli(capsys, "--version")
assert "simstadtpy: " in out # package version still printed
assert "SimStadt: not found" in err
# ---------------------------------------------------------------------------
# cmd_run
# ---------------------------------------------------------------------------
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment