diff --git a/.gitignore b/.gitignore index e2fb743..7bb8506 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ __pycache__/ *.egg dist/ build/ +!build/Dockerfile.tools +!build/*.py *.whl # Virtual environments diff --git a/Makefile b/Makefile index d249f53..ce49ba2 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ DOCKER_RUN_ROOT := docker run --rm -v $(CURDIR):/workspace -v $(CURDIR)/../decre PROTO_DIR := /proto GEN_DIR := sdk/src/opendecree/_generated -.PHONY: all generate lint format typecheck test integration build clean tools docs pre-commit help +.PHONY: all generate gen-constants lint format typecheck test integration build clean tools docs pre-commit help all: generate lint typecheck test @@ -19,8 +19,12 @@ $(TOOLS_SENTINEL): build/Dockerfile.tools docker build -t $(TOOLS_IMAGE) -f build/Dockerfile.tools build/ @touch $(TOOLS_SENTINEL) -## generate: Generate Python proto stubs from proto definitions -generate: $(TOOLS_SENTINEL) +## gen-constants: Generate _constants.py from pyproject.toml [tool.opendecree] +gen-constants: + python3 build/gen-constants.py + +## generate: Generate Python proto stubs and package constants +generate: $(TOOLS_SENTINEL) gen-constants $(DOCKER_RUN) sh -c '\ SITE=$$(python -c "import site; print(site.getsitepackages()[0])") && \ GRPC_PROTO=$$(python -c "import grpc_tools; import os; print(os.path.join(os.path.dirname(grpc_tools.__file__), \"_proto\"))") && \ diff --git a/build/gen-constants.py b/build/gen-constants.py new file mode 100644 index 0000000..7884656 --- /dev/null +++ b/build/gen-constants.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +"""Generate sdk/src/opendecree/_constants.py from pyproject.toml [tool.opendecree].""" + +import tomllib +from pathlib import Path + +ROOT = Path(__file__).parent.parent +PYPROJECT = ROOT / "sdk" / "pyproject.toml" +OUT = ROOT / "sdk" / "src" / "opendecree" / "_constants.py" + +with PYPROJECT.open("rb") as f: + config = tomllib.load(f) + +supported = config["tool"]["opendecree"]["supported_server_version"] + +OUT.write_text( + "# Generated by build/gen-constants.py — do not edit manually.\n" + f'SUPPORTED_SERVER_VERSION = "{supported}"\n' +) +print(f"Written {OUT.relative_to(ROOT)}") diff --git a/sdk/pyproject.toml b/sdk/pyproject.toml index 7fd242f..cae4ce4 100644 --- a/sdk/pyproject.toml +++ b/sdk/pyproject.toml @@ -93,3 +93,6 @@ omit = ["src/opendecree/_generated/*"] [tool.coverage.report] fail_under = 95 + +[tool.opendecree] +supported_server_version = ">=0.3.0,<1.0.0" diff --git a/sdk/src/opendecree/__init__.py b/sdk/src/opendecree/__init__.py index 8b4978b..b82cdaa 100644 --- a/sdk/src/opendecree/__init__.py +++ b/sdk/src/opendecree/__init__.py @@ -4,7 +4,8 @@ __version__ = _pkg_version("opendecree") -SUPPORTED_SERVER_VERSION = ">=0.3.0,<1.0.0" +from opendecree._constants import SUPPORTED_SERVER_VERSION + PROTO_VERSION = "v1" from opendecree._convert import URL diff --git a/sdk/src/opendecree/_constants.py b/sdk/src/opendecree/_constants.py new file mode 100644 index 0000000..bdb571c --- /dev/null +++ b/sdk/src/opendecree/_constants.py @@ -0,0 +1,2 @@ +# Generated by build/gen-constants.py — do not edit manually. +SUPPORTED_SERVER_VERSION = ">=0.3.0,<1.0.0"