From 5d4f9417fde261a2611f7d1f70bab1bb92405cd9 Mon Sep 17 00:00:00 2001 From: nvaldez Date: Wed, 18 Nov 2026 21:16:07 +0100 Subject: [PATCH] daedalus 0.2.0: hello - sample python script (category test) printing the greeting and app version; first registry entry with tests, README row, and daedalus.hello package Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- CHANGELOG.md | 8 +++++ README.md | 15 ++++++++-- daedalus/registry.py | 10 +++++-- daedalus/tests/test_cli.py | 2 +- pyproject.toml | 4 ++- python/src/hello/hello.py | 44 +++++++++++++++++++++++++++ python/tests/test_hello.py | 61 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 137 insertions(+), 7 deletions(-) create mode 100644 python/src/hello/hello.py create mode 100644 python/tests/test_hello.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 1755e62..7749fcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,14 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and - Nothing yet. +## [0.2.0] - 2026-11-18 + +### Added in 0.2.0 + +- `hello`: sample Python script (category `test`) that prints a hello + line and the daedalus version; first registered script, with tests and + an installed package entry (`daedalus.hello`). + ## [0.1.0] - 2026-11-18 ### Added in 0.1.0 diff --git a/README.md b/README.md index 685202a..8634627 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,15 @@ daedalus --list # list everything | Script | Type | Categories | What it does | | --- | --- | --- | --- | -| *(none yet)* | — | — | Add scripts per [AGENTS section 5](./AGENTS.md#5-integrating-a-script) or [SPEC section 6](./SPEC.md#6-adding-a-script). | +| `hello` | Python | test | Prints a hello line and the daedalus version | + +Run the sample script: + +```bash +daedalus hello # hello from daedalus 0.2.0 +daedalus test hello # same, through the category prefix +daedalus test # list the scripts in the 'test' category +``` `daedalus --list` prints the version, a `script` / `type` / `categories` table, and each description wrapped under its row. @@ -31,5 +39,6 @@ table, and each description wrapped under its row. write tests, bump `version` in `pyproject.toml`, and run `python autotest.py`. -Until the registry has at least one script, `daedalus --list` prints an -empty catalog and unknown names exit with code 2. +`hello` is the sample script: copy its file, registry entry, README row, +and tests to add your own. Unknown names exit with code 2 and suggest +close matches. diff --git a/daedalus/registry.py b/daedalus/registry.py index 5105cf7..43f0f7b 100644 --- a/daedalus/registry.py +++ b/daedalus/registry.py @@ -53,8 +53,14 @@ class Script: return ", ".join(self.categories) -SCRIPTS: dict[str, Script] = {} -"""Every script daedalus can run; empty in this template (SPEC.md section 6).""" +SCRIPTS: dict[str, Script] = { + "hello": Script( + path="python/src/hello/hello.py", + description="Print a hello line and the daedalus version", + categories="test", + ), +} +"""Every script daedalus can run (SPEC.md section 4).""" def used_categories() -> set[str]: diff --git a/daedalus/tests/test_cli.py b/daedalus/tests/test_cli.py index bfff0f4..586641c 100644 --- a/daedalus/tests/test_cli.py +++ b/daedalus/tests/test_cli.py @@ -140,7 +140,7 @@ def test_path(fake_registry, capsys): assert capsys.readouterr().out.strip() == str(LIBRARY_ROOT / "python/src/alpha/alpha.py") -@pytest.mark.parametrize("installed, expected", [(True, "daedalus 1.2.3"), (False, "daedalus 0.1.0")]) +@pytest.mark.parametrize("installed, expected", [(True, "daedalus 1.2.3"), (False, "daedalus 0.2.0")]) def test_version(monkeypatch, capsys, installed, expected): """--version uses metadata or pyproject.toml in a checkout.""" def fake_version(_name): diff --git a/pyproject.toml b/pyproject.toml index 9e4928c..ba68dc5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "daedalus" -version = "0.1.0" +version = "0.2.0" description = "Template for daedalus: loose scripts in one repo, run with: daedalus [args...]" readme = "README.md" requires-python = ">=3.11" @@ -19,6 +19,7 @@ daedalus = "daedalus.cli:main" packages = [ "daedalus", "daedalus.daedalus_logging", + "daedalus.hello", "daedalus._library.python.src", "daedalus._library.bash", "daedalus._library.powershell", @@ -26,6 +27,7 @@ packages = [ ] [tool.setuptools.package-dir] +"daedalus.hello" = "python/src/hello" "daedalus._library.python.src" = "python/src" "daedalus._library.bash" = "bash" "daedalus._library.powershell" = "powershell" diff --git a/python/src/hello/hello.py b/python/src/hello/hello.py new file mode 100644 index 0000000..675c57c --- /dev/null +++ b/python/src/hello/hello.py @@ -0,0 +1,44 @@ +"""Print a hello line and the daedalus version. + +Run via daedalus: ``daedalus hello`` (see daedalus README). A sample +script that exercises the registry, categories, the ``test`` category +listing, and the run_python_script entry end to end. +""" +from __future__ import annotations + +import argparse +import importlib.metadata +import pathlib +import sys +import tomllib + +UNKNOWN = "unknown" + + +def app_version() -> str: + """Installed daedalus version, else the checkout pyproject, else 'unknown'.""" + try: + return importlib.metadata.version("daedalus") # plain and editable installs + except importlib.metadata.PackageNotFoundError: + pass + # A checkout that is not installed: python/src/hello/hello.py -> pyproject.toml + pyproject = pathlib.Path(__file__).resolve().parents[3] / "pyproject.toml" + if pyproject.is_file(): + project = tomllib.loads(pyproject.read_text(encoding="utf-8")).get("project", {}) + version = project.get("version") + if isinstance(version, str) and version: + return version + return UNKNOWN + + +def main(argv: list[str] | None = None) -> int: + """Print ``hello from daedalus ``; return the exit code.""" + parser = argparse.ArgumentParser(prog="hello", + description=__doc__.splitlines()[0]) + parser.parse_args(argv) + print(f"hello from daedalus {app_version()}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/python/tests/test_hello.py b/python/tests/test_hello.py new file mode 100644 index 0000000..f038fe6 --- /dev/null +++ b/python/tests/test_hello.py @@ -0,0 +1,61 @@ +"""Tests for hello: version resolution, output, and end-to-end runs. + +Pure functions, main with argument lists, and the category-prefixed CLI +form (daedalus agent rule 5.6). +""" +import os +import subprocess +import sys + +import pytest + +from daedalus import REPO_ROOT +from daedalus.hello import hello + + +def test_main_prints_hello_and_version(capsys): + """main prints the greeting with a resolved version and exits 0.""" + assert hello.main([]) == 0 + out = capsys.readouterr().out.strip() + assert out.startswith("hello from daedalus ") + assert hello.UNKNOWN not in out + + +def test_app_version_from_metadata(monkeypatch): + """An installed daedalus resolves its version from the metadata.""" + monkeypatch.setattr(hello.importlib.metadata, "version", + lambda _name: "9.9.9") + assert hello.app_version() == "9.9.9" + + +def test_app_version_falls_back_to_pyproject(monkeypatch): + """A checkout that is not installed reads pyproject.toml (SPEC item 3.9.2).""" + def not_found(_name): + raise hello.importlib.metadata.PackageNotFoundError(_name) + + monkeypatch.setattr(hello.importlib.metadata, "version", not_found) + assert hello.app_version() == "0.2.0" + + +def test_help_exits_zero(capsys): + """hello --help shows the script's own usage (SPEC item 3.1.1).""" + with pytest.raises(SystemExit) as excinfo: + hello.main(["--help"]) + assert excinfo.value.code == 0 + assert "usage: hello" in capsys.readouterr().out + + +def run_cli(*args: str) -> subprocess.CompletedProcess: + """Run the real daedalus CLI from outside the repo.""" + env = {**os.environ, "PYTHONPATH": str(REPO_ROOT)} + return subprocess.run([sys.executable, "-m", "daedalus", *args], + capture_output=True, text=True, check=False, + cwd=REPO_ROOT.parent, env=env) + + +@pytest.mark.parametrize("argv", (["hello"], ["test", "hello"])) +def test_daedalus_runs_hello(argv): + """daedalus hello and daedalus test hello both print the greeting (SPEC item 3.2).""" + result = run_cli(*argv) + assert result.returncode == 0, result.stderr + assert result.stdout.startswith("hello from daedalus ")