Skip to main content
Glama
fix_imports.py1.26 kB
#!/usr/bin/env python3 """ 修复所有相对导入问题 """ import os import re from pathlib import Path def fix_imports(file_path): """修复单个文件的相对导入""" try: with open(file_path, 'r', encoding='utf-8') as f: content = f.read() original_content = content # 替换 from ..module import pattern content = re.sub(r'from \.\.(\w+\.?\w*) import', r'from \1 import', content) # 替换 from .module import pattern content = re.sub(r'from \.(\w+\.?\w*) import', r'from \1 import', content) if content != original_content: with open(file_path, 'w', encoding='utf-8') as f: f.write(content) print(f"Fixed imports in: {file_path}") return True except Exception as e: print(f"Error fixing {file_path}: {e}") return False return False def main(): src_path = Path(__file__).parent / "src" fixed_count = 0 for py_file in src_path.rglob("*.py"): if py_file.is_file(): if fix_imports(py_file): fixed_count += 1 print(f"Fixed imports in {fixed_count} files") if __name__ == "__main__": main()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kscz0000/Zhiwen-Assistant-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server