mirror of
https://github.com/csunny/DB-GPT.git
synced 2026-07-16 17:15:22 +00:00
fix: code format
This commit is contained in:
@@ -18,32 +18,74 @@ from pathlib import Path
|
||||
|
||||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
||||
|
||||
|
||||
# Source paths relative to REPO ROOT -> wheel target paths
|
||||
# ---------------------------------------------------------------------------
|
||||
# Source paths (relative to REPO ROOT) -> wheel target paths
|
||||
# Used in editable mode where we can reach repo root via ../../
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_SKILL_SRC = "skills"
|
||||
_SKILL_DST = "dbgpt_app/_builtin_skills"
|
||||
|
||||
_SKILLS_MAP = {
|
||||
"skills/csv-data-analysis": "dbgpt_app/_builtin_skills/csv-data-analysis",
|
||||
"skills/skill-creator": "dbgpt_app/_builtin_skills/skill-creator",
|
||||
"skills/financial-report-analyzer": "dbgpt_app/_builtin_skills/financial-report-analyzer",
|
||||
"skills/walmart-sales-analyzer": "dbgpt_app/_builtin_skills/walmart-sales-analyzer",
|
||||
"skills/agent-browser": "dbgpt_app/_builtin_skills/agent-browser",
|
||||
f"{_SKILL_SRC}/{name}": f"{_SKILL_DST}/{name}"
|
||||
for name in [
|
||||
"csv-data-analysis",
|
||||
"skill-creator",
|
||||
"financial-report-analyzer",
|
||||
"walmart-sales-analyzer",
|
||||
"agent-browser",
|
||||
]
|
||||
}
|
||||
|
||||
_EXAMPLE_DST = "dbgpt_app/_builtin_examples"
|
||||
|
||||
# fmt: off
|
||||
_EXAMPLES_MAP = {
|
||||
# repo_root_relative_path -> wheel_target
|
||||
"docker/examples/excel/Walmart_Sales.csv": "dbgpt_app/_builtin_examples/excel/Walmart_Sales.csv",
|
||||
"docker/examples/fin_report/pdf/2020-01-23__浙江海翔药业股份有限公司__002099__海翔药业__2019年__年度报告.pdf": "dbgpt_app/_builtin_examples/fin_report/pdf/2020-01-23__浙江海翔药业股份有限公司__002099__海翔药业__2019年__年度报告.pdf",
|
||||
"docker/examples/excel/Walmart_Sales.csv": (
|
||||
f"{_EXAMPLE_DST}/excel/Walmart_Sales.csv"
|
||||
),
|
||||
(
|
||||
"docker/examples/fin_report/pdf/"
|
||||
"2020-01-23__浙江海翔药业股份有限公司__002099__"
|
||||
"海翔药业__2019年__年度报告.pdf"
|
||||
): (
|
||||
f"{_EXAMPLE_DST}/fin_report/pdf/"
|
||||
"2020-01-23__浙江海翔药业股份有限公司__002099__"
|
||||
"海翔药业__2019年__年度报告.pdf"
|
||||
),
|
||||
}
|
||||
# fmt: on
|
||||
|
||||
_TPL = "dbgpt_app/pilot_template"
|
||||
|
||||
# fmt: off
|
||||
_PILOT_TPL_MAP = {
|
||||
# repo_root_relative_path -> wheel_target
|
||||
"pilot/meta_data/alembic.ini": "dbgpt_app/pilot_template/meta_data/alembic.ini",
|
||||
"pilot/meta_data/alembic/README": "dbgpt_app/pilot_template/meta_data/alembic/README",
|
||||
"pilot/meta_data/alembic/env.py": "dbgpt_app/pilot_template/meta_data/alembic/env.py",
|
||||
"pilot/meta_data/alembic/script.py.mako": "dbgpt_app/pilot_template/meta_data/alembic/script.py.mako",
|
||||
"pilot/benchmark_meta_data/2025_07_27_public_500_standard_benchmark_question_list.xlsx": "dbgpt_app/pilot_template/benchmark_meta_data/2025_07_27_public_500_standard_benchmark_question_list.xlsx",
|
||||
"pilot/examples/Walmart_Sales.db": "dbgpt_app/pilot_template/examples/Walmart_Sales.db",
|
||||
"pilot/meta_data/alembic.ini": (
|
||||
f"{_TPL}/meta_data/alembic.ini"
|
||||
),
|
||||
"pilot/meta_data/alembic/README": (
|
||||
f"{_TPL}/meta_data/alembic/README"
|
||||
),
|
||||
"pilot/meta_data/alembic/env.py": (
|
||||
f"{_TPL}/meta_data/alembic/env.py"
|
||||
),
|
||||
"pilot/meta_data/alembic/script.py.mako": (
|
||||
f"{_TPL}/meta_data/alembic/script.py.mako"
|
||||
),
|
||||
(
|
||||
"pilot/benchmark_meta_data/"
|
||||
"2025_07_27_public_500_standard_benchmark"
|
||||
"_question_list.xlsx"
|
||||
): (
|
||||
f"{_TPL}/benchmark_meta_data/"
|
||||
"2025_07_27_public_500_standard_benchmark"
|
||||
"_question_list.xlsx"
|
||||
),
|
||||
"pilot/examples/Walmart_Sales.db": (
|
||||
f"{_TPL}/examples/Walmart_Sales.db"
|
||||
),
|
||||
}
|
||||
# fmt: on
|
||||
|
||||
# sdist force-include remaps these paths:
|
||||
# ../../skills/X -> skills/X
|
||||
@@ -57,35 +99,40 @@ _SDIST_REMAP = {
|
||||
|
||||
|
||||
class CustomBuildHook(BuildHookInterface):
|
||||
"""Dynamically set wheel force-include paths for editable and standard builds."""
|
||||
"""Dynamically set force-include paths for editable and standard builds."""
|
||||
|
||||
def initialize(self, version, build_data):
|
||||
"""Called by hatchling before building.
|
||||
|
||||
Args:
|
||||
version: "editable" for uv sync / pip install -e .
|
||||
"standard" for uv build / pip wheel
|
||||
build_data: mutable dict; set "force_include" key to inject mappings
|
||||
version: "editable" for ``uv sync`` / ``pip install -e .``
|
||||
"standard" for ``uv build`` / ``pip wheel``
|
||||
build_data: mutable dict; set ``force_include`` to inject
|
||||
path mappings
|
||||
"""
|
||||
pkg_root = Path(self.root) # packages/dbgpt-app/
|
||||
all_mappings = {**_SKILLS_MAP, **_EXAMPLES_MAP, **_PILOT_TPL_MAP}
|
||||
force_include = {}
|
||||
all_mappings = {
|
||||
**_SKILLS_MAP,
|
||||
**_EXAMPLES_MAP,
|
||||
**_PILOT_TPL_MAP,
|
||||
}
|
||||
force_include: dict[str, str] = {}
|
||||
|
||||
if version == "editable":
|
||||
# Editable: resolve from repo root (two levels up from packages/dbgpt-app/)
|
||||
# Editable: resolve from repo root (../../ from packages/X/)
|
||||
repo_root = pkg_root.parent.parent
|
||||
for repo_rel_path, wheel_target in all_mappings.items():
|
||||
source = str(repo_root / repo_rel_path)
|
||||
for repo_rel, wheel_target in all_mappings.items():
|
||||
source = str(repo_root / repo_rel)
|
||||
if os.path.exists(source):
|
||||
force_include[source] = wheel_target
|
||||
else:
|
||||
# Standard build from sdist: files were placed at sdist-relative paths
|
||||
# by the sdist force-include config in pyproject.toml
|
||||
for repo_rel_path, wheel_target in all_mappings.items():
|
||||
sdist_path = repo_rel_path
|
||||
# Standard build from sdist: files sit at sdist-relative
|
||||
# paths set by pyproject.toml [tool.hatch.build.targets.sdist]
|
||||
for repo_rel, wheel_target in all_mappings.items():
|
||||
sdist_path = repo_rel
|
||||
for prefix, replacement in _SDIST_REMAP.items():
|
||||
if repo_rel_path.startswith(prefix):
|
||||
sdist_path = replacement + repo_rel_path[len(prefix) :]
|
||||
if repo_rel.startswith(prefix):
|
||||
sdist_path = replacement + repo_rel[len(prefix) :]
|
||||
break
|
||||
source = str(pkg_root / sdist_path)
|
||||
if os.path.exists(source):
|
||||
|
||||
Reference in New Issue
Block a user