AutoCython-zhang 2.3.0__tar.gz → 2.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/AutoCython/_version.py +1 -1
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/AutoCython/compile.py +3 -3
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/AutoCython/obfuscate.py +38 -9
- autocython_zhang-2.3.1/AutoCython_zhang.egg-info/PKG-INFO +280 -0
- autocython_zhang-2.3.1/PKG-INFO +280 -0
- autocython_zhang-2.3.1/README.md +260 -0
- autocython_zhang-2.3.0/AutoCython_zhang.egg-info/PKG-INFO +0 -120
- autocython_zhang-2.3.0/PKG-INFO +0 -120
- autocython_zhang-2.3.0/README.md +0 -100
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/AutoCython/AutoCython.py +0 -0
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/AutoCython/__init__.py +0 -0
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/AutoCython/run_tasks.py +0 -0
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/AutoCython/tools.py +0 -0
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/AutoCython_zhang.egg-info/SOURCES.txt +0 -0
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/AutoCython_zhang.egg-info/dependency_links.txt +0 -0
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/AutoCython_zhang.egg-info/entry_points.txt +0 -0
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/AutoCython_zhang.egg-info/requires.txt +0 -0
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/AutoCython_zhang.egg-info/top_level.txt +0 -0
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/LICENSE +0 -0
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/MANIFEST.in +0 -0
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/pyproject.toml +0 -0
- {autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/setup.cfg +0 -0
|
@@ -67,7 +67,7 @@ def compile_to_binary(file_path: str, del_source=False, obfuscate=True, obfuscat
|
|
|
67
67
|
temp_file_path = os.path.join(temp_dir, safe_file_name)
|
|
68
68
|
shutil.copy2(abs_file_path, temp_file_path)
|
|
69
69
|
|
|
70
|
-
#
|
|
70
|
+
# 混淆源码(失败则显式抛错,避免静默降级)
|
|
71
71
|
if obfuscate:
|
|
72
72
|
try:
|
|
73
73
|
with open(temp_file_path, 'r', encoding='utf-8') as f:
|
|
@@ -75,8 +75,8 @@ def compile_to_binary(file_path: str, del_source=False, obfuscate=True, obfuscat
|
|
|
75
75
|
obfuscated = obfuscate_source(original_source, seed=obfuscate_seed)
|
|
76
76
|
with open(temp_file_path, 'w', encoding='utf-8') as f:
|
|
77
77
|
f.write(obfuscated)
|
|
78
|
-
except Exception:
|
|
79
|
-
|
|
78
|
+
except Exception as exc:
|
|
79
|
+
raise RuntimeError(f"Obfuscation failed for {file_path}: {exc}") from exc
|
|
80
80
|
|
|
81
81
|
# 创建临时的 setup.py 文件
|
|
82
82
|
setup_code = f"""
|
|
@@ -5,11 +5,16 @@ import hashlib
|
|
|
5
5
|
import random
|
|
6
6
|
|
|
7
7
|
_UNSAFE_CALLS = frozenset({'globals', 'locals', 'eval', 'exec', 'vars'})
|
|
8
|
+
_PATTERN_SKIP_ATTR = '_autocython_skip_literal_obf'
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
def _has_unsafe_call(node):
|
|
11
12
|
"""检查函数体是否包含 globals()/locals()/eval()/exec()/vars() 调用"""
|
|
12
|
-
|
|
13
|
+
if hasattr(node, 'body') and isinstance(node.body, list):
|
|
14
|
+
nodes = _walk_no_nested_scope(node.body)
|
|
15
|
+
else:
|
|
16
|
+
nodes = ast.walk(node)
|
|
17
|
+
for child in nodes:
|
|
13
18
|
if isinstance(child, ast.Call) and isinstance(child.func, ast.Name) and child.func.id in _UNSAFE_CALLS:
|
|
14
19
|
return True
|
|
15
20
|
return False
|
|
@@ -27,12 +32,28 @@ def _walk_no_nested_scope(body):
|
|
|
27
32
|
yield from _walk_no_nested_scope([child])
|
|
28
33
|
|
|
29
34
|
|
|
35
|
+
def _is_docstring_stmt(stmt):
|
|
36
|
+
"""判断语句是否为合法 docstring(仅字符串字面量)"""
|
|
37
|
+
if not isinstance(stmt, ast.Expr):
|
|
38
|
+
return False
|
|
39
|
+
value = stmt.value
|
|
40
|
+
if isinstance(value, ast.Constant):
|
|
41
|
+
return isinstance(value.value, str)
|
|
42
|
+
return isinstance(value, ast.Str)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _mark_pattern_constants(pattern):
|
|
46
|
+
"""标记 match/case pattern 内常量,避免被替换为表达式导致语法失效"""
|
|
47
|
+
for child in ast.walk(pattern):
|
|
48
|
+
if isinstance(child, ast.Constant):
|
|
49
|
+
setattr(child, _PATTERN_SKIP_ATTR, True)
|
|
50
|
+
|
|
51
|
+
|
|
30
52
|
class _DocstringRemover(ast.NodeTransformer):
|
|
31
53
|
"""移除 module/class/function 首部的 docstring"""
|
|
32
54
|
|
|
33
55
|
def _strip_docstring(self, node):
|
|
34
|
-
if
|
|
35
|
-
and isinstance(node.body[0].value, (ast.Constant, ast.Str))):
|
|
56
|
+
if node.body and _is_docstring_stmt(node.body[0]):
|
|
36
57
|
node.body.pop(0)
|
|
37
58
|
if not node.body:
|
|
38
59
|
node.body.append(ast.Pass())
|
|
@@ -210,8 +231,14 @@ class _StringEncryptor(ast.NodeTransformer):
|
|
|
210
231
|
def visit_JoinedStr(self, node):
|
|
211
232
|
return node # 不处理 f-string
|
|
212
233
|
|
|
234
|
+
def visit_match_case(self, node):
|
|
235
|
+
_mark_pattern_constants(node.pattern)
|
|
236
|
+
return self.generic_visit(node)
|
|
237
|
+
|
|
213
238
|
def visit_Constant(self, node):
|
|
214
239
|
v = node.value
|
|
240
|
+
if getattr(node, _PATTERN_SKIP_ATTR, False):
|
|
241
|
+
return node
|
|
215
242
|
if not isinstance(v, str) or len(v) <= 1:
|
|
216
243
|
return node
|
|
217
244
|
key = self._key
|
|
@@ -256,8 +283,14 @@ class _ConstantFoldingObfuscator(ast.NodeTransformer):
|
|
|
256
283
|
def __init__(self, rng=None):
|
|
257
284
|
self._rng = rng or random
|
|
258
285
|
|
|
286
|
+
def visit_match_case(self, node):
|
|
287
|
+
_mark_pattern_constants(node.pattern)
|
|
288
|
+
return self.generic_visit(node)
|
|
289
|
+
|
|
259
290
|
def visit_Constant(self, node):
|
|
260
291
|
v = node.value
|
|
292
|
+
if getattr(node, _PATTERN_SKIP_ATTR, False):
|
|
293
|
+
return node
|
|
261
294
|
if isinstance(v, bool) or not isinstance(v, int):
|
|
262
295
|
return node
|
|
263
296
|
if v in (0, 1) or v < 0 or v > 10000:
|
|
@@ -315,18 +348,14 @@ class _ControlFlowFlattener(ast.NodeTransformer):
|
|
|
315
348
|
return True
|
|
316
349
|
if len(node.body) < 3:
|
|
317
350
|
return True
|
|
318
|
-
for child in
|
|
351
|
+
for child in _walk_no_nested_scope(node.body):
|
|
319
352
|
if isinstance(child, (ast.Yield, ast.YieldFrom)):
|
|
320
353
|
return True
|
|
321
354
|
# nonlocal/global 变量在状态机分支中会被 Cython 误判为未赋值
|
|
322
355
|
if isinstance(child, (ast.Nonlocal, ast.Global)):
|
|
323
356
|
return True
|
|
324
357
|
# comprehension 在 while True 状态机内会触发 Cython ControlFlowAnalysis crash
|
|
325
|
-
for child in
|
|
326
|
-
if child is node:
|
|
327
|
-
continue
|
|
328
|
-
if isinstance(child, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
|
|
329
|
-
continue
|
|
358
|
+
for child in _walk_no_nested_scope(node.body):
|
|
330
359
|
if isinstance(child, (ast.ListComp, ast.SetComp, ast.DictComp, ast.GeneratorExp)):
|
|
331
360
|
return True
|
|
332
361
|
return False
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: AutoCython-zhang
|
|
3
|
+
Version: 2.3.1
|
|
4
|
+
Summary: 自动Cython,使用Cython批量编译.py文件为.pyd文件!
|
|
5
|
+
Author-email: zhang_gavin <qq814608@163.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: homepage, https://github.com/zhang0281/AutoCython
|
|
8
|
+
Project-URL: repository, https://github.com/zhang0281/AutoCython
|
|
9
|
+
Project-URL: documentation, https://github.com/zhang0281/AutoCython#readme
|
|
10
|
+
Keywords: cython,compile,pyd,pyc,python,autopyd
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: setuptools
|
|
17
|
+
Requires-Dist: cython
|
|
18
|
+
Requires-Dist: rich
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# AutoCython V2
|
|
22
|
+
|
|
23
|
+
**自动 Cython:一键将 Python 文件批量编译为 `PYD / SO` 二进制文件,内置 AST 七重混淆引擎**
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## ✨ 特性
|
|
27
|
+
|
|
28
|
+
- 单文件 / 目录批量编译
|
|
29
|
+
- 跨平台支持(Windows / Linux / macOS)
|
|
30
|
+
- AST 七重混淆引擎(可复现)
|
|
31
|
+
- Rich 实时进度 UI,中英文自动切换
|
|
32
|
+
- 编译后可选删除源码
|
|
33
|
+
- 自动 strip 符号表(Linux / macOS)
|
|
34
|
+
|
|
35
|
+
## 📦 安装
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install -U AutoCython-zhang
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
要求 Python ≥ 3.9。
|
|
42
|
+
|
|
43
|
+
## ⚙️ 依赖环境
|
|
44
|
+
|
|
45
|
+
### C/C++ 编译器
|
|
46
|
+
|
|
47
|
+
| 平台 | 编译器 |
|
|
48
|
+
|------|--------|
|
|
49
|
+
| Windows | Visual Studio(MSVC) |
|
|
50
|
+
| Linux | gcc & g++ |
|
|
51
|
+
| macOS | clang(Xcode Command Line Tools) |
|
|
52
|
+
|
|
53
|
+
**重要提示**:编译器架构必须与 Python 解释器一致(64 位 Python 需 64 位编译器)
|
|
54
|
+
|
|
55
|
+
> 其他编译器配置请参考 [Cython](https://github.com/cython/cython) 项目
|
|
56
|
+
|
|
57
|
+
## 🚀 使用指南
|
|
58
|
+
|
|
59
|
+
### 命令行参数
|
|
60
|
+
|
|
61
|
+
| 参数 | 说明 | 默认值 |
|
|
62
|
+
|------|------|--------|
|
|
63
|
+
| `-f, --file` | 编译单个文件 | — |
|
|
64
|
+
| `-p, --path` | 编译目录下所有 `.py` 文件 | — |
|
|
65
|
+
| `-c, --conc` | 并发编译线程数 | 2 |
|
|
66
|
+
| `-d, --del` | 编译后删除源代码 | False |
|
|
67
|
+
| `--seed` | 混淆随机种子(可复现构建) | None |
|
|
68
|
+
| `-v, --version` | 显示版本号 | — |
|
|
69
|
+
| `-h, --help` | 显示帮助信息 | — |
|
|
70
|
+
|
|
71
|
+
> `-f` 和 `-p` 互斥,不可同时使用。
|
|
72
|
+
|
|
73
|
+
### 命令行示例
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# 编译单个文件
|
|
77
|
+
AutoCython -f test.py
|
|
78
|
+
|
|
79
|
+
# 编译整个目录
|
|
80
|
+
AutoCython -p /path/to/project
|
|
81
|
+
|
|
82
|
+
# 编译后删除源代码
|
|
83
|
+
AutoCython -d -f test.py
|
|
84
|
+
AutoCython -d -p /path/to/project
|
|
85
|
+
|
|
86
|
+
# 4 线程并发编译
|
|
87
|
+
AutoCython -c 4 -p /path/to/project
|
|
88
|
+
|
|
89
|
+
# 指定混淆随机种子(可复现构建)
|
|
90
|
+
AutoCython --seed 2025 -f test.py
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 手动排除文件不编译
|
|
94
|
+
|
|
95
|
+
在文件 **前两行任意一行** 包含以下标记即可跳过编译:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
# AutoCython No Compile
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
> 兼容旧版拼写 `# AucoCython No Compile`
|
|
102
|
+
|
|
103
|
+
### 自动排除规则
|
|
104
|
+
|
|
105
|
+
以下文件和目录会被自动跳过:
|
|
106
|
+
|
|
107
|
+
- `__init__.py` 文件
|
|
108
|
+
- `__pycache__`、`venv`、`.venv`、`build`、`dist`、`node_modules`、`.git`、`.eggs` 目录
|
|
109
|
+
- `*.egg-info` 目录
|
|
110
|
+
|
|
111
|
+
## 🔐 AST 混淆引擎
|
|
112
|
+
|
|
113
|
+
编译前自动执行七重 AST 变换(按执行顺序),大幅提升逆向难度:
|
|
114
|
+
|
|
115
|
+
| 序号 | 变换 | 说明 | 安全跳过条件 |
|
|
116
|
+
|------|------|------|-------------|
|
|
117
|
+
| 1 | Docstring 移除 | 清除 module / class / function 的文档字符串 | 无 |
|
|
118
|
+
| 2 | Annotation 移除 | 清除函数参数、返回值、变量的类型注解 | 无 |
|
|
119
|
+
| 3 | 局部变量重命名 | 基于 hash 的标识符替换,保护闭包变量 | 含 `globals()`/`locals()`/`eval()`/`exec()`/`vars()` 调用 |
|
|
120
|
+
| 4 | 控制流平坦化 | 函数体转换为 `while True` + 状态机调度 | async 函数、yield/yield from、nonlocal/global 声明、comprehension、函数体 < 3 条语句、含不安全调用 |
|
|
121
|
+
| 5 | 虚假分支插入 | 30% 概率插入永真/永假不透明谓词 | 含不安全调用 |
|
|
122
|
+
| 6 | 字符串加密 | 字符串常量替换为 XOR 解密表达式 | 长度 ≤ 1 的字符串、f-string、`match/case` pattern 常量 |
|
|
123
|
+
| 7 | 常量折叠混淆 | 整数常量拆分为算术表达式 | 0、1、负数、> 10000 的整数、布尔值、`match/case` pattern 常量 |
|
|
124
|
+
|
|
125
|
+
> `ast.unparse()` 天然丢弃所有注释,无需额外处理。
|
|
126
|
+
|
|
127
|
+
使用 `--seed` 参数可固定随机种子,实现可复现混淆。
|
|
128
|
+
|
|
129
|
+
## 📚 Python API
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from AutoCython import compile # CLI 入口
|
|
133
|
+
from AutoCython.compile import compile_to_binary, get_platform_extension
|
|
134
|
+
from AutoCython.obfuscate import obfuscate_source
|
|
135
|
+
from AutoCython.run_tasks import run_tasks
|
|
136
|
+
from AutoCython.tools import find_python_files, get_system_language
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### `compile_to_binary(file_path, del_source=False, obfuscate=True, obfuscate_seed=None)`
|
|
140
|
+
|
|
141
|
+
将单个 `.py` 文件编译为二进制扩展(`.pyd` / `.so`)。当 `obfuscate=True` 且混淆失败时,会抛出 `RuntimeError`,避免静默回退到原始源码。
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from AutoCython.compile import compile_to_binary
|
|
145
|
+
|
|
146
|
+
output = compile_to_binary("example.py")
|
|
147
|
+
print(output) # example.cpython-312-x86_64-linux-gnu.so
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### `obfuscate_source(source_code, seed=None)`
|
|
151
|
+
|
|
152
|
+
对源码执行七重 AST 混淆变换,返回混淆后的源码字符串。
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from AutoCython.obfuscate import obfuscate_source
|
|
156
|
+
|
|
157
|
+
code = open("example.py").read()
|
|
158
|
+
obfuscated = obfuscate_source(code, seed=42)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### `run_tasks(task_list, max_workers=2, language=None, raise_on_failure=False)`
|
|
162
|
+
|
|
163
|
+
并发执行任务列表,实时显示 Rich 进度 UI。`task_list` 中每个元素为四元组 `(函数, 显示名称, 位置参数元组, 关键字参数字典)`。
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
from AutoCython.run_tasks import run_tasks
|
|
167
|
+
|
|
168
|
+
tasks = [
|
|
169
|
+
(func, display_name, (arg1, arg2), {}),
|
|
170
|
+
]
|
|
171
|
+
summary = run_tasks(tasks, max_workers=4)
|
|
172
|
+
# summary = {"total": N, "succeeded": N, "failed": N, "elapsed": float, "tasks": [...]}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### `find_python_files(path)`
|
|
176
|
+
|
|
177
|
+
递归查找目录下所有可编译的 `.py` 文件(排除 `__init__.py` 和标记文件)。
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
from AutoCython.tools import find_python_files
|
|
181
|
+
|
|
182
|
+
files = find_python_files("/path/to/project")
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## 🧪 测试
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
# 运行全部测试
|
|
189
|
+
pytest
|
|
190
|
+
|
|
191
|
+
# 只运行单元测试
|
|
192
|
+
pytest -m unit
|
|
193
|
+
|
|
194
|
+
# 只运行集成测试 (kd_dist)
|
|
195
|
+
pytest -m integ
|
|
196
|
+
|
|
197
|
+
# 排除集成测试(快速验证)
|
|
198
|
+
pytest -m "not integ"
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### kd-dist 集成测试
|
|
202
|
+
|
|
203
|
+
kd-dist 集成测试框架用于验证真实项目的编译兼容性和行为等价性。
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# 指定真实项目根目录(未设置则自动探测)
|
|
207
|
+
export KD_DIST_ROOT=/path/to/kd-dist
|
|
208
|
+
|
|
209
|
+
# 开启严格文件计数阈值校验(默认关闭)
|
|
210
|
+
export KD_DIST_STRICT_COUNTS=1
|
|
211
|
+
|
|
212
|
+
# 输出 kd-dist 分层测试 JSON 报告
|
|
213
|
+
export KD_DIST_REPORT_PATH=.pytest_cache/kd_dist_report.json
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
| 测试标记 | 说明 |
|
|
217
|
+
|----------|------|
|
|
218
|
+
| `kd_compile_plain` | 纯编译矩阵测试 |
|
|
219
|
+
| `kd_compile_obfuscate` | 混淆编译矩阵测试 |
|
|
220
|
+
| `kd_behavior` | 行为等价性验证 |
|
|
221
|
+
|
|
222
|
+
配置文件:
|
|
223
|
+
- `tests/kd_dist/manifest.json` — import policy 与行为等价用例
|
|
224
|
+
- `tests/kd_dist/known_failures.json` — 已知 Cython 不兼容文件(xfail 治理)
|
|
225
|
+
|
|
226
|
+
## 📁 项目结构
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
AutoCython/
|
|
230
|
+
├── AutoCython/
|
|
231
|
+
│ ├── __init__.py # 版本导入 + main() 入口
|
|
232
|
+
│ ├── _version.py # 版本号定义
|
|
233
|
+
│ ├── AutoCython.py # CLI 编译入口
|
|
234
|
+
│ ├── compile.py # Cython 编译核心逻辑
|
|
235
|
+
│ ├── obfuscate.py # AST 七重混淆引擎
|
|
236
|
+
│ ├── run_tasks.py # 并发任务执行 + Rich UI
|
|
237
|
+
│ └── tools.py # 工具函数(参数解析、文件查找、国际化)
|
|
238
|
+
├── tests/
|
|
239
|
+
│ ├── test_autocython.py # CLI 入口测试
|
|
240
|
+
│ ├── test_compile.py # 编译模块测试
|
|
241
|
+
│ ├── test_obfuscate.py # 混淆模块测试
|
|
242
|
+
│ ├── test_run_tasks.py # 并发任务测试
|
|
243
|
+
│ ├── test_tools.py # 工具函数测试
|
|
244
|
+
│ └── kd_dist/ # kd-dist 集成测试框架
|
|
245
|
+
├── pyproject.toml # 项目配置
|
|
246
|
+
├── requirements.txt # 依赖清单
|
|
247
|
+
├── LICENSE # MIT 许可证
|
|
248
|
+
└── README.md
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## ⚠️ 常见问题
|
|
252
|
+
|
|
253
|
+
| 问题 | 原因 | 解决方案 |
|
|
254
|
+
|------|------|----------|
|
|
255
|
+
| 编译失败 | 源码含 Cython 不支持的语法 | 查阅 [Cython Wiki](https://github.com/cython/cython/wiki) |
|
|
256
|
+
| 文件名不支持 | 含连字符等特殊字符 | 自动转下划线,或手动重命名 |
|
|
257
|
+
| 编译超时 | 单文件编译超过 300 秒 | 拆分大文件或检查死循环 |
|
|
258
|
+
| 混淆后运行异常 | 触发了不安全变换 | 使用 `# AutoCython No Compile` 排除该文件 |
|
|
259
|
+
|
|
260
|
+
## 📅 更新记录
|
|
261
|
+
|
|
262
|
+
### V2 版本
|
|
263
|
+
|
|
264
|
+
| 版本 | 日期 | 说明 |
|
|
265
|
+
|------|------|------|
|
|
266
|
+
| V2.3.0 | 2025 | 混淆测试集成 known failure 机制,更新构建和项目配置 |
|
|
267
|
+
| V2.1.0 | 2025-06-23 | 禁用激进性能优化选项,显示系统信息 |
|
|
268
|
+
| V2.0.0 | 2025-06-09 | 完全重构代码,使用新 UI |
|
|
269
|
+
|
|
270
|
+
### V1 版本
|
|
271
|
+
|
|
272
|
+
1. 20220613 — 新增 Linux 支持,需配置 gcc & g++
|
|
273
|
+
2. 20221123 — 支持文件头标记排除编译
|
|
274
|
+
3. 20230306 — 支持指定命令行头(如 `Python310`)以兼容非 Windows 编译
|
|
275
|
+
4. 20230324 — 文档更新
|
|
276
|
+
5. 20240506 — 修复编译失败时遗漏复原 `__init__.py` 的问题
|
|
277
|
+
|
|
278
|
+
## 📄 许可证
|
|
279
|
+
|
|
280
|
+
[MIT License](LICENSE)
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: AutoCython-zhang
|
|
3
|
+
Version: 2.3.1
|
|
4
|
+
Summary: 自动Cython,使用Cython批量编译.py文件为.pyd文件!
|
|
5
|
+
Author-email: zhang_gavin <qq814608@163.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: homepage, https://github.com/zhang0281/AutoCython
|
|
8
|
+
Project-URL: repository, https://github.com/zhang0281/AutoCython
|
|
9
|
+
Project-URL: documentation, https://github.com/zhang0281/AutoCython#readme
|
|
10
|
+
Keywords: cython,compile,pyd,pyc,python,autopyd
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: setuptools
|
|
17
|
+
Requires-Dist: cython
|
|
18
|
+
Requires-Dist: rich
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# AutoCython V2
|
|
22
|
+
|
|
23
|
+
**自动 Cython:一键将 Python 文件批量编译为 `PYD / SO` 二进制文件,内置 AST 七重混淆引擎**
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## ✨ 特性
|
|
27
|
+
|
|
28
|
+
- 单文件 / 目录批量编译
|
|
29
|
+
- 跨平台支持(Windows / Linux / macOS)
|
|
30
|
+
- AST 七重混淆引擎(可复现)
|
|
31
|
+
- Rich 实时进度 UI,中英文自动切换
|
|
32
|
+
- 编译后可选删除源码
|
|
33
|
+
- 自动 strip 符号表(Linux / macOS)
|
|
34
|
+
|
|
35
|
+
## 📦 安装
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install -U AutoCython-zhang
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
要求 Python ≥ 3.9。
|
|
42
|
+
|
|
43
|
+
## ⚙️ 依赖环境
|
|
44
|
+
|
|
45
|
+
### C/C++ 编译器
|
|
46
|
+
|
|
47
|
+
| 平台 | 编译器 |
|
|
48
|
+
|------|--------|
|
|
49
|
+
| Windows | Visual Studio(MSVC) |
|
|
50
|
+
| Linux | gcc & g++ |
|
|
51
|
+
| macOS | clang(Xcode Command Line Tools) |
|
|
52
|
+
|
|
53
|
+
**重要提示**:编译器架构必须与 Python 解释器一致(64 位 Python 需 64 位编译器)
|
|
54
|
+
|
|
55
|
+
> 其他编译器配置请参考 [Cython](https://github.com/cython/cython) 项目
|
|
56
|
+
|
|
57
|
+
## 🚀 使用指南
|
|
58
|
+
|
|
59
|
+
### 命令行参数
|
|
60
|
+
|
|
61
|
+
| 参数 | 说明 | 默认值 |
|
|
62
|
+
|------|------|--------|
|
|
63
|
+
| `-f, --file` | 编译单个文件 | — |
|
|
64
|
+
| `-p, --path` | 编译目录下所有 `.py` 文件 | — |
|
|
65
|
+
| `-c, --conc` | 并发编译线程数 | 2 |
|
|
66
|
+
| `-d, --del` | 编译后删除源代码 | False |
|
|
67
|
+
| `--seed` | 混淆随机种子(可复现构建) | None |
|
|
68
|
+
| `-v, --version` | 显示版本号 | — |
|
|
69
|
+
| `-h, --help` | 显示帮助信息 | — |
|
|
70
|
+
|
|
71
|
+
> `-f` 和 `-p` 互斥,不可同时使用。
|
|
72
|
+
|
|
73
|
+
### 命令行示例
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# 编译单个文件
|
|
77
|
+
AutoCython -f test.py
|
|
78
|
+
|
|
79
|
+
# 编译整个目录
|
|
80
|
+
AutoCython -p /path/to/project
|
|
81
|
+
|
|
82
|
+
# 编译后删除源代码
|
|
83
|
+
AutoCython -d -f test.py
|
|
84
|
+
AutoCython -d -p /path/to/project
|
|
85
|
+
|
|
86
|
+
# 4 线程并发编译
|
|
87
|
+
AutoCython -c 4 -p /path/to/project
|
|
88
|
+
|
|
89
|
+
# 指定混淆随机种子(可复现构建)
|
|
90
|
+
AutoCython --seed 2025 -f test.py
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 手动排除文件不编译
|
|
94
|
+
|
|
95
|
+
在文件 **前两行任意一行** 包含以下标记即可跳过编译:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
# AutoCython No Compile
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
> 兼容旧版拼写 `# AucoCython No Compile`
|
|
102
|
+
|
|
103
|
+
### 自动排除规则
|
|
104
|
+
|
|
105
|
+
以下文件和目录会被自动跳过:
|
|
106
|
+
|
|
107
|
+
- `__init__.py` 文件
|
|
108
|
+
- `__pycache__`、`venv`、`.venv`、`build`、`dist`、`node_modules`、`.git`、`.eggs` 目录
|
|
109
|
+
- `*.egg-info` 目录
|
|
110
|
+
|
|
111
|
+
## 🔐 AST 混淆引擎
|
|
112
|
+
|
|
113
|
+
编译前自动执行七重 AST 变换(按执行顺序),大幅提升逆向难度:
|
|
114
|
+
|
|
115
|
+
| 序号 | 变换 | 说明 | 安全跳过条件 |
|
|
116
|
+
|------|------|------|-------------|
|
|
117
|
+
| 1 | Docstring 移除 | 清除 module / class / function 的文档字符串 | 无 |
|
|
118
|
+
| 2 | Annotation 移除 | 清除函数参数、返回值、变量的类型注解 | 无 |
|
|
119
|
+
| 3 | 局部变量重命名 | 基于 hash 的标识符替换,保护闭包变量 | 含 `globals()`/`locals()`/`eval()`/`exec()`/`vars()` 调用 |
|
|
120
|
+
| 4 | 控制流平坦化 | 函数体转换为 `while True` + 状态机调度 | async 函数、yield/yield from、nonlocal/global 声明、comprehension、函数体 < 3 条语句、含不安全调用 |
|
|
121
|
+
| 5 | 虚假分支插入 | 30% 概率插入永真/永假不透明谓词 | 含不安全调用 |
|
|
122
|
+
| 6 | 字符串加密 | 字符串常量替换为 XOR 解密表达式 | 长度 ≤ 1 的字符串、f-string、`match/case` pattern 常量 |
|
|
123
|
+
| 7 | 常量折叠混淆 | 整数常量拆分为算术表达式 | 0、1、负数、> 10000 的整数、布尔值、`match/case` pattern 常量 |
|
|
124
|
+
|
|
125
|
+
> `ast.unparse()` 天然丢弃所有注释,无需额外处理。
|
|
126
|
+
|
|
127
|
+
使用 `--seed` 参数可固定随机种子,实现可复现混淆。
|
|
128
|
+
|
|
129
|
+
## 📚 Python API
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from AutoCython import compile # CLI 入口
|
|
133
|
+
from AutoCython.compile import compile_to_binary, get_platform_extension
|
|
134
|
+
from AutoCython.obfuscate import obfuscate_source
|
|
135
|
+
from AutoCython.run_tasks import run_tasks
|
|
136
|
+
from AutoCython.tools import find_python_files, get_system_language
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### `compile_to_binary(file_path, del_source=False, obfuscate=True, obfuscate_seed=None)`
|
|
140
|
+
|
|
141
|
+
将单个 `.py` 文件编译为二进制扩展(`.pyd` / `.so`)。当 `obfuscate=True` 且混淆失败时,会抛出 `RuntimeError`,避免静默回退到原始源码。
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from AutoCython.compile import compile_to_binary
|
|
145
|
+
|
|
146
|
+
output = compile_to_binary("example.py")
|
|
147
|
+
print(output) # example.cpython-312-x86_64-linux-gnu.so
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### `obfuscate_source(source_code, seed=None)`
|
|
151
|
+
|
|
152
|
+
对源码执行七重 AST 混淆变换,返回混淆后的源码字符串。
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from AutoCython.obfuscate import obfuscate_source
|
|
156
|
+
|
|
157
|
+
code = open("example.py").read()
|
|
158
|
+
obfuscated = obfuscate_source(code, seed=42)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### `run_tasks(task_list, max_workers=2, language=None, raise_on_failure=False)`
|
|
162
|
+
|
|
163
|
+
并发执行任务列表,实时显示 Rich 进度 UI。`task_list` 中每个元素为四元组 `(函数, 显示名称, 位置参数元组, 关键字参数字典)`。
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
from AutoCython.run_tasks import run_tasks
|
|
167
|
+
|
|
168
|
+
tasks = [
|
|
169
|
+
(func, display_name, (arg1, arg2), {}),
|
|
170
|
+
]
|
|
171
|
+
summary = run_tasks(tasks, max_workers=4)
|
|
172
|
+
# summary = {"total": N, "succeeded": N, "failed": N, "elapsed": float, "tasks": [...]}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### `find_python_files(path)`
|
|
176
|
+
|
|
177
|
+
递归查找目录下所有可编译的 `.py` 文件(排除 `__init__.py` 和标记文件)。
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
from AutoCython.tools import find_python_files
|
|
181
|
+
|
|
182
|
+
files = find_python_files("/path/to/project")
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## 🧪 测试
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
# 运行全部测试
|
|
189
|
+
pytest
|
|
190
|
+
|
|
191
|
+
# 只运行单元测试
|
|
192
|
+
pytest -m unit
|
|
193
|
+
|
|
194
|
+
# 只运行集成测试 (kd_dist)
|
|
195
|
+
pytest -m integ
|
|
196
|
+
|
|
197
|
+
# 排除集成测试(快速验证)
|
|
198
|
+
pytest -m "not integ"
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### kd-dist 集成测试
|
|
202
|
+
|
|
203
|
+
kd-dist 集成测试框架用于验证真实项目的编译兼容性和行为等价性。
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# 指定真实项目根目录(未设置则自动探测)
|
|
207
|
+
export KD_DIST_ROOT=/path/to/kd-dist
|
|
208
|
+
|
|
209
|
+
# 开启严格文件计数阈值校验(默认关闭)
|
|
210
|
+
export KD_DIST_STRICT_COUNTS=1
|
|
211
|
+
|
|
212
|
+
# 输出 kd-dist 分层测试 JSON 报告
|
|
213
|
+
export KD_DIST_REPORT_PATH=.pytest_cache/kd_dist_report.json
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
| 测试标记 | 说明 |
|
|
217
|
+
|----------|------|
|
|
218
|
+
| `kd_compile_plain` | 纯编译矩阵测试 |
|
|
219
|
+
| `kd_compile_obfuscate` | 混淆编译矩阵测试 |
|
|
220
|
+
| `kd_behavior` | 行为等价性验证 |
|
|
221
|
+
|
|
222
|
+
配置文件:
|
|
223
|
+
- `tests/kd_dist/manifest.json` — import policy 与行为等价用例
|
|
224
|
+
- `tests/kd_dist/known_failures.json` — 已知 Cython 不兼容文件(xfail 治理)
|
|
225
|
+
|
|
226
|
+
## 📁 项目结构
|
|
227
|
+
|
|
228
|
+
```
|
|
229
|
+
AutoCython/
|
|
230
|
+
├── AutoCython/
|
|
231
|
+
│ ├── __init__.py # 版本导入 + main() 入口
|
|
232
|
+
│ ├── _version.py # 版本号定义
|
|
233
|
+
│ ├── AutoCython.py # CLI 编译入口
|
|
234
|
+
│ ├── compile.py # Cython 编译核心逻辑
|
|
235
|
+
│ ├── obfuscate.py # AST 七重混淆引擎
|
|
236
|
+
│ ├── run_tasks.py # 并发任务执行 + Rich UI
|
|
237
|
+
│ └── tools.py # 工具函数(参数解析、文件查找、国际化)
|
|
238
|
+
├── tests/
|
|
239
|
+
│ ├── test_autocython.py # CLI 入口测试
|
|
240
|
+
│ ├── test_compile.py # 编译模块测试
|
|
241
|
+
│ ├── test_obfuscate.py # 混淆模块测试
|
|
242
|
+
│ ├── test_run_tasks.py # 并发任务测试
|
|
243
|
+
│ ├── test_tools.py # 工具函数测试
|
|
244
|
+
│ └── kd_dist/ # kd-dist 集成测试框架
|
|
245
|
+
├── pyproject.toml # 项目配置
|
|
246
|
+
├── requirements.txt # 依赖清单
|
|
247
|
+
├── LICENSE # MIT 许可证
|
|
248
|
+
└── README.md
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## ⚠️ 常见问题
|
|
252
|
+
|
|
253
|
+
| 问题 | 原因 | 解决方案 |
|
|
254
|
+
|------|------|----------|
|
|
255
|
+
| 编译失败 | 源码含 Cython 不支持的语法 | 查阅 [Cython Wiki](https://github.com/cython/cython/wiki) |
|
|
256
|
+
| 文件名不支持 | 含连字符等特殊字符 | 自动转下划线,或手动重命名 |
|
|
257
|
+
| 编译超时 | 单文件编译超过 300 秒 | 拆分大文件或检查死循环 |
|
|
258
|
+
| 混淆后运行异常 | 触发了不安全变换 | 使用 `# AutoCython No Compile` 排除该文件 |
|
|
259
|
+
|
|
260
|
+
## 📅 更新记录
|
|
261
|
+
|
|
262
|
+
### V2 版本
|
|
263
|
+
|
|
264
|
+
| 版本 | 日期 | 说明 |
|
|
265
|
+
|------|------|------|
|
|
266
|
+
| V2.3.0 | 2025 | 混淆测试集成 known failure 机制,更新构建和项目配置 |
|
|
267
|
+
| V2.1.0 | 2025-06-23 | 禁用激进性能优化选项,显示系统信息 |
|
|
268
|
+
| V2.0.0 | 2025-06-09 | 完全重构代码,使用新 UI |
|
|
269
|
+
|
|
270
|
+
### V1 版本
|
|
271
|
+
|
|
272
|
+
1. 20220613 — 新增 Linux 支持,需配置 gcc & g++
|
|
273
|
+
2. 20221123 — 支持文件头标记排除编译
|
|
274
|
+
3. 20230306 — 支持指定命令行头(如 `Python310`)以兼容非 Windows 编译
|
|
275
|
+
4. 20230324 — 文档更新
|
|
276
|
+
5. 20240506 — 修复编译失败时遗漏复原 `__init__.py` 的问题
|
|
277
|
+
|
|
278
|
+
## 📄 许可证
|
|
279
|
+
|
|
280
|
+
[MIT License](LICENSE)
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# AutoCython V2
|
|
2
|
+
|
|
3
|
+
**自动 Cython:一键将 Python 文件批量编译为 `PYD / SO` 二进制文件,内置 AST 七重混淆引擎**
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## ✨ 特性
|
|
7
|
+
|
|
8
|
+
- 单文件 / 目录批量编译
|
|
9
|
+
- 跨平台支持(Windows / Linux / macOS)
|
|
10
|
+
- AST 七重混淆引擎(可复现)
|
|
11
|
+
- Rich 实时进度 UI,中英文自动切换
|
|
12
|
+
- 编译后可选删除源码
|
|
13
|
+
- 自动 strip 符号表(Linux / macOS)
|
|
14
|
+
|
|
15
|
+
## 📦 安装
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install -U AutoCython-zhang
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
要求 Python ≥ 3.9。
|
|
22
|
+
|
|
23
|
+
## ⚙️ 依赖环境
|
|
24
|
+
|
|
25
|
+
### C/C++ 编译器
|
|
26
|
+
|
|
27
|
+
| 平台 | 编译器 |
|
|
28
|
+
|------|--------|
|
|
29
|
+
| Windows | Visual Studio(MSVC) |
|
|
30
|
+
| Linux | gcc & g++ |
|
|
31
|
+
| macOS | clang(Xcode Command Line Tools) |
|
|
32
|
+
|
|
33
|
+
**重要提示**:编译器架构必须与 Python 解释器一致(64 位 Python 需 64 位编译器)
|
|
34
|
+
|
|
35
|
+
> 其他编译器配置请参考 [Cython](https://github.com/cython/cython) 项目
|
|
36
|
+
|
|
37
|
+
## 🚀 使用指南
|
|
38
|
+
|
|
39
|
+
### 命令行参数
|
|
40
|
+
|
|
41
|
+
| 参数 | 说明 | 默认值 |
|
|
42
|
+
|------|------|--------|
|
|
43
|
+
| `-f, --file` | 编译单个文件 | — |
|
|
44
|
+
| `-p, --path` | 编译目录下所有 `.py` 文件 | — |
|
|
45
|
+
| `-c, --conc` | 并发编译线程数 | 2 |
|
|
46
|
+
| `-d, --del` | 编译后删除源代码 | False |
|
|
47
|
+
| `--seed` | 混淆随机种子(可复现构建) | None |
|
|
48
|
+
| `-v, --version` | 显示版本号 | — |
|
|
49
|
+
| `-h, --help` | 显示帮助信息 | — |
|
|
50
|
+
|
|
51
|
+
> `-f` 和 `-p` 互斥,不可同时使用。
|
|
52
|
+
|
|
53
|
+
### 命令行示例
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# 编译单个文件
|
|
57
|
+
AutoCython -f test.py
|
|
58
|
+
|
|
59
|
+
# 编译整个目录
|
|
60
|
+
AutoCython -p /path/to/project
|
|
61
|
+
|
|
62
|
+
# 编译后删除源代码
|
|
63
|
+
AutoCython -d -f test.py
|
|
64
|
+
AutoCython -d -p /path/to/project
|
|
65
|
+
|
|
66
|
+
# 4 线程并发编译
|
|
67
|
+
AutoCython -c 4 -p /path/to/project
|
|
68
|
+
|
|
69
|
+
# 指定混淆随机种子(可复现构建)
|
|
70
|
+
AutoCython --seed 2025 -f test.py
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 手动排除文件不编译
|
|
74
|
+
|
|
75
|
+
在文件 **前两行任意一行** 包含以下标记即可跳过编译:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
# AutoCython No Compile
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
> 兼容旧版拼写 `# AucoCython No Compile`
|
|
82
|
+
|
|
83
|
+
### 自动排除规则
|
|
84
|
+
|
|
85
|
+
以下文件和目录会被自动跳过:
|
|
86
|
+
|
|
87
|
+
- `__init__.py` 文件
|
|
88
|
+
- `__pycache__`、`venv`、`.venv`、`build`、`dist`、`node_modules`、`.git`、`.eggs` 目录
|
|
89
|
+
- `*.egg-info` 目录
|
|
90
|
+
|
|
91
|
+
## 🔐 AST 混淆引擎
|
|
92
|
+
|
|
93
|
+
编译前自动执行七重 AST 变换(按执行顺序),大幅提升逆向难度:
|
|
94
|
+
|
|
95
|
+
| 序号 | 变换 | 说明 | 安全跳过条件 |
|
|
96
|
+
|------|------|------|-------------|
|
|
97
|
+
| 1 | Docstring 移除 | 清除 module / class / function 的文档字符串 | 无 |
|
|
98
|
+
| 2 | Annotation 移除 | 清除函数参数、返回值、变量的类型注解 | 无 |
|
|
99
|
+
| 3 | 局部变量重命名 | 基于 hash 的标识符替换,保护闭包变量 | 含 `globals()`/`locals()`/`eval()`/`exec()`/`vars()` 调用 |
|
|
100
|
+
| 4 | 控制流平坦化 | 函数体转换为 `while True` + 状态机调度 | async 函数、yield/yield from、nonlocal/global 声明、comprehension、函数体 < 3 条语句、含不安全调用 |
|
|
101
|
+
| 5 | 虚假分支插入 | 30% 概率插入永真/永假不透明谓词 | 含不安全调用 |
|
|
102
|
+
| 6 | 字符串加密 | 字符串常量替换为 XOR 解密表达式 | 长度 ≤ 1 的字符串、f-string、`match/case` pattern 常量 |
|
|
103
|
+
| 7 | 常量折叠混淆 | 整数常量拆分为算术表达式 | 0、1、负数、> 10000 的整数、布尔值、`match/case` pattern 常量 |
|
|
104
|
+
|
|
105
|
+
> `ast.unparse()` 天然丢弃所有注释,无需额外处理。
|
|
106
|
+
|
|
107
|
+
使用 `--seed` 参数可固定随机种子,实现可复现混淆。
|
|
108
|
+
|
|
109
|
+
## 📚 Python API
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
from AutoCython import compile # CLI 入口
|
|
113
|
+
from AutoCython.compile import compile_to_binary, get_platform_extension
|
|
114
|
+
from AutoCython.obfuscate import obfuscate_source
|
|
115
|
+
from AutoCython.run_tasks import run_tasks
|
|
116
|
+
from AutoCython.tools import find_python_files, get_system_language
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### `compile_to_binary(file_path, del_source=False, obfuscate=True, obfuscate_seed=None)`
|
|
120
|
+
|
|
121
|
+
将单个 `.py` 文件编译为二进制扩展(`.pyd` / `.so`)。当 `obfuscate=True` 且混淆失败时,会抛出 `RuntimeError`,避免静默回退到原始源码。
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from AutoCython.compile import compile_to_binary
|
|
125
|
+
|
|
126
|
+
output = compile_to_binary("example.py")
|
|
127
|
+
print(output) # example.cpython-312-x86_64-linux-gnu.so
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### `obfuscate_source(source_code, seed=None)`
|
|
131
|
+
|
|
132
|
+
对源码执行七重 AST 混淆变换,返回混淆后的源码字符串。
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from AutoCython.obfuscate import obfuscate_source
|
|
136
|
+
|
|
137
|
+
code = open("example.py").read()
|
|
138
|
+
obfuscated = obfuscate_source(code, seed=42)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### `run_tasks(task_list, max_workers=2, language=None, raise_on_failure=False)`
|
|
142
|
+
|
|
143
|
+
并发执行任务列表,实时显示 Rich 进度 UI。`task_list` 中每个元素为四元组 `(函数, 显示名称, 位置参数元组, 关键字参数字典)`。
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from AutoCython.run_tasks import run_tasks
|
|
147
|
+
|
|
148
|
+
tasks = [
|
|
149
|
+
(func, display_name, (arg1, arg2), {}),
|
|
150
|
+
]
|
|
151
|
+
summary = run_tasks(tasks, max_workers=4)
|
|
152
|
+
# summary = {"total": N, "succeeded": N, "failed": N, "elapsed": float, "tasks": [...]}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### `find_python_files(path)`
|
|
156
|
+
|
|
157
|
+
递归查找目录下所有可编译的 `.py` 文件(排除 `__init__.py` 和标记文件)。
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
from AutoCython.tools import find_python_files
|
|
161
|
+
|
|
162
|
+
files = find_python_files("/path/to/project")
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## 🧪 测试
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
# 运行全部测试
|
|
169
|
+
pytest
|
|
170
|
+
|
|
171
|
+
# 只运行单元测试
|
|
172
|
+
pytest -m unit
|
|
173
|
+
|
|
174
|
+
# 只运行集成测试 (kd_dist)
|
|
175
|
+
pytest -m integ
|
|
176
|
+
|
|
177
|
+
# 排除集成测试(快速验证)
|
|
178
|
+
pytest -m "not integ"
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### kd-dist 集成测试
|
|
182
|
+
|
|
183
|
+
kd-dist 集成测试框架用于验证真实项目的编译兼容性和行为等价性。
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
# 指定真实项目根目录(未设置则自动探测)
|
|
187
|
+
export KD_DIST_ROOT=/path/to/kd-dist
|
|
188
|
+
|
|
189
|
+
# 开启严格文件计数阈值校验(默认关闭)
|
|
190
|
+
export KD_DIST_STRICT_COUNTS=1
|
|
191
|
+
|
|
192
|
+
# 输出 kd-dist 分层测试 JSON 报告
|
|
193
|
+
export KD_DIST_REPORT_PATH=.pytest_cache/kd_dist_report.json
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
| 测试标记 | 说明 |
|
|
197
|
+
|----------|------|
|
|
198
|
+
| `kd_compile_plain` | 纯编译矩阵测试 |
|
|
199
|
+
| `kd_compile_obfuscate` | 混淆编译矩阵测试 |
|
|
200
|
+
| `kd_behavior` | 行为等价性验证 |
|
|
201
|
+
|
|
202
|
+
配置文件:
|
|
203
|
+
- `tests/kd_dist/manifest.json` — import policy 与行为等价用例
|
|
204
|
+
- `tests/kd_dist/known_failures.json` — 已知 Cython 不兼容文件(xfail 治理)
|
|
205
|
+
|
|
206
|
+
## 📁 项目结构
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
AutoCython/
|
|
210
|
+
├── AutoCython/
|
|
211
|
+
│ ├── __init__.py # 版本导入 + main() 入口
|
|
212
|
+
│ ├── _version.py # 版本号定义
|
|
213
|
+
│ ├── AutoCython.py # CLI 编译入口
|
|
214
|
+
│ ├── compile.py # Cython 编译核心逻辑
|
|
215
|
+
│ ├── obfuscate.py # AST 七重混淆引擎
|
|
216
|
+
│ ├── run_tasks.py # 并发任务执行 + Rich UI
|
|
217
|
+
│ └── tools.py # 工具函数(参数解析、文件查找、国际化)
|
|
218
|
+
├── tests/
|
|
219
|
+
│ ├── test_autocython.py # CLI 入口测试
|
|
220
|
+
│ ├── test_compile.py # 编译模块测试
|
|
221
|
+
│ ├── test_obfuscate.py # 混淆模块测试
|
|
222
|
+
│ ├── test_run_tasks.py # 并发任务测试
|
|
223
|
+
│ ├── test_tools.py # 工具函数测试
|
|
224
|
+
│ └── kd_dist/ # kd-dist 集成测试框架
|
|
225
|
+
├── pyproject.toml # 项目配置
|
|
226
|
+
├── requirements.txt # 依赖清单
|
|
227
|
+
├── LICENSE # MIT 许可证
|
|
228
|
+
└── README.md
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## ⚠️ 常见问题
|
|
232
|
+
|
|
233
|
+
| 问题 | 原因 | 解决方案 |
|
|
234
|
+
|------|------|----------|
|
|
235
|
+
| 编译失败 | 源码含 Cython 不支持的语法 | 查阅 [Cython Wiki](https://github.com/cython/cython/wiki) |
|
|
236
|
+
| 文件名不支持 | 含连字符等特殊字符 | 自动转下划线,或手动重命名 |
|
|
237
|
+
| 编译超时 | 单文件编译超过 300 秒 | 拆分大文件或检查死循环 |
|
|
238
|
+
| 混淆后运行异常 | 触发了不安全变换 | 使用 `# AutoCython No Compile` 排除该文件 |
|
|
239
|
+
|
|
240
|
+
## 📅 更新记录
|
|
241
|
+
|
|
242
|
+
### V2 版本
|
|
243
|
+
|
|
244
|
+
| 版本 | 日期 | 说明 |
|
|
245
|
+
|------|------|------|
|
|
246
|
+
| V2.3.0 | 2025 | 混淆测试集成 known failure 机制,更新构建和项目配置 |
|
|
247
|
+
| V2.1.0 | 2025-06-23 | 禁用激进性能优化选项,显示系统信息 |
|
|
248
|
+
| V2.0.0 | 2025-06-09 | 完全重构代码,使用新 UI |
|
|
249
|
+
|
|
250
|
+
### V1 版本
|
|
251
|
+
|
|
252
|
+
1. 20220613 — 新增 Linux 支持,需配置 gcc & g++
|
|
253
|
+
2. 20221123 — 支持文件头标记排除编译
|
|
254
|
+
3. 20230306 — 支持指定命令行头(如 `Python310`)以兼容非 Windows 编译
|
|
255
|
+
4. 20230324 — 文档更新
|
|
256
|
+
5. 20240506 — 修复编译失败时遗漏复原 `__init__.py` 的问题
|
|
257
|
+
|
|
258
|
+
## 📄 许可证
|
|
259
|
+
|
|
260
|
+
[MIT License](LICENSE)
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: AutoCython-zhang
|
|
3
|
-
Version: 2.3.0
|
|
4
|
-
Summary: 自动Cython,使用Cython批量编译.py文件为.pyd文件!
|
|
5
|
-
Author-email: zhang_gavin <qq814608@163.com>
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: homepage, https://github.com/zhang0281/AutoCython
|
|
8
|
-
Project-URL: repository, https://github.com/zhang0281/AutoCython
|
|
9
|
-
Project-URL: documentation, https://github.com/zhang0281/AutoCython#readme
|
|
10
|
-
Keywords: cython,compile,pyd,pyc,python,autopyd
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Operating System :: OS Independent
|
|
13
|
-
Requires-Python: >=3.9
|
|
14
|
-
Description-Content-Type: text/markdown
|
|
15
|
-
License-File: LICENSE
|
|
16
|
-
Requires-Dist: setuptools
|
|
17
|
-
Requires-Dist: cython
|
|
18
|
-
Requires-Dist: rich
|
|
19
|
-
Dynamic: license-file
|
|
20
|
-
|
|
21
|
-
# AutoCython V2
|
|
22
|
-
中文 | [English](https://github.com/EVA-JianJun/AutoCython/blob/master/README.en.md)
|
|
23
|
-
|
|
24
|
-
**自动 Cython:一键将 Python 文件批量编译为 `PYD / SO` 文件**
|
|
25
|
-

|
|
26
|
-
|
|
27
|
-
## ✨ 特性
|
|
28
|
-
- 单文件/多文件批量编译
|
|
29
|
-
- 跨平台支持 (Windows/Linux/MacOS)
|
|
30
|
-
- 简洁命令行界面
|
|
31
|
-
|
|
32
|
-
## 📦 安装
|
|
33
|
-
```bash
|
|
34
|
-
pip install -U AutoCython-zhang
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## ⚙️ 依赖环境
|
|
38
|
-
### C/C++ 编译器
|
|
39
|
-
- **Windows**: Visual Studio
|
|
40
|
-
- **Linux**: gcc & g++
|
|
41
|
-
|
|
42
|
-
**重要提示**:编译器架构必须与Python解释器一致(64位Python需64位编译器)
|
|
43
|
-
|
|
44
|
-
> 其他编译器配置请参考 [Cython](https://github.com/cython/cython) 项目
|
|
45
|
-
|
|
46
|
-
## 🚀 使用指南
|
|
47
|
-
### 命令行操作
|
|
48
|
-

|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
# 编译单个文件
|
|
52
|
-
AutoCython -f test.py
|
|
53
|
-
|
|
54
|
-
# 编译整个目录
|
|
55
|
-
AutoCython -p D:/python_code/ProjectPath
|
|
56
|
-
|
|
57
|
-
# 编译后删除源代码 (默认不删除)
|
|
58
|
-
AutoCython -d -f test.py
|
|
59
|
-
AutoCython -d -p D:/python_code/ProjectPath
|
|
60
|
-
|
|
61
|
-
# 指定混淆随机种子(可复现构建)
|
|
62
|
-
AutoCython --seed 2025 -f test.py
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### 编译界面
|
|
66
|
-

|
|
67
|
-
|
|
68
|
-
### 手动排除文件不编译
|
|
69
|
-
在文件头部 **前两行** 添加声明:
|
|
70
|
-
```python
|
|
71
|
-
# AutoCython No Compile
|
|
72
|
-
# 此文件将跳过编译处理
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## 🧪 测试
|
|
76
|
-
```bash
|
|
77
|
-
# 运行全部测试
|
|
78
|
-
pytest
|
|
79
|
-
|
|
80
|
-
# 只运行单元测试
|
|
81
|
-
pytest -m unit
|
|
82
|
-
|
|
83
|
-
# 只运行集成测试 (kd_dist)
|
|
84
|
-
pytest -m integ
|
|
85
|
-
|
|
86
|
-
# 排除集成测试(快速验证)
|
|
87
|
-
pytest -m "not integ"
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### kd-dist 集成测试配置
|
|
91
|
-
```bash
|
|
92
|
-
# 指定真实项目根目录(未设置则自动探测)
|
|
93
|
-
export KD_DIST_ROOT=/path/to/kd-dist
|
|
94
|
-
|
|
95
|
-
# 开启严格文件计数阈值校验(默认关闭)
|
|
96
|
-
export KD_DIST_STRICT_COUNTS=1
|
|
97
|
-
|
|
98
|
-
# 输出 kd-dist 分层测试 JSON 报告
|
|
99
|
-
export KD_DIST_REPORT_PATH=.pytest_cache/kd_dist_report.json
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
`tests/kd_dist/manifest.json` 用于定义 import policy 与行为等价用例,
|
|
103
|
-
`tests/kd_dist/known_failures.json` 用于记录已知 Cython 不兼容文件(xfail 治理)。
|
|
104
|
-
|
|
105
|
-
## ⚠️ 常见问题解决
|
|
106
|
-
|
|
107
|
-
一般是源代码中有 Cython 不支持的语句, 或者文件名不支持等.
|
|
108
|
-
可以查阅 [Cython Wiki](https://github.com/cython/cython/wiki) 项目 官方文档, 或者提 Issue.
|
|
109
|
-
|
|
110
|
-
## 📅 更新记录
|
|
111
|
-
### V2 版本
|
|
112
|
-
1. 20250623 release V2.1.0 禁用激进的性能优化选项. 显示系统信息.
|
|
113
|
-
2. 20250609 release V2.0.0 重构了代码, 使用新的界面 (不安全版本)
|
|
114
|
-
|
|
115
|
-
### V1 版本
|
|
116
|
-
1. 20220613 更新对Linux的支持, Linux下需要配置gcc&g++
|
|
117
|
-
2. 20221123 可以通过文件头手动指定不编译的文件
|
|
118
|
-
3. 20230306 更新可以指定命令行头如 `Python310` 以此支持非Widnows系统下编译
|
|
119
|
-
4. 20230324 更新文档
|
|
120
|
-
5. 20240506 修复编译失败时遗漏复原 \_\_init\_\_.py 的问题
|
autocython_zhang-2.3.0/PKG-INFO
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: AutoCython-zhang
|
|
3
|
-
Version: 2.3.0
|
|
4
|
-
Summary: 自动Cython,使用Cython批量编译.py文件为.pyd文件!
|
|
5
|
-
Author-email: zhang_gavin <qq814608@163.com>
|
|
6
|
-
License-Expression: MIT
|
|
7
|
-
Project-URL: homepage, https://github.com/zhang0281/AutoCython
|
|
8
|
-
Project-URL: repository, https://github.com/zhang0281/AutoCython
|
|
9
|
-
Project-URL: documentation, https://github.com/zhang0281/AutoCython#readme
|
|
10
|
-
Keywords: cython,compile,pyd,pyc,python,autopyd
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Operating System :: OS Independent
|
|
13
|
-
Requires-Python: >=3.9
|
|
14
|
-
Description-Content-Type: text/markdown
|
|
15
|
-
License-File: LICENSE
|
|
16
|
-
Requires-Dist: setuptools
|
|
17
|
-
Requires-Dist: cython
|
|
18
|
-
Requires-Dist: rich
|
|
19
|
-
Dynamic: license-file
|
|
20
|
-
|
|
21
|
-
# AutoCython V2
|
|
22
|
-
中文 | [English](https://github.com/EVA-JianJun/AutoCython/blob/master/README.en.md)
|
|
23
|
-
|
|
24
|
-
**自动 Cython:一键将 Python 文件批量编译为 `PYD / SO` 文件**
|
|
25
|
-

|
|
26
|
-
|
|
27
|
-
## ✨ 特性
|
|
28
|
-
- 单文件/多文件批量编译
|
|
29
|
-
- 跨平台支持 (Windows/Linux/MacOS)
|
|
30
|
-
- 简洁命令行界面
|
|
31
|
-
|
|
32
|
-
## 📦 安装
|
|
33
|
-
```bash
|
|
34
|
-
pip install -U AutoCython-zhang
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## ⚙️ 依赖环境
|
|
38
|
-
### C/C++ 编译器
|
|
39
|
-
- **Windows**: Visual Studio
|
|
40
|
-
- **Linux**: gcc & g++
|
|
41
|
-
|
|
42
|
-
**重要提示**:编译器架构必须与Python解释器一致(64位Python需64位编译器)
|
|
43
|
-
|
|
44
|
-
> 其他编译器配置请参考 [Cython](https://github.com/cython/cython) 项目
|
|
45
|
-
|
|
46
|
-
## 🚀 使用指南
|
|
47
|
-
### 命令行操作
|
|
48
|
-

|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
# 编译单个文件
|
|
52
|
-
AutoCython -f test.py
|
|
53
|
-
|
|
54
|
-
# 编译整个目录
|
|
55
|
-
AutoCython -p D:/python_code/ProjectPath
|
|
56
|
-
|
|
57
|
-
# 编译后删除源代码 (默认不删除)
|
|
58
|
-
AutoCython -d -f test.py
|
|
59
|
-
AutoCython -d -p D:/python_code/ProjectPath
|
|
60
|
-
|
|
61
|
-
# 指定混淆随机种子(可复现构建)
|
|
62
|
-
AutoCython --seed 2025 -f test.py
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### 编译界面
|
|
66
|
-

|
|
67
|
-
|
|
68
|
-
### 手动排除文件不编译
|
|
69
|
-
在文件头部 **前两行** 添加声明:
|
|
70
|
-
```python
|
|
71
|
-
# AutoCython No Compile
|
|
72
|
-
# 此文件将跳过编译处理
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## 🧪 测试
|
|
76
|
-
```bash
|
|
77
|
-
# 运行全部测试
|
|
78
|
-
pytest
|
|
79
|
-
|
|
80
|
-
# 只运行单元测试
|
|
81
|
-
pytest -m unit
|
|
82
|
-
|
|
83
|
-
# 只运行集成测试 (kd_dist)
|
|
84
|
-
pytest -m integ
|
|
85
|
-
|
|
86
|
-
# 排除集成测试(快速验证)
|
|
87
|
-
pytest -m "not integ"
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### kd-dist 集成测试配置
|
|
91
|
-
```bash
|
|
92
|
-
# 指定真实项目根目录(未设置则自动探测)
|
|
93
|
-
export KD_DIST_ROOT=/path/to/kd-dist
|
|
94
|
-
|
|
95
|
-
# 开启严格文件计数阈值校验(默认关闭)
|
|
96
|
-
export KD_DIST_STRICT_COUNTS=1
|
|
97
|
-
|
|
98
|
-
# 输出 kd-dist 分层测试 JSON 报告
|
|
99
|
-
export KD_DIST_REPORT_PATH=.pytest_cache/kd_dist_report.json
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
`tests/kd_dist/manifest.json` 用于定义 import policy 与行为等价用例,
|
|
103
|
-
`tests/kd_dist/known_failures.json` 用于记录已知 Cython 不兼容文件(xfail 治理)。
|
|
104
|
-
|
|
105
|
-
## ⚠️ 常见问题解决
|
|
106
|
-
|
|
107
|
-
一般是源代码中有 Cython 不支持的语句, 或者文件名不支持等.
|
|
108
|
-
可以查阅 [Cython Wiki](https://github.com/cython/cython/wiki) 项目 官方文档, 或者提 Issue.
|
|
109
|
-
|
|
110
|
-
## 📅 更新记录
|
|
111
|
-
### V2 版本
|
|
112
|
-
1. 20250623 release V2.1.0 禁用激进的性能优化选项. 显示系统信息.
|
|
113
|
-
2. 20250609 release V2.0.0 重构了代码, 使用新的界面 (不安全版本)
|
|
114
|
-
|
|
115
|
-
### V1 版本
|
|
116
|
-
1. 20220613 更新对Linux的支持, Linux下需要配置gcc&g++
|
|
117
|
-
2. 20221123 可以通过文件头手动指定不编译的文件
|
|
118
|
-
3. 20230306 更新可以指定命令行头如 `Python310` 以此支持非Widnows系统下编译
|
|
119
|
-
4. 20230324 更新文档
|
|
120
|
-
5. 20240506 修复编译失败时遗漏复原 \_\_init\_\_.py 的问题
|
autocython_zhang-2.3.0/README.md
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
# AutoCython V2
|
|
2
|
-
中文 | [English](https://github.com/EVA-JianJun/AutoCython/blob/master/README.en.md)
|
|
3
|
-
|
|
4
|
-
**自动 Cython:一键将 Python 文件批量编译为 `PYD / SO` 文件**
|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
## ✨ 特性
|
|
8
|
-
- 单文件/多文件批量编译
|
|
9
|
-
- 跨平台支持 (Windows/Linux/MacOS)
|
|
10
|
-
- 简洁命令行界面
|
|
11
|
-
|
|
12
|
-
## 📦 安装
|
|
13
|
-
```bash
|
|
14
|
-
pip install -U AutoCython-zhang
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## ⚙️ 依赖环境
|
|
18
|
-
### C/C++ 编译器
|
|
19
|
-
- **Windows**: Visual Studio
|
|
20
|
-
- **Linux**: gcc & g++
|
|
21
|
-
|
|
22
|
-
**重要提示**:编译器架构必须与Python解释器一致(64位Python需64位编译器)
|
|
23
|
-
|
|
24
|
-
> 其他编译器配置请参考 [Cython](https://github.com/cython/cython) 项目
|
|
25
|
-
|
|
26
|
-
## 🚀 使用指南
|
|
27
|
-
### 命令行操作
|
|
28
|
-

|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
# 编译单个文件
|
|
32
|
-
AutoCython -f test.py
|
|
33
|
-
|
|
34
|
-
# 编译整个目录
|
|
35
|
-
AutoCython -p D:/python_code/ProjectPath
|
|
36
|
-
|
|
37
|
-
# 编译后删除源代码 (默认不删除)
|
|
38
|
-
AutoCython -d -f test.py
|
|
39
|
-
AutoCython -d -p D:/python_code/ProjectPath
|
|
40
|
-
|
|
41
|
-
# 指定混淆随机种子(可复现构建)
|
|
42
|
-
AutoCython --seed 2025 -f test.py
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### 编译界面
|
|
46
|
-

|
|
47
|
-
|
|
48
|
-
### 手动排除文件不编译
|
|
49
|
-
在文件头部 **前两行** 添加声明:
|
|
50
|
-
```python
|
|
51
|
-
# AutoCython No Compile
|
|
52
|
-
# 此文件将跳过编译处理
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## 🧪 测试
|
|
56
|
-
```bash
|
|
57
|
-
# 运行全部测试
|
|
58
|
-
pytest
|
|
59
|
-
|
|
60
|
-
# 只运行单元测试
|
|
61
|
-
pytest -m unit
|
|
62
|
-
|
|
63
|
-
# 只运行集成测试 (kd_dist)
|
|
64
|
-
pytest -m integ
|
|
65
|
-
|
|
66
|
-
# 排除集成测试(快速验证)
|
|
67
|
-
pytest -m "not integ"
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### kd-dist 集成测试配置
|
|
71
|
-
```bash
|
|
72
|
-
# 指定真实项目根目录(未设置则自动探测)
|
|
73
|
-
export KD_DIST_ROOT=/path/to/kd-dist
|
|
74
|
-
|
|
75
|
-
# 开启严格文件计数阈值校验(默认关闭)
|
|
76
|
-
export KD_DIST_STRICT_COUNTS=1
|
|
77
|
-
|
|
78
|
-
# 输出 kd-dist 分层测试 JSON 报告
|
|
79
|
-
export KD_DIST_REPORT_PATH=.pytest_cache/kd_dist_report.json
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
`tests/kd_dist/manifest.json` 用于定义 import policy 与行为等价用例,
|
|
83
|
-
`tests/kd_dist/known_failures.json` 用于记录已知 Cython 不兼容文件(xfail 治理)。
|
|
84
|
-
|
|
85
|
-
## ⚠️ 常见问题解决
|
|
86
|
-
|
|
87
|
-
一般是源代码中有 Cython 不支持的语句, 或者文件名不支持等.
|
|
88
|
-
可以查阅 [Cython Wiki](https://github.com/cython/cython/wiki) 项目 官方文档, 或者提 Issue.
|
|
89
|
-
|
|
90
|
-
## 📅 更新记录
|
|
91
|
-
### V2 版本
|
|
92
|
-
1. 20250623 release V2.1.0 禁用激进的性能优化选项. 显示系统信息.
|
|
93
|
-
2. 20250609 release V2.0.0 重构了代码, 使用新的界面 (不安全版本)
|
|
94
|
-
|
|
95
|
-
### V1 版本
|
|
96
|
-
1. 20220613 更新对Linux的支持, Linux下需要配置gcc&g++
|
|
97
|
-
2. 20221123 可以通过文件头手动指定不编译的文件
|
|
98
|
-
3. 20230306 更新可以指定命令行头如 `Python310` 以此支持非Widnows系统下编译
|
|
99
|
-
4. 20230324 更新文档
|
|
100
|
-
5. 20240506 修复编译失败时遗漏复原 \_\_init\_\_.py 的问题
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/AutoCython_zhang.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{autocython_zhang-2.3.0 → autocython_zhang-2.3.1}/AutoCython_zhang.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|