本地工具路径DTU_*环境变量改造落地:10处调用点去硬编码+变量优先解析,本机全链路验证通过,文档同步收口,requirements补pre-commit
This commit is contained in:
@@ -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)
|
||||
|
||||
# 渲染
|
||||
|
||||
Reference in New Issue
Block a user