51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
"""探针12:全量位置差分 vast.dump(include_attributes=True) vs CPython。"""
|
|
import sys, os, glob
|
|
sys.path.insert(0, r'd:\Users\TermiNexus\Desktop\TransPyC\lib')
|
|
import vast as ast
|
|
import ast as cpy_ast
|
|
|
|
files = sorted(glob.glob(r'd:\Users\TermiNexus\Desktop\TransPyC\lib\**\*.py', recursive=True))
|
|
files += sorted(glob.glob(r'd:\Users\TermiNexus\Desktop\TransPyC\lib\*.py'))
|
|
files = sorted(set(files))
|
|
|
|
# 排除测试脚本
|
|
files = [f for f in files if '_test' not in os.path.basename(f) and '_probe' not in os.path.basename(f) and 'vast' not in f.replace('\\', '/').split('/lib/')[0]]
|
|
|
|
ok = 0
|
|
fail = []
|
|
skip = []
|
|
for f in files:
|
|
try:
|
|
with open(f, 'r', encoding='utf-8') as fh:
|
|
src = fh.read()
|
|
except Exception as e:
|
|
skip.append((f, f'read: {e}'))
|
|
continue
|
|
try:
|
|
cpy = cpy_ast.dump(cpy_ast.parse(src), indent=2, include_attributes=True)
|
|
except SyntaxError as e:
|
|
skip.append((f, f'cpy SyntaxError: {e}'))
|
|
continue
|
|
except Exception as e:
|
|
skip.append((f, f'cpy {e}'))
|
|
continue
|
|
try:
|
|
vas = ast.dump(ast.parse(src), indent=2, include_attributes=True)
|
|
except Exception as e:
|
|
fail.append((f, f'vast: {e}'))
|
|
continue
|
|
if vas != cpy:
|
|
# 定位第一个差异
|
|
import difflib
|
|
diff = list(difflib.unified_diff(cpy.split('\n'), vas.split('\n'), lineterm='', n=0))
|
|
fail.append((f, f'DIFF:\n' + '\n'.join(diff[:12])))
|
|
else:
|
|
ok += 1
|
|
|
|
print(f"=== 位置差分结果 ===")
|
|
print(f"文件总数: {len(files)} 一致: {ok} 失败: {len(fail)} 跳过: {len(skip)}")
|
|
for f, reason in fail[:8]:
|
|
print(f"\n>>> {f}\n{reason}")
|
|
for f, reason in skip[:5]:
|
|
print(f"[skip] {f}: {reason}")
|