Repository navigation
Expand file tree
/
Copy pathconcat_src.py
More file actions
59 lines (52 loc) · 2.29 KB
/
Copy pathconcat_src.py
File metadata and controls
59 lines (52 loc) · 2.29 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
#!/usr/bin/env python3
"""Concatenate all comfycli/*.static.py in dependency order for single-file translation."""
import os
import re
BASE = os.path.join(os.path.dirname(__file__), "comfycli")
# 仅保留 sd.cpp 后端实际使用的模块(torch 时代的模型栈已废弃)。
# 顺序 = 依赖顺序(被依赖者在前)。
FILES = [
"cli_args.static.py",
"sd_backend.static.py",
"torch_helper.static.py",
"nodes.static.py",
"execution.static.py",
"main.static.py",
]
# 上游 prelude 无 dict_keys,由 comfycli_ffi.scm 提供 Scheme 实现;
# 这里用一条 import 让类型检查器认识该名字(import 本身不生成代码)。
HEADER = ("from comfycli_builtins import dict_keys, is_link, path_dirname, path_split\n"
"from comfycli_builtins import is_string, to_int, to_float, to_str\n"
"from comfycli_builtins import florence2_caption\n"
"from comfycli_builtins import birefnet_remove\n"
"from comfycli_builtins import ocr_image, ocr_image_json\n"
"from comfycli_builtins import torch_std_safetensors_load, torch_std_safetensors_count, "
"torch_std_safetensors_save, torch_std_safetensors_merge, torch_std_safetensors_free, "
"torch_std_copy_file\n\n")
KEEP_MAIN = {"main.static.py"}
def strip_main_py(content):
"""Remove 'def main():\\n pass' stub."""
return re.sub(r'\n\s*def main\(\):\s*\n\s+pass\s*', '', content)
def concat():
lines = []
for fname in FILES:
path = os.path.join(BASE, fname)
if not os.path.exists(path):
print(f"WARNING: {path} not found, skipping")
continue
with open(path) as f:
content = f.read()
if fname not in KEEP_MAIN:
content = strip_main_py(content)
# Strip from ... import ... (not needed in bundle; all defs inline)
cleaned = re.sub(r'(?m)^\s*(from\s+\S.*import\s+\S[\s\S]*?)(?=\n\S|\Z)', '', content)
lines.append(f"# === {fname} ===\n")
lines.append(cleaned)
lines.append("\n")
return HEADER + "".join(lines)
if __name__ == "__main__":
output = concat()
out_path = os.path.join(BASE, "_bundle.static.py")
with open(out_path, "w") as f:
f.write(output)
print(f"Written {out_path} ({len(output.splitlines())} lines)")