# import sys # log_file = open("setup.log", "a", encoding="utf-8") # class LoggerWriter: # def __init__(self, stream, log_file): # self.stream = stream # self.log_file = log_file # def write(self, message): # self.stream.write(message) # self.log_file.write(message) # def flush(self): # self.stream.flush() # self.log_file.flush() # sys.stdout = LoggerWriter(sys.stdout, log_file) # sys.stderr = LoggerWriter(sys.stderr, log_file)# setup.py import sys, os from cx_Freeze import setup, Executable # from PySide6 import QtCore # import ssl from setuptools import find_packages from updateManager.__version__ import ( __title__, __version__, __description__, __author__, __author_email__, __license__, __install_requires__, __exe_name__, __icon_file__, __main_script__, __file_log_level__, __gui_log_level__ ) import subprocess from setuptools.command.build_ext import build_ext from setuptools.command.install import install from cx_Freeze.command.build_exe import build_exe as _build_exe import importlib.util import logging # 패들 코어 패치 적용 print("패들 코어 패치 검사 및 적용...") try: import patch_paddle_core patch_paddle_core.patch_paddle_core() except Exception as e: print(f"패들 코어 패치 적용 중 오류 발생: {e}") print("패치 실패, 빌드 계속 진행합니다.") # 필요한 파일 경로 설정 base_dir = os.path.dirname(__file__) browsers_dir = os.path.join(base_dir, 'src', 'browsers') chromium_dir = os.path.join(browsers_dir, 'src', 'browsers', 'chromium-1155') # whale_dir = os.path.join(browsers_dir, 'src', 'browsers', 'whale') extensions_dir = os.path.join(browsers_dir, 'src', 'browsers', 'extensions') # user_data_dir = os.path.join(browsers_dir, 'src', 'browsers', 'user_data') # include_files = [ # os.path.abspath('config.ini'), # os.path.abspath('prompt.json'), # os.path.abspath('userDB.db'), # os.path.abspath('HakgyoansimDunggeunmisoTTFB.ttf'), # (os.path.abspath('src/initialDB.db'), 'src/initialDB.db'), # (os.path.abspath('src/Percenty_SS_Code.json'), 'src/Percenty_SS_Code.json'), # (os.path.abspath(chromium_dir), 'browsers/chromium-1155'), # (os.path.abspath(whale_dir), 'browsers/whale'), # (os.path.abspath(extensions_dir), 'browsers/extensions'), # (os.path.abspath(user_data_dir), 'browsers/user_data'), # ] # PySide6 DLL 경로 추가 # pyside6_path = os.path.join(os.path.dirname(sys.executable), "Lib", "site-packages", "PySide6") # pyside6_plugins_path = os.path.join(pyside6_path, "plugins") # pyside6_bin_path = pyside6_path # 'bin' 폴더가 없으면 기본 경로 사용 dll_files = [ # "LIBPQ.dll", # "MIMAPI64.dll", # "Qt63DQuickScene3D.dll", "api-ms-win-core-com-l1-1-0.dll", "api-ms-win-core-debug-l1-1-0.dll", "api-ms-win-core-errorhandling-l1-1-0.dll", "api-ms-win-core-handle-l1-1-0.dll", "api-ms-win-core-heap-l1-1-0.dll", # "api-ms-win-core-heap-l2-1-0.dll", "api-ms-win-core-interlocked-l1-1-0.dll", # "api-ms-win-core-libraryloader-l1-2-0.dll", # "api-ms-win-core-libraryloader-l1-2-1.dll", "api-ms-win-core-localization-l1-2-0.dll", # "api-ms-win-core-path-l1-1-0.dll", "api-ms-win-core-processthreads-l1-1-0.dll", "api-ms-win-core-processthreads-l1-1-1.dll", "api-ms-win-core-profile-l1-1-0.dll", # "api-ms-win-core-realtime-l1-1-1.dll", "api-ms-win-core-rtlsupport-l1-1-0.dll", "api-ms-win-core-synch-l1-1-0.dll", "api-ms-win-core-synch-l1-2-0.dll", "api-ms-win-core-sysinfo-l1-1-0.dll", # "api-ms-win-core-winrt-error-l1-1-0.dll", # "api-ms-win-core-winrt-l1-1-0.dll", # "api-ms-win-core-winrt-string-l1-1-0.dll", "api-ms-win-crt-conio-l1-1-0.dll", "api-ms-win-crt-environment-l1-1-0.dll", "api-ms-win-crt-filesystem-l1-1-0.dll", "api-ms-win-crt-multibyte-l1-1-0.dll", "api-ms-win-crt-private-l1-1-0.dll", "api-ms-win-crt-process-l1-1-0.dll", "api-ms-win-crt-time-l1-1-0.dll", "api-ms-win-crt-utility-l1-1-0.dll", # "api-ms-win-power-base-l1-1-0.dll", # "api-ms-win-power-setting-l1-1-0.dll", # "api-ms-win-shcore-scaling-l1-1-1.dll", ] # ✅ DLL 경로 설정 (Windows 10의 System32에서 가져오기) system32_path = "C:/Windows/System32/downlevel" dll_include_files = [(os.path.join(system32_path, dll), dll) for dll in dll_files] dll_include_files = [] # 충돌 가능성으로 인해 빈 리스트로 초기화 # 패들 라이브러리 경로 설정 # 경로 수정: scripts/Lib -> Lib로 변경 base_path = os.path.dirname(os.path.abspath(__file__)) site_packages = os.path.join(base_path, "Lib", "site-packages") # 올바른 경로 지정 paddle_path = os.path.join(site_packages, "paddle") paddleocr_path = os.path.join(site_packages, "paddleocr") paddle_includes = [] # 경로가 존재하는 경우에만 포함 if os.path.exists(paddle_path): paddle_includes.append((paddle_path, 'lib/paddle')) print(f"paddle 경로 추가: {paddle_path}") if os.path.exists(paddleocr_path): paddle_includes.append((paddleocr_path, 'lib/paddleocr')) print(f"paddleocr 경로 추가: {paddleocr_path}") onnxruntime_capi = os.path.join(site_packages, 'onnxruntime', 'capi') if os.path.exists(onnxruntime_capi): onnxruntime_includes.append((onnxruntime_capi, 'lib/onnxruntime/capi')) vc_runtime_files = [ ('C:/Windows/System32/vcruntime140.dll', 'vcruntime140.dll'), ('C:/Windows/System32/vcruntime140_1.dll', 'vcruntime140_1.dll'), ('C:/Windows/System32/msvcp140.dll', 'msvcp140.dll'), ('C:/Windows/System32/msvcp140_1.dll', 'msvcp140_1.dll'), ('C:/Windows/System32/msvcp140_2.dll', 'msvcp140_2.dll'), ('C:/Windows/System32/concrt140.dll', 'concrt140.dll'), ('C:/Windows/System32/vcomp140.dll', 'vcomp140.dll'), ] include_files.extend([f for f in vc_runtime_files if os.path.exists(f[0])]) # ✅ 기존 포함 파일 + DLL 추가 include_files = dll_include_files + paddle_includes + onnxruntime_includes + vc_runtime_files + [ # include_files = dll_include_files + [ # 나머지 파일들 ('src/ppocr/PP_Models', 'lib/src/ppocr/PP_Models'), ('src/Edit_PartTimer3.ico', 'lib/src/Edit_PartTimer3.ico'), # 아이콘 파일 경로 수정 ('win.exe.manifest', 'win.exe.manifest'), ('libssl-3-x64.dll', 'libssl-3-x64.dll'), ('libcrypto-3-x64.dll', 'libcrypto-3-x64.dll'), ('kiprisCategories.json', 'kiprisCategories.json'), ('src/keyword/kiprisCategories.json', 'lib/src/keyword/kiprisCategories.json'), ('src/modules/fonts/Cafe24Ohsquare-v2.0.ttf', 'lib/src/fonts/Cafe24Ohsquare-v2.0.ttf'), ('src/modules/fonts/gamtanload.ttf', 'lib/src/fonts/gamtanload.ttf'), ('src/modules/fonts/NanumBarunGothic.ttf', 'lib/src/fonts/NanumBarunGothic.ttf'), ('src/modules/fonts/NanumSquareRoundR.ttf', 'lib/src/fonts/NanumSquareRoundR.ttf'), ('src/modules/fonts/HakgyoansimDunggeunmisoTTFB.ttf', 'lib/src/fonts/HakgyoansimDunggeunmisoTTFB.ttf'), ('src/modules/fonts/Cafe24Ohsquare-v2.0.ttf', 'lib/src/modules/fonts/Cafe24Ohsquare-v2.0.ttf'), ('src/modules/fonts/gamtanload.ttf', 'lib/src/modules/fonts/gamtanload.ttf'), ('src/modules/fonts/NanumBarunGothic.ttf', 'lib/src/modules/fonts/NanumBarunGothic.ttf'), ('src/modules/fonts/NanumSquareRoundR.ttf', 'lib/src/modules/fonts/NanumSquareRoundR.ttf'), ('src/modules/fonts/HakgyoansimDunggeunmisoTTFB.ttf', 'lib/src/modules/fonts/HakgyoansimDunggeunmisoTTFB.ttf'), ('src/modules/migan_onnx/migan_pipeline_v2.onnx', 'lib/src/modules/migan_onnx/migan_onnx/migan_pipeline_v2.onnx'), ('퍼센티 다양한 카테고리 엑셀 수집(스스 기준).xlsx', '퍼센티 다양한 카테고리 엑셀 수집(스스 기준).xlsx'), ('src/Percenty_SS_Code.json', 'lib/src/Percenty_SS_Code.json'), ('src/browsers/chromium-1155', 'lib/src/browsers/chromium-1155'), # ('src/browsers/whale', 'lib/src/browsers/whale'), ('src/browsers/extensions', 'lib/src/browsers/extensions'), # ('src/browsers/user_data', 'lib/src/browsers/user_data'), # ('src/browsers/whale/user_data', 'lib/src/browsers/whale/user_data'), # (pyside6_bin_path, "PySide6"), # PySide6 DLL 파일 경로 # (pyside6_plugins_path, "PySide6/plugins"), # plugins 경로 추가 ('C:/Windows/System32/vcomp140.dll', 'vcomp140.dll'), ] for src, dest in include_files: if not os.path.exists(src): print(f"경로가 존재하지 않습니다: {src}") # 사용된 패키지 정의 build_exe_options = { 'include_msvcr': True, # VC++ 런타임 자동 포함 'packages': [ 'ctypes', 'asyncio', 'subprocess', 'pyperclip', 'numpy', 'numba', 'rembg', # rembg 의존성 추가 'cv2', 'requests', 'pyclipper', 'skimage', 'PIL', 'bs4', 'PySide6', 'psutil', # 'win32api', 'win32file', 'win32pipe', 'win32event', 'pywintypes', 'win32con', 'win32process', 'win32clipboard', 'win32gui', 'pandas', 'supabase', 'translatepy', 'markdown', 'paddle', 'paddleocr', # paddle 관련 모듈 포함 'jsonschema', # rembg 추가 의존성 ], 'includes': [ # 'PySide6.QtWidgets', 'PySide6.QtCore', 'PySide6.QtGui', 'shiboken6','playwright','comtypes.stream', 'win32com.client', 'win32com.server', 'pythoncom', 'loggerModule', 'toggleSwitch', 'src.modules.request_inpaint', 'onnxruntime', 'rembg', 'numba', 'numba.core.types.old_scalars', 'jsonschema', # rembg 관련 의존성 추가 'numba.core', 'numba.core.types', 'numba.core.types.scalars', 'numba.typed', 'numba.experimental', # numba 내부 모듈들 'browser_control', 'locatorManager', 'src.cmdDiag', 'src.inputDiag', 'src.keyword', 'src.priceSetDiag', 'src.modules.image_processor3', 'skimage', 'skimage.morphology', 'skimage.measure', 'skimage.filters', 'skimage.color', 'skimage.util', 'imghdr', 'imgaug', 'rapidfuzz', 'albumentations', 'albumentations', 'cython', 'fire', 'lmdb', 'PIL', 'docx', 'yaml', 'shapely', 'tqdm', ], 'include_files': include_files, 'excludes': [ 'tkinter', 'PyQt4', 'PyQt5', 'AppKit', 'Foundation', 'IPython', 'OpenSSL', 'curses', 'test', 'matplotlib', 'asyncpg' ], 'zip_include_packages': [], # 아무 패키지도 압축하지 않음 (numpy 관련 문제 해결) 'silent': True # 디버그 메시지 활성화 } # 애플리케이션 메인 파일 및 설정 base = None if sys.platform == 'win32': base = 'Win32GUI' # ✅ 아이콘 지정: icon='파일경로.ico' executables = [ Executable( 'main.py', base=base, target_name='Edit_PartTimer3.exe', icon="Edit_PartTimer3.ico" ) ] # build_exe 클래스를 확장하여 빌드 후 iss 파일 생성 class build_exe(_build_exe): def run(self): # # 빌드 전에 로그 레벨을 INFO로 변경 # self._set_log_level_for_production() # 원래 빌드 프로세스 실행 _build_exe.run(self) print("\n빌드가 완료되었습니다. 이제 Inno Setup 스크립트 생성을 시작합니다...\n") try: # generate_iss.py 스크립트 실행 result = subprocess.run([sys.executable, "generate_iss.py"], capture_output=True, text=True) if result.returncode == 0: print(result.stdout) print("\nInno Setup 스크립트 생성이 완료되었습니다!") else: print(f"Inno Setup 스크립트 생성 중 오류 발생: {result.stderr}") except Exception as e: print(f"Inno Setup 스크립트 생성 중 예외 발생: {e}") # def _set_log_level_for_production(self): # """패키징 시 로그 레벨을 INFO로 설정합니다""" # version_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'updateManager', '__version__.py') # # 파일 내용 읽기 # with open(version_file_path, 'r', encoding='utf-8') as f: # content = f.read() # # DEBUG를 INFO로 변경 # if 'logging.DEBUG' in content: # content = content.replace('__log_level__ = logging.DEBUG', '__log_level__ = logging.INFO') # # 변경된 내용 저장 # with open(version_file_path, 'w', encoding='utf-8') as f: # f.write(content) # print("로그 레벨이 배포 버전에 맞게 INFO로 변경되었습니다.") if __name__ == '__main__': # Setup 설정 (cmdclass에 build_exe 추가) setup( name=__title__, version=__version__, description=__description__, author=__author__, author_email=__author_email__, license=__license__, packages=find_packages(), install_requires=__install_requires__, python_requires='>=3.11', include_package_data=True, zip_safe=False, options={'build_exe': build_exe_options}, executables=executables, cmdclass={ "build_exe": build_exe, }, )