1+ # -*- mode: python ; coding: utf-8 -*-
2+
3+ import os
4+ import sys
5+ from pathlib import Path
6+
7+ # Get the project root directory;
8+ project_root = Path ('.' ).resolve ()
9+
10+ # Conditional file existence checks for optional resources;
11+ def add_data_if_exists (src_path , dst_path ):
12+ """Add data file to the list only if it exists;"""
13+ if os .path .exists (src_path ):
14+ return [(src_path , dst_path )]
15+ return []
16+
17+ # Build data files list with existence checks;
18+ data_files = []
19+
20+ # Add locales directory for internationalization support;
21+ locales_dir = project_root / 'locales'
22+ if locales_dir .exists ():
23+ for locale_file in locales_dir .glob ('*.json' ):
24+ data_files .append ((str (locale_file ), 'locales' ))
25+
26+ # Add config.json if it exists;
27+ config_file = project_root / 'config.json'
28+ data_files .extend (add_data_if_exists (str (config_file ), '.' ))
29+
30+ # Add version.json if it exists;
31+ version_file = project_root / 'version.json'
32+ data_files .extend (add_data_if_exists (str (version_file ), '.' ))
33+
34+ # Hidden imports for better compatibility;
35+ hidden_imports = [
36+ # CustomTkinter and GUI related;
37+ 'customtkinter' ,
38+ 'customtkinter.windows' ,
39+ 'customtkinter.windows.widgets' ,
40+ 'tkinter' ,
41+ 'tkinter.ttk' ,
42+ 'tkinter.messagebox' ,
43+ 'tkinter.filedialog' ,
44+
45+ # HTML/Markdown rendering;
46+ 'tkhtmlview' ,
47+ 'markdown2' ,
48+ 'pygments' ,
49+ 'pygments.lexers' ,
50+ 'pygments.formatters' ,
51+
52+ # Image processing;
53+ 'PIL' ,
54+ 'PIL.Image' ,
55+ 'PIL.ImageTk' ,
56+ 'PIL.ImageDraw' ,
57+ 'PIL.ImageFont' ,
58+
59+ # PDF processing;
60+ 'fitz' , # PyMuPDF;
61+ 'pymupdf' ,
62+
63+ # HTTP and networking;
64+ 'requests' ,
65+ 'urllib3' ,
66+ 'tenacity' ,
67+
68+ # JSON and utilities;
69+ 'json' ,
70+ 'jsbeautifier' ,
71+ 'tqdm' ,
72+
73+ # Application modules;
74+ 'src' ,
75+ 'src.gui' ,
76+ 'src.gui.main_window' ,
77+ 'src.gui.panels' ,
78+ 'src.gui.panels.left_panel' ,
79+ 'src.gui.panels.center_panel' ,
80+ 'src.gui.panels.right_panel' ,
81+ 'src.gui.panels.right_panel_sections' ,
82+ 'src.gui.panels.right_panel_sections.api_section' ,
83+ 'src.gui.panels.right_panel_sections.control_section' ,
84+ 'src.gui.panels.right_panel_sections.log_section' ,
85+ 'src.gui.panels.right_panel_sections.mode_section' ,
86+ 'src.gui.panels.right_panel_sections.page_section' ,
87+ 'src.gui.panels.right_panel_sections.progress_section' ,
88+ 'src.config' ,
89+ 'src.config.settings' ,
90+ 'src.api' ,
91+ 'src.api.monkey_ocr_client' ,
92+ 'src.utils' ,
93+ 'src.utils.file_utils' ,
94+ 'src.utils.i18n' ,
95+ ]
96+
97+ # Modules to exclude from the build;
98+ exclude_modules = [
99+ 'matplotlib' ,
100+ 'numpy' ,
101+ 'scipy' ,
102+ 'pandas' ,
103+ 'IPython' ,
104+ 'jupyter' ,
105+ 'notebook' ,
106+ 'pytest' ,
107+ 'setuptools' ,
108+ 'distutils' ,
109+ ]
110+
111+ # Check for icon file;
112+ icon_path = None
113+ possible_icons = ['icon.ico' , 'app.ico' , 'monkey.ico' , 'assets/icon.ico' ]
114+ for icon_file in possible_icons :
115+ if os .path .exists (icon_file ):
116+ icon_path = icon_file
117+ break
118+
119+ a = Analysis (
120+ ['main.py' ],
121+ pathex = [],
122+ binaries = [],
123+ datas = data_files ,
124+ hiddenimports = hidden_imports ,
125+ hookspath = [],
126+ hooksconfig = {},
127+ runtime_hooks = [],
128+ excludes = exclude_modules ,
129+ win_no_prefer_redirects = False ,
130+ win_private_assemblies = False ,
131+ cipher = None ,
132+ noarchive = False ,
133+ )
134+
135+ pyz = PYZ (a .pure , a .zipped_data , cipher = None )
136+
137+ exe = EXE (
138+ pyz ,
139+ a .scripts ,
140+ a .binaries ,
141+ a .zipfiles ,
142+ a .datas ,
143+ [],
144+ name = 'MonkeyOCR' ,
145+ debug = False ,
146+ bootloader_ignore_signals = False ,
147+ strip = False ,
148+ upx = True ,
149+ upx_exclude = [],
150+ runtime_tmpdir = None ,
151+ console = False , # GUI application, no console window;
152+ disable_windowed_traceback = False ,
153+ target_arch = None ,
154+ codesign_identity = None ,
155+ entitlements_file = None ,
156+ icon = icon_path , # Will be None if no icon found;
157+ )
0 commit comments