本地工具路径DTU_*环境变量改造落地:10处调用点去硬编码+变量优先解析,本机全链路验证通过,文档同步收口,requirements补pre-commit

This commit is contained in:
2026-10-02 22:14:49 +08:00
parent b96d649e62
commit 33a4aa4945
30 changed files with 4074 additions and 2917 deletions
+5 -3
View File
@@ -52,8 +52,10 @@ def resolve_font(path):
if not os.path.exists(path):
sys.exit('ERROR: --font 指定的文件不存在: ' + path)
return path
# 默认字体:Windows 宋体集合 simsun.ttc(lv_font_conv 不支持 .ttc,需先抽取 face0)
ttc = r'C:\Windows\Fonts\simsun.ttc'
# 默认字体:Windows 宋体集合 simsun.ttc,由 WINDIR 环境变量的系统字体目录推导
# (兼容非 C 盘系统盘);lv_font_conv 不支持 .ttc,需先抽取 face0
windir = os.environ.get('WINDIR') or r'C:\Windows'
ttc = os.path.join(windir, 'Fonts', 'simsun.ttc')
if os.path.exists(ttc):
try:
from fontTools.ttLib import TTCollection
@@ -64,7 +66,7 @@ def resolve_font(path):
return tmp
except Exception as e:
sys.exit('ERROR: 抽取 simsun.ttc 失败,请 pip install fonttools,或用 --font 指定 ttf: ' + str(e))
sys.exit('ERROR: 未找到 C:\\Windows\\Fonts\\simsun.ttc,请用 --font 指定字体 ttf/otf 路径')
sys.exit('ERROR: 未找到 %s,请用 --font 指定字体 ttf/otf 路径' % ttc)
# ---------------------------------------------------------------------------
+15 -9
View File
@@ -446,14 +446,18 @@ class Graph:
# ---------------------------------------------------------------------------
def find_dot() -> str | None:
p = shutil.which("dot")
if p:
return p
for c in (r"C:\Program Files\Graphviz\bin\dot.exe",
r"C:\Program Files (x86)\Graphviz\bin\dot.exe"):
if os.path.isfile(c):
return c
return None
"""定位 Graphviz dot:DTU_GRAPHVIZ_DOT(显式)→ PATH。
显式变量已设置则严格使用(无效立即报错,不静默回退);未设置时只查
PATH,未找到返回 None 并降级为"只生成 .dot、不渲染"(保持既有语义)。
见 docs/环境与部署/本地工具路径环境变量方案.md §3。
"""
explicit = os.environ.get("DTU_GRAPHVIZ_DOT", "").strip()
if explicit:
if not os.path.isfile(explicit):
sys.exit("ERROR: DTU_GRAPHVIZ_DOT 已设置但不存在: {}(清除该变量可改用 PATH 查找)".format(explicit))
return explicit
return shutil.which("dot")
def render(dot: str, dotfile: str, outfiles: dict[str, str]) -> bool:
@@ -579,7 +583,8 @@ def main() -> int:
f.write(dm)
written.append(pm)
# JSON 数据
# JSON 数据(末尾补单个换行:与 pre-commit end-of-file-fixer 口径一致,
# 避免每次重生成都触发该钩子的"首次修复"抖动,模式同 make_font.py)
pj = os.path.join(outdir, "引用关系图.json")
payload = {
"title": title,
@@ -592,6 +597,7 @@ def main() -> int:
}
with open(pj, "w", encoding="utf-8", newline="\n") as f:
json.dump(payload, f, ensure_ascii=False, indent=1)
f.write("\n")
written.append(pj)
# 渲染