Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ __pycache__/
*.egg
dist/
build/
!build/Dockerfile.tools
!build/*.py
*.whl

# Virtual environments
Expand Down
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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\"))") && \
Expand Down
20 changes: 20 additions & 0 deletions build/gen-constants.py
Original file line number Diff line number Diff line change
@@ -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)}")
3 changes: 3 additions & 0 deletions sdk/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 2 additions & 1 deletion sdk/src/opendecree/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/opendecree/_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by build/gen-constants.py — do not edit manually.
SUPPORTED_SERVER_VERSION = ">=0.3.0,<1.0.0"