diff --git a/inject_runtime_pyproject.py b/inject_runtime_pyproject.py index 11ee34f1..b36f34db 100644 --- a/inject_runtime_pyproject.py +++ b/inject_runtime_pyproject.py @@ -10,14 +10,40 @@ RUNTIME_PYPROJECT_PATH = "tesseract_core/runtime/meta/pyproject.toml" +BASE_OPTIONAL_DEPS = { + "dev": [ + "fastapi", + "httpx", # required by fastapi test client + "jsf", + "requests", + "numpy", + "pre-commit", + "pytest", + "pytest-cov", + "pytest-mock", + "moto[server]", + "aiobotocore>=2.19.0", # without this pip dependency resolution fails + "typeguard", + "detect-secrets[gibberish]", + # also add all other extras here + "tesseract-core[runtime]", + ], + "runtime": [], +} + +BASE_SCRIPTS = { + "tesseract": "tesseract_core.sdk.cli:entrypoint", +} + class RuntimeDepenencyHook(MetadataHookInterface): PLUGIN_NAME = "runtime-deps" def update(self, metadata): runtime_metadata = toml.load(Path(self.root) / RUNTIME_PYPROJECT_PATH) - metadata["optional-dependencies"]["runtime"] = runtime_metadata["project"][ - "dependencies" - ] - metadata["scripts"].update(runtime_metadata["project"]["scripts"]) + metadata["optional-dependencies"] = { + **BASE_OPTIONAL_DEPS, + "runtime": runtime_metadata["project"]["dependencies"], + } + metadata["scripts"] = {**BASE_SCRIPTS, **runtime_metadata["project"]["scripts"]} return metadata diff --git a/pyproject.toml b/pyproject.toml index 33e3c7ee..f0086058 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,38 +17,18 @@ dependencies = [ "numpy", "requests", ] -dynamic = ["version"] - -[project.optional-dependencies] -# Populated by our custom hook based on dependencies in `tesseract_core/runtime/meta/pyproject.toml` -# Changes to this list will be ignored -runtime = [] - -dev = [ - "fastapi", - "httpx", # required by fastapi test client - "jsf", - "requests", - "numpy", - "pre-commit", - "pytest", - "pytest-cov", - "pytest-mock", - "moto[server]", - "aiobotocore>=2.19.0", # without this pip dependency resolution fails - "typeguard", - "detect-secrets[gibberish]", - # also add all other extras here - "tesseract-core[runtime]", +dynamic = [ + # Injected via hatch-vcs + "version", + # Injected via inject_runtime_pyproject.py + "optional-dependencies", + "scripts", ] [project.urls] Homepage = "https://github.com/pasteurlabs/tesseract-core" Documentation = "https://pasteur-labs-tesseract-core.readthedocs-hosted.com/en/latest/" -[project.scripts] -tesseract = "tesseract_core.sdk.cli:entrypoint" - [build-system] requires = ["hatchling", "hatch-vcs", "toml"] build-backend = "hatchling.build" diff --git a/tesseract_core/sdk/cli.py b/tesseract_core/sdk/cli.py index 04d657bd..961d68d8 100755 --- a/tesseract_core/sdk/cli.py +++ b/tesseract_core/sdk/cli.py @@ -134,7 +134,7 @@ def _validate_tesseract_name(name: str | None) -> str: def version_callback(value: bool | None) -> None: """Typer callback for version option.""" if value: - from . import __version__ + from tesseract_core import __version__ typer.echo(__version__) raise typer.Exit() diff --git a/tests/sdk_tests/test_cli.py b/tests/sdk_tests/test_cli.py index 7a5af60c..a82cf94f 100644 --- a/tests/sdk_tests/test_cli.py +++ b/tests/sdk_tests/test_cli.py @@ -27,3 +27,11 @@ def test_suggestion_on_misspelled_command(cli_runner): assert result.exit_code == 2, result.stdout assert "No such command 'wellbloodygreatinnit'." in result.stderr assert "Did you mean" not in result.stderr + + +def test_version(cli_runner): + from tesseract_core import __version__ + + result = cli_runner.invoke(cli, ["--version"]) + assert result.exit_code == 0, result.stdout + assert __version__ in result.stdout