mirror of
https://github.com/katanemo/plano.git
synced 2026-04-25 00:36:34 +02:00
fix sdist build: use build hook to bundle config files (#803)
* fix sdist build: use build hook to bundle config files * copy hatch_build.py in Dockerfile
This commit is contained in:
parent
c13ce19293
commit
8f7a8a8a17
4 changed files with 54 additions and 5 deletions
|
|
@ -69,6 +69,7 @@ RUN pip install --no-cache-dir uv
|
||||||
COPY cli/pyproject.toml ./
|
COPY cli/pyproject.toml ./
|
||||||
COPY cli/uv.lock ./
|
COPY cli/uv.lock ./
|
||||||
COPY cli/README.md ./
|
COPY cli/README.md ./
|
||||||
|
COPY cli/hatch_build.py ./
|
||||||
COPY config/plano_config_schema.yaml /config/plano_config_schema.yaml
|
COPY config/plano_config_schema.yaml /config/plano_config_schema.yaml
|
||||||
COPY config/envoy.template.yaml /config/envoy.template.yaml
|
COPY config/envoy.template.yaml /config/envoy.template.yaml
|
||||||
|
|
||||||
|
|
|
||||||
1
cli/.gitignore
vendored
Normal file
1
cli/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
planoai/data/
|
||||||
44
cli/hatch_build.py
Normal file
44
cli/hatch_build.py
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
"""Hatch build hook to bundle config files from the repo into the package.
|
||||||
|
|
||||||
|
Single source of truth stays in ../config/. This hook copies them into
|
||||||
|
planoai/data/ so they end up inside both the sdist and wheel.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
||||||
|
|
||||||
|
FILES = {
|
||||||
|
"plano_config_schema.yaml": "plano_config_schema.yaml",
|
||||||
|
"envoy.template.yaml": "envoy.template.yaml",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class CustomBuildHook(BuildHookInterface):
|
||||||
|
def initialize(self, version, build_data):
|
||||||
|
root = os.path.dirname(__file__)
|
||||||
|
# Repo checkout: ../config/ | sdist: config/
|
||||||
|
candidates = [
|
||||||
|
os.path.join(root, "..", "config"),
|
||||||
|
os.path.join(root, "config"),
|
||||||
|
]
|
||||||
|
dest_dir = os.path.join(root, "planoai", "data")
|
||||||
|
os.makedirs(dest_dir, exist_ok=True)
|
||||||
|
|
||||||
|
for src_name, dest_name in FILES.items():
|
||||||
|
dest = os.path.join(dest_dir, dest_name)
|
||||||
|
copied = False
|
||||||
|
for cand in candidates:
|
||||||
|
src = os.path.join(cand, src_name)
|
||||||
|
if os.path.exists(src):
|
||||||
|
shutil.copy2(src, dest)
|
||||||
|
copied = True
|
||||||
|
break
|
||||||
|
if not copied and not os.path.exists(dest):
|
||||||
|
raise FileNotFoundError(
|
||||||
|
f"Config file {src_name} not found. "
|
||||||
|
"Build from the repo root or ensure files are present."
|
||||||
|
)
|
||||||
|
|
||||||
|
build_data["force_include"][dest_dir] = "planoai/data"
|
||||||
|
|
@ -37,12 +37,15 @@ path = "planoai/__init__.py"
|
||||||
[tool.hatch.build.targets.wheel]
|
[tool.hatch.build.targets.wheel]
|
||||||
packages = ["planoai"]
|
packages = ["planoai"]
|
||||||
|
|
||||||
[tool.hatch.build.targets.wheel.force-include]
|
|
||||||
"../config/plano_config_schema.yaml" = "planoai/data/plano_config_schema.yaml"
|
|
||||||
"../config/envoy.template.yaml" = "planoai/data/envoy.template.yaml"
|
|
||||||
|
|
||||||
[tool.hatch.build.targets.sdist]
|
[tool.hatch.build.targets.sdist]
|
||||||
include = ["planoai/**"]
|
include = ["planoai/**", "hatch_build.py"]
|
||||||
|
|
||||||
|
[tool.hatch.build.targets.sdist.force-include]
|
||||||
|
"../config/plano_config_schema.yaml" = "config/plano_config_schema.yaml"
|
||||||
|
"../config/envoy.template.yaml" = "config/envoy.template.yaml"
|
||||||
|
|
||||||
|
[tool.hatch.build]
|
||||||
|
hooks.custom.path = "hatch_build.py"
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
addopts = ["-v"]
|
addopts = ["-v"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue