78 lines
2.6 KiB
Python
78 lines
2.6 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
import site
|
|
import re
|
|
import sys
|
|
|
|
def patch_paddle_core():
|
|
"""
|
|
paddle/base/core.py 파일에서 site.USER_SITE 관련 버그를 수정하는 패치 함수
|
|
|
|
문제: site.USER_SITE가 None일 때 발생하는 오류 수정
|
|
해결: hasattr(site, 'USER_SITE') 조건에 and site.USER_SITE 추가
|
|
"""
|
|
print("패들 코어 패치 시작...")
|
|
|
|
# site-packages 경로 찾기
|
|
site_packages = site.getsitepackages()
|
|
paddle_core_paths = []
|
|
|
|
# 가능한 모든 경로에서 paddle/base/core.py 찾기
|
|
for site_dir in site_packages:
|
|
core_path = os.path.join(site_dir, 'paddle', 'base', 'core.py')
|
|
if os.path.exists(core_path):
|
|
paddle_core_paths.append(core_path)
|
|
|
|
if not paddle_core_paths:
|
|
print("paddle/base/core.py 파일을 찾을 수 없습니다.")
|
|
return False
|
|
|
|
success = False
|
|
|
|
for core_path in paddle_core_paths:
|
|
print(f"패치 대상 파일 발견: {core_path}")
|
|
|
|
# 파일 내용 읽기
|
|
with open(core_path, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
# 패치 전 백업 생성
|
|
backup_path = core_path + '.backup'
|
|
if not os.path.exists(backup_path):
|
|
with open(backup_path, 'w', encoding='utf-8') as f:
|
|
f.write(content)
|
|
print(f"백업 파일 생성: {backup_path}")
|
|
|
|
# 패치 패턴 매칭: if hasattr(site, 'USER_SITE') 찾기
|
|
pattern = r'if\s+hasattr\(site,\s+\'USER_SITE\'\)'
|
|
|
|
# 패치가 필요한지 확인
|
|
if not re.search(pattern + r'\s+and\s+site\.USER_SITE', content):
|
|
# 패치 적용 (and site.USER_SITE 추가)
|
|
patched_content = re.sub(
|
|
pattern,
|
|
"if hasattr(site, 'USER_SITE') and site.USER_SITE",
|
|
content
|
|
)
|
|
|
|
# 패치된 내용으로 파일 업데이트
|
|
with open(core_path, 'w', encoding='utf-8') as f:
|
|
f.write(patched_content)
|
|
|
|
print(f"성공적으로 패치되었습니다: {core_path}")
|
|
success = True
|
|
else:
|
|
print(f"이미 패치가 적용되어 있습니다: {core_path}")
|
|
success = True
|
|
|
|
if success:
|
|
print("패들 코어 패치 완료!")
|
|
return True
|
|
else:
|
|
print("패치 실패: 적절한 패치 포인트를 찾을 수 없습니다.")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
patch_paddle_core() |