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: 1 addition & 1 deletion .github/workflows/release-please.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Build package
shell: bash
run: |
uv build --wheel --package otdf-python
uv build --package otdf-python

- name: Test import
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
- name: Build otdf-python wheel using uv
run: |
uv sync --frozen
uv build --wheel --package otdf-python
uv build --package otdf-python
shell: bash

- name: Check wheel with twine
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.15.16
rev: v0.15.20
hooks:
# Run the linter.
- id: ruff-check
Expand Down
34 changes: 34 additions & 0 deletions packages/otdf-python/hatch_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Hatchling build hook for otdf-python."""

from pathlib import Path

from hatchling.builders.hooks.plugin.interface import BuildHookInterface


class CustomBuildHook(BuildHookInterface):
"""Dynamically resolves proto sources for wheel builds from source tree or sdist."""

def initialize(self, version, build_data):
"""Set force_include for otdf_python_proto based on build context."""
if self.target_name != "wheel":
return

root = Path(self.root)

# When building from source tree, the proto package is a sibling directory.
# When building from an sdist, we embed the protos at _proto/ inside the sdist root.
source_tree_path = (
root / ".." / "otdf-python-proto" / "src" / "otdf_python_proto"
).resolve()
sdist_path = (root / "_proto" / "otdf_python_proto").resolve()

if source_tree_path.is_dir():
proto_src = str(source_tree_path)
elif sdist_path.is_dir():
proto_src = str(sdist_path)
else:
raise FileNotFoundError(
f"otdf_python_proto sources not found at {source_tree_path!r} or {sdist_path!r}"
)

build_data["force_include"][proto_src] = "otdf_python_proto"
11 changes: 9 additions & 2 deletions packages/otdf-python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@ build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["src/otdf_python"]
# force-include for proto sources is handled dynamically by hatch_build.py
# to support both source-tree builds and sdist-based builds

[tool.hatch.build.targets.wheel.force-include]
"../otdf-python-proto/src/otdf_python_proto" = "otdf_python_proto"
[tool.hatch.build.targets.sdist]
packages = ["src/otdf_python"]

[tool.hatch.build.targets.sdist.force-include]
"../otdf-python-proto/src/otdf_python_proto" = "_proto/otdf_python_proto"

[tool.hatch.build.hooks.custom]

[dependency-groups]
dev = [
Expand Down
Loading