bd1a10487c
PyPI policy-blocks the plain name: the 0.12.1 upload was rejected with "The name 'daedalus' isn't allowed" (near the existing daedalus-cli and pydaedalus projects). The distribution is now daedalus-tools; command, imports, registry, and the repository name stay daedalus. hello's installed-version lookup follows. publish now derives artifact file names from the PEP 625 normalized name (daedalus_tools-<version>.tar.gz) - with a hyphenated project name the previously constructed names would have missed what setuptools writes to dist/ (publish spec 3.2, new regression test). Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
"""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
|
|
|
|
try: # SPEC item 6.9: complete hello's own arguments
|
|
from argcomplete import autocomplete
|
|
except ImportError: # pragma: no cover - completion off without argcomplete
|
|
autocomplete = None
|
|
|
|
UNKNOWN = "unknown"
|
|
|
|
|
|
def app_version() -> str:
|
|
"""Installed daedalus version, else the checkout pyproject, else 'unknown'."""
|
|
try:
|
|
return importlib.metadata.version("daedalus-tools") # 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 <version>``; return the exit code."""
|
|
parser = argparse.ArgumentParser(prog="hello",
|
|
description=__doc__.splitlines()[0])
|
|
if autocomplete is not None: # SPEC item 6.9
|
|
autocomplete(parser)
|
|
parser.parse_args(argv)
|
|
print(f"hello from daedalus {app_version()}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|