IMG_Worker/modules/onnx_ocr_module/setup_onnx_ocr.py

94 lines
2.3 KiB
Python

# -*- coding: utf-8 -*-
import os
import sys
from cx_Freeze import setup, Executable
# 메타데이터 스캔으로 인한 재귀 이슈를 피하기 위해 간단한 우회 적용
try:
import cx_Freeze.module as _cx_mod
def _noop_update_distribution(self, name=None):
return None
_cx_mod.Module.update_distribution = _noop_update_distribution # type: ignore[attr-defined]
# 훅 로딩 자체를 비활성화하여 재귀 이슈 회피
def _noop_load_hook(self):
return None
_cx_mod.Module.load_hook = _noop_load_hook # type: ignore[attr-defined]
except Exception:
pass
base_dir = os.path.dirname(os.path.abspath(__file__))
src_dir = os.path.join(base_dir, "src")
includes = [
# onnxruntime 런타임 사용 경로만 명시 (나머지는 런타임에 src 경로에서 import)
"onnxruntime",
]
packages = [
"os",
"sys",
]
excludes = [
# 완전 ONNX-only 경로: paddle 계열 제외
"paddle",
"paddleocr",
"paddlehub",
# 호스트 환경에서 로드하도록 제외
"numpy",
"cv2",
"PIL",
"onnxruntime",
]
include_files = []
# 모델/사전 파일 포함
models_dir = os.path.join(base_dir, "models")
dict_dir = os.path.join(base_dir, "dict")
test_dir = os.path.join(base_dir, "test")
if os.path.isdir(models_dir):
include_files.append((models_dir, "models"))
if os.path.isdir(dict_dir):
include_files.append((dict_dir, "dict"))
if os.path.isdir(test_dir):
include_files.append((test_dir, "test"))
# 런타임에 src를 import 경로로 쓰므로 동봉
if os.path.isdir(src_dir):
include_files.append((src_dir, "src"))
# zip 대신 평문 폴더 배치로 경로 문제 회피
zip_includes = []
build_exe_options = {
"includes": includes,
"packages": packages,
"excludes": excludes,
"include_files": include_files,
"zip_include_packages": zip_includes,
"include_msvcr": True,
"optimize": 0,
"silent": True,
}
executables = [
Executable(
script=os.path.join(base_dir, "run_ocr_test.py"),
base=None,
target_name="onnx_ocr_test.exe",
)
]
setup(
name="onnx_ocr_test",
version="0.1.0",
description="ONNX OCR module minimal test",
options={"build_exe": build_exe_options},
executables=executables,
)