将 .py 和 .pyi 后缀名改为了 .vp 和 .vpi 后缀名

This commit is contained in:
2026-07-30 16:33:56 +08:00
parent f79c8ca643
commit cfc30d735c
322 changed files with 246 additions and 31772 deletions

View File

@@ -119,7 +119,7 @@ class Phase1Generator:
for root, dirs, files in os.walk(includes_dir):
dirs[:] = [d for d in dirs if not d.startswith('.') and d != '__pycache__']
for fname in files:
if fname.endswith('.py') or fname.endswith('.pyi'):
if fname.endswith('.vp') or fname.endswith('.py') or fname.endswith('.vpi') or fname.endswith('.pyi'):
src_path: str = os.path.join(root, fname)
rel_from_inc: str = os.path.relpath(src_path, includes_dir)
ModulePath: str = rel_from_inc.replace(os.sep, '.').replace('/', '.')
@@ -127,10 +127,10 @@ class Phase1Generator:
info: tuple[str, str, str] = (src_path, rel_from_inc, includes_dir)
include_file_map[module_name] = info
top_pkg: str = module_name.split('.')[0]
# __init__.py 是包入口,应优先作为 top_pkg 的代表
# __init__.vp/__init__.py 是包入口,应优先作为 top_pkg 的代表
# (参考 find_reachable_files_from_entries 的优先级逻辑),
# 否则若 os/path.py 先被遍历,'os' 会错误指向 path.py
# 而非 os/__init__.py,导致包入口 SHA1 未注册到 sha1_map
# 否则若 os/path.vp 先被遍历,'os' 会错误指向 path.vp
# 而非 os/__init__.vp导致包入口 SHA1 未注册到 sha1_map
if module_name == f"{top_pkg}.__init__":
include_file_map[top_pkg] = info
elif top_pkg not in include_file_map:
@@ -208,12 +208,15 @@ class Phase1Generator:
return needed_infos
def run(self) -> None:
"""扫描源目录,只处理入口文件可达的 .py 文件(导入遍历)"""
"""扫描源目录,只处理入口文件可达的 .vp/.py 文件(导入遍历)"""
py_files: list[str]
if self.entry_files:
py_files = list(self.entry_files)
else:
main_py: str = os.path.join(self.src_root, 'main.py')
main_py: str = os.path.join(self.src_root, 'main.vp')
if not os.path.exists(main_py):
# 回退到 main.py向后兼容
main_py = os.path.join(self.src_root, 'main.py')
if os.path.exists(main_py):
py_files = [main_py]
else:
@@ -221,7 +224,7 @@ class Phase1Generator:
for root, dirs, files in os.walk(self.src_root):
dirs[:] = [d for d in dirs if d not in ('__pycache__',)]
for file in files:
if file.endswith('.py'):
if file.endswith('.vp') or file.endswith('.py'):
py_files.append(os.path.join(root, file))
if not py_files:
@@ -286,7 +289,7 @@ class Phase1Generator:
for root, dirs, files in os.walk(includes_dir):
dirs[:] = [d for d in dirs if not d.startswith('.') and d != '__pycache__']
for fname in files:
if fname.endswith('.py') or fname.endswith('.pyi'):
if fname.endswith('.vp') or fname.endswith('.py') or fname.endswith('.vpi') or fname.endswith('.pyi'):
src_path: str = os.path.join(root, fname)
rel_from_inc: str = os.path.relpath(src_path, includes_dir)
include_py_files.append((src_path, rel_from_inc, includes_dir))
@@ -315,14 +318,14 @@ class Phase1Generator:
self.include_py_map[top_module] = sha1
self.include_py_map[module_name] = sha1
sig_path: str = os.path.join(self.temp_dir, f"{sha1}.pyi")
sig_path: str = os.path.join(self.temp_dir, f"{sha1}.vpi")
if os.path.isfile(sig_path):
_vlog().info(f" 缓存命中: {rel_from_inc} -> {sha1}.pyi")
_vlog().info(f" 缓存命中: {rel_from_inc} -> {sha1}.vpi")
continue
# 全局缓存检查(不被 --clean 清除)
if _TryGlobalCache(sha1, 'pyi', sig_path):
_vlog().info(f" 缓存命中(全局): {rel_from_inc} -> {sha1}.pyi")
_vlog().info(f" 缓存命中(全局): {rel_from_inc} -> {sha1}.vpi")
continue
# 缓存未命中,需读取 content 生成 .pyi
@@ -332,7 +335,7 @@ class Phase1Generator:
with open(sig_path, 'w', encoding='utf-8', newline='\n') as f:
f.write(sig_content)
_SaveToGlobalCache(sha1, 'pyi', sig_path)
_vlog().info(f" 生成签名: {rel_from_inc} -> {sha1}.pyi")
_vlog().info(f" 生成签名: {rel_from_inc} -> {sha1}.vpi")
except Exception as e:
_vlog().error(f"处理 include 文件失败 {rel_from_inc}: {e}")
@@ -341,7 +344,7 @@ class Phase1Generator:
if not os.path.isdir(self.temp_dir):
return typedef_map
for fname in os.listdir(self.temp_dir):
if not fname.endswith('.pyi'):
if not (fname.endswith('.vpi') or fname.endswith('.pyi')):
continue
pyi_path: str = os.path.join(self.temp_dir, fname)
try:
@@ -474,7 +477,7 @@ class Phase1Generator:
except Exception:
pass
sig_path: str = os.path.join(self.temp_dir, f"{sha1}.pyi")
sig_path: str = os.path.join(self.temp_dir, f"{sha1}.vpi")
if not os.path.isfile(sig_path):
_TryGlobalCache(sha1, 'pyi', sig_path)
with open(sig_path, 'r', encoding='utf-8') as f:
@@ -530,9 +533,9 @@ class Phase1Generator:
return
self.sha1_map[sha1] = rel_path.replace(os.sep, '/').replace(chr(92), '/')
sig_path: str = os.path.join(self.temp_dir, f"{sha1}.pyi")
sig_path: str = os.path.join(self.temp_dir, f"{sha1}.vpi")
if os.path.isfile(sig_path):
_vlog().info(f" -> {sha1}.pyi (缓存)")
_vlog().info(f" -> {sha1}.vpi (缓存)")
# 缓存命中时补全缺失的 .doc.json
doc_path: str = os.path.join(self.temp_dir, f"{sha1}.doc.json")
if not os.path.isfile(doc_path):
@@ -551,7 +554,7 @@ class Phase1Generator:
# 全局缓存检查
if _TryGlobalCache(sha1, 'pyi', sig_path):
_vlog().info(f" -> {sha1}.pyi (全局缓存)")
_vlog().info(f" -> {sha1}.vpi (全局缓存)")
doc_path: str = os.path.join(self.temp_dir, f"{sha1}.doc.json")
if not os.path.isfile(doc_path):
_TryGlobalCache(sha1, 'doc.json', doc_path)
@@ -566,7 +569,7 @@ class Phase1Generator:
with open(sig_path, 'w', encoding='utf-8', newline='\n') as f:
f.write(sig_content)
_SaveToGlobalCache(sha1, 'pyi', sig_path)
_vlog().info(f" -> {sha1}.pyi (签名)")
_vlog().info(f" -> {sha1}.vpi (签名)")
# 提取 docstring 写入 {sha1}.doc.json供 Phase2 跨模块 __doc__ 加载
docs: dict[str, str] = self._extract_docstrings(content)
@@ -588,7 +591,7 @@ class Phase1Generator:
_vlog().info(f" -> {sha1}.stub.ll (缓存)")
return
sig_path: str = os.path.join(self.temp_dir, f"{sha1}.pyi")
sig_path: str = os.path.join(self.temp_dir, f"{sha1}.vpi")
with open(sig_path, 'r', encoding='utf-8') as f:
sig_content: str = f.read()
@@ -613,9 +616,9 @@ class Phase1Generator:
ctype_marker_names.add(attr_name)
valid_sha1_keys: set[str] = set(self.sha1_map.keys())
for fname in os.listdir(self.temp_dir):
if not fname.endswith('.pyi'):
if not (fname.endswith('.vpi') or fname.endswith('.pyi')):
continue
sha1_key: str = fname.replace('.pyi', '')
sha1_key: str = fname.replace('.vpi', '').replace('.pyi', '')
if sha1_key not in valid_sha1_keys:
continue
pyi_path: str = os.path.join(self.temp_dir, fname)