Skip to content

Commit 27901cb

Browse files
zeevdrclaude
andcommitted
feat(constants): auto-source SUPPORTED_SERVER_VERSION from pyproject.toml
Move the version constraint to [tool.opendecree] in pyproject.toml as the single source of truth. build/gen-constants.py reads it and writes sdk/src/opendecree/_constants.py; make generate now runs gen-constants first. __init__.py imports SUPPORTED_SERVER_VERSION from _constants.py instead of hardcoding it. Also fix the build/ .gitignore rule — it was too broad, silently requiring force-add for Dockerfile.tools. Negation patterns now let tracked scripts (*.py, Dockerfile.tools) be added normally. Closes #64 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent caf0aa6 commit 27901cb

6 files changed

Lines changed: 36 additions & 4 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ __pycache__/
66
*.egg
77
dist/
88
build/
9+
!build/Dockerfile.tools
10+
!build/*.py
911
*.whl
1012

1113
# Virtual environments

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ DOCKER_RUN_ROOT := docker run --rm -v $(CURDIR):/workspace -v $(CURDIR)/../decre
66
PROTO_DIR := /proto
77
GEN_DIR := sdk/src/opendecree/_generated
88

9-
.PHONY: all generate lint format typecheck test integration build clean tools docs pre-commit help
9+
.PHONY: all generate gen-constants lint format typecheck test integration build clean tools docs pre-commit help
1010

1111
all: generate lint typecheck test
1212

@@ -19,8 +19,12 @@ $(TOOLS_SENTINEL): build/Dockerfile.tools
1919
docker build -t $(TOOLS_IMAGE) -f build/Dockerfile.tools build/
2020
@touch $(TOOLS_SENTINEL)
2121

22-
## generate: Generate Python proto stubs from proto definitions
23-
generate: $(TOOLS_SENTINEL)
22+
## gen-constants: Generate _constants.py from pyproject.toml [tool.opendecree]
23+
gen-constants:
24+
python3 build/gen-constants.py
25+
26+
## generate: Generate Python proto stubs and package constants
27+
generate: $(TOOLS_SENTINEL) gen-constants
2428
$(DOCKER_RUN) sh -c '\
2529
SITE=$$(python -c "import site; print(site.getsitepackages()[0])") && \
2630
GRPC_PROTO=$$(python -c "import grpc_tools; import os; print(os.path.join(os.path.dirname(grpc_tools.__file__), \"_proto\"))") && \

build/gen-constants.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
"""Generate sdk/src/opendecree/_constants.py from pyproject.toml [tool.opendecree]."""
3+
4+
import tomllib
5+
from pathlib import Path
6+
7+
ROOT = Path(__file__).parent.parent
8+
PYPROJECT = ROOT / "sdk" / "pyproject.toml"
9+
OUT = ROOT / "sdk" / "src" / "opendecree" / "_constants.py"
10+
11+
with PYPROJECT.open("rb") as f:
12+
config = tomllib.load(f)
13+
14+
supported = config["tool"]["opendecree"]["supported_server_version"]
15+
16+
OUT.write_text(
17+
"# Generated by build/gen-constants.py — do not edit manually.\n"
18+
f'SUPPORTED_SERVER_VERSION = "{supported}"\n'
19+
)
20+
print(f"Written {OUT.relative_to(ROOT)}")

sdk/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,6 @@ omit = ["src/opendecree/_generated/*"]
9393

9494
[tool.coverage.report]
9595
fail_under = 95
96+
97+
[tool.opendecree]
98+
supported_server_version = ">=0.3.0,<1.0.0"

sdk/src/opendecree/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
__version__ = _pkg_version("opendecree")
66

7-
SUPPORTED_SERVER_VERSION = ">=0.3.0,<1.0.0"
7+
from opendecree._constants import SUPPORTED_SERVER_VERSION
8+
89
PROTO_VERSION = "v1"
910

1011
from opendecree._convert import URL

sdk/src/opendecree/_constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Generated by build/gen-constants.py — do not edit manually.
2+
SUPPORTED_SERVER_VERSION = ">=0.3.0,<1.0.0"

0 commit comments

Comments
 (0)