-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
65 lines (49 loc) · 1.97 KB
/
Copy pathsetup.py
File metadata and controls
65 lines (49 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""setup.py — 与 pyproject.toml 配合工作,唯一目的是在 build_py 阶段
把仓库根的规则源文件(core/ personas/ capabilities/ personas/ adapters/
mcp.example.json)拷贝到 agentseed/_resources/,让它们随 wheel 分发。
这样 `pip install agentseed` 后无需外部仓库即可运行(_packaged_resources_root() 检测包内资源)。
dev 模式(pip install -e .)不触发 build_py 的拷贝,
此时 _resources/ 不存在,sync_rules 自动回退到 dev 模式(用 parent.parent = REPO_ROOT 读源)。
"""
import shutil
from pathlib import Path
from setuptools import setup
from setuptools.command.build_py import build_py
from setuptools.command.sdist import sdist
ROOT = Path(__file__).resolve().parent
PKG_RESOURCES = ROOT / "src" / "agentseed" / "_resources"
# 必须随包分发的源文件/目录(相对仓库根)
PACKAGED_SOURCES = [
"core",
"personas",
"capabilities",
"adapters",
"mcp.example.json",
]
def _sync_resources() -> None:
"""把规则源同步到 agentseed/_resources/。
幂等:每次构建前清空 _resources/ 重建,避免旧文件残留。
"""
if PKG_RESOURCES.exists():
shutil.rmtree(PKG_RESOURCES)
PKG_RESOURCES.mkdir(parents=True, exist_ok=True)
for src in PACKAGED_SOURCES:
src_path = ROOT / src
dst_path = PKG_RESOURCES / src
if not src_path.exists():
continue
if src_path.is_dir():
shutil.copytree(src_path, dst_path)
else:
shutil.copy2(src_path, dst_path)
class BuildPyCommand(build_py):
"""build_py 子类:构建前同步规则源到包内。"""
def run(self):
_sync_resources()
super().run()
class SdistCommand(sdist):
"""sdist 子类:打包源分发前同步规则源到包内(让 sdist 也能直接 pip install)。"""
def run(self):
_sync_resources()
super().run()
setup(cmdclass={"build_py": BuildPyCommand, "sdist": SdistCommand})