Files

43 lines
1.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""发布打包辅助(开发工具,`_` 前缀运行时不会被插件扫描加载)。
把本插件压成 dist-plugin/xq0045_xq0046_v<版本>.zip,
包根布局:plugin.json / 各 .py / requirements.txt 直接位于 zip 根。
排除项:__pycache__、debug、.sessions、本脚本、*.pyc。
用法(仓库根下执行):
.venv\\Scripts\\python.exe "plugins\\XQ0001-0100\\XQ0045_XQ0046 金色印象通联数据导出\\_pack.py"
随后发布(desktop/ 下执行,见 docs/插件/发版规范.md):
.venv\\Scripts\\python.exe tools\\agent_cli.py publish \\
dist-plugin/xq0045_xq0046_v1.0.0.zip --id xq0045_xq0046 --version 1.0.0
"""
import json
import sys
import zipfile
from pathlib import Path
_HERE = Path(__file__).resolve().parent
# 仓库根 = plugins/XQ0001-0100/<插件目录>/ 的 parents[2],统一出包位置
_OUT_DIR = _HERE.parents[2] / "dist-plugin"
_EXCLUDE_DIRS = {"ui-src", "__pycache__", "debug", ".sessions"}
_EXCLUDE_FILES = {"_pack.py"}
def main():
manifest = json.loads((_HERE / "plugin.json").read_text(encoding="utf-8"))
pid, ver = manifest["id"], manifest["version"]
_OUT_DIR.mkdir(exist_ok=True)
out = _OUT_DIR / f"{pid}_v{ver}.zip"
with zipfile.ZipFile(out, "w", zipfile.ZIP_DEFLATED) as zf:
for p in sorted(_HERE.rglob("*")):
rel = p.relative_to(_HERE)
if set(rel.parts) & _EXCLUDE_DIRS or p.name in _EXCLUDE_FILES or p.suffix == ".pyc":
continue
if p.is_file():
zf.write(p, str(rel))
print(f"已打包: {out}({out.stat().st_size / 1024:.0f} KB)")
if __name__ == "__main__":
main()