Skip to content

Commit 717c8cd

Browse files
committed
feat: enhance runtime data file collection and exclude unnecessary packages to optimize bundle size
1 parent c0cc4f4 commit 717c8cd

1 file changed

Lines changed: 60 additions & 22 deletions

File tree

sarcasm.spec

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,60 @@ except ImportError:
4545
# Dynamic platform-aware naming
4646
appname = f"SarcAsM-v{version}"
4747

48-
# 1. Include Napari resources
48+
# ---------------------------------------------------------------------------
49+
# Data files required at runtime
50+
# ---------------------------------------------------------------------------
4951
napari_data = collect_data_files('napari')
50-
51-
# 2. Include Vispy resources (critical for GLSL shaders)
52+
napari_builtins_data = collect_data_files('napari_builtins')
5253
vispy_data = collect_data_files('vispy')
54+
rfc3987_data = collect_data_files('rfc3987_syntax')
55+
lark_data = collect_data_files('lark')
5356

54-
# 3. Include models directory (recursive)
5557
model_data = [
5658
('sarcasm/models', 'sarcasm/models'),
5759
]
5860

61+
# ---------------------------------------------------------------------------
62+
# Packages NOT used by the app — exclude to cut bundle size and startup time
63+
# ---------------------------------------------------------------------------
64+
excludes = [
65+
# Documentation / dev tools (pulled transitively, not needed at runtime)
66+
'sphinx', 'babel', 'docutils', 'alabaster', 'snowballstemmer',
67+
'sphinxcontrib',
68+
# Interactive console / autocompletion (napari console, not needed)
69+
'jedi', 'parso',
70+
# Plotly / kaleido (not used by the app)
71+
'plotly', 'kaleido',
72+
# HuggingFace ecosystem (transitive, not used)
73+
'hf_xet', 'huggingface_hub',
74+
# PyTorch extras not needed for inference
75+
'pytorch_lightning', 'lightning',
76+
# Optical flow / tracking (optional dep, not in standalone app)
77+
'ptlflow',
78+
# Jupyter / notebook (dev only)
79+
'notebook', 'jupyterlab', 'jupyter_client', 'jupyter_core',
80+
'jupyter_server', 'nbconvert', 'nbformat', 'nbclient',
81+
'ipykernel', 'ipywidgets',
82+
# Testing
83+
'pytest', 'hypothesis',
84+
# Other unused transitive deps
85+
'tkinter', '_tkinter',
86+
'timm',
87+
'h5py',
88+
]
89+
5990
a = Analysis(
6091
['sarcasm_app/__main__.py'],
6192
pathex=['.'],
6293
binaries=[],
63-
datas=napari_data + vispy_data + model_data,
94+
datas=(
95+
napari_data
96+
+ napari_builtins_data
97+
+ vispy_data
98+
+ rfc3987_data
99+
+ lark_data
100+
+ model_data
101+
),
64102
hiddenimports=[
65103
'napari',
66104
'napari._qt',
@@ -73,7 +111,7 @@ a = Analysis(
73111
hookspath=[],
74112
hooksconfig={},
75113
runtime_hooks=[],
76-
excludes=[],
114+
excludes=excludes,
77115
noarchive=False,
78116
optimize=0,
79117
)
@@ -83,13 +121,13 @@ pyz = PYZ(a.pure)
83121
exe = EXE(
84122
pyz,
85123
a.scripts,
86-
[], # Empty - no binaries in exe
87-
exclude_binaries=True, # Critical for ONEDIR
124+
[], # Empty - no binaries in exe
125+
exclude_binaries=True, # Critical for ONEDIR
88126
name=appname,
89127
debug=False,
90128
bootloader_ignore_signals=False,
91129
strip=False,
92-
upx=False, # ← Disabled for compatibility
130+
upx=False,
93131
upx_exclude=[],
94132
runtime_tmpdir=None,
95133
console=False,
@@ -101,10 +139,21 @@ exe = EXE(
101139
icon='sarcasm_app/icons/sarcasm.ico',
102140
)
103141

104-
# Platform-specific configurations
142+
# COLLECT is needed on all platforms (gathers binaries + data alongside the EXE)
143+
coll = COLLECT(
144+
exe,
145+
a.binaries,
146+
a.zipfiles,
147+
a.datas,
148+
strip=False,
149+
upx=False,
150+
name=appname,
151+
)
152+
153+
# macOS: wrap in a .app bundle
105154
if sys.platform == 'darwin':
106155
app = BUNDLE(
107-
exe,
156+
coll,
108157
name=f'{appname}.app',
109158
icon='sarcasm_app/icons/sarcasm.icns',
110159
bundle_identifier='de.example.sarcasm',
@@ -117,14 +166,3 @@ if sys.platform == 'darwin':
117166
'LSUIElement': 'False',
118167
}
119168
)
120-
else:
121-
# Windows/Linux ONEDIR configuration
122-
coll = COLLECT(
123-
exe,
124-
a.binaries,
125-
a.zipfiles,
126-
a.datas,
127-
strip=False,
128-
upx=False,
129-
name=appname,
130-
)

0 commit comments

Comments
 (0)