Skip to content

Commit b34ab16

Browse files
committed
fix(build): use custom .spec file to properly import modules
1 parent 089c4f5 commit b34ab16

5 files changed

Lines changed: 109 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ __pycache__/
44
requirements.txt
55
.DS_Store
66
build/
7-
dist/
8-
main.spec
7+
dist/

Justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ set-up-project: install-python create-virtual-environment sync-dependencies
3131
sync-dependencies:
3232
uv sync --all-packages --all-groups --all-extras
3333

34-
build-package:
35-
uv run pyinstaller src/lwPython/main.py
34+
build-package: clean-generated-files
35+
uv run pyinstaller main.spec
3636

3737
run-tests:
3838
uv run pytest -vv

main.spec

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
from pathlib import Path
4+
5+
from PyInstaller import compat
6+
from PyInstaller.utils.hooks import collect_data_files, copy_metadata
7+
8+
9+
Path('build/main').mkdir(parents=True, exist_ok=True)
10+
Path('dist').mkdir(parents=True, exist_ok=True)
11+
12+
13+
hiddenimports = [
14+
'docling.backend.docling_parse_v2_backend',
15+
'docling.backend.docling_parse_v4_backend',
16+
'docling.backend.pypdfium2_backend',
17+
'docling.models.plugins',
18+
'docling.models.plugins.defaults',
19+
'markitdown.__main__',
20+
'textractor.cli',
21+
'textractor.cli.cli',
22+
]
23+
24+
datas = (
25+
collect_data_files('docling')
26+
+ collect_data_files('docling_parse')
27+
+ collect_data_files('magika')
28+
+ copy_metadata('docling')
29+
+ copy_metadata('docling-core')
30+
+ copy_metadata('docling-ibm-models')
31+
+ copy_metadata('docling-parse')
32+
+ copy_metadata('markitdown')
33+
)
34+
35+
excludes = [
36+
'pytest',
37+
'_pytest',
38+
'tensorflow',
39+
'tensorboard',
40+
'torch.utils.tensorboard',
41+
'torchaudio',
42+
'speech_recognition',
43+
]
44+
45+
if compat.is_linux:
46+
excludes += [
47+
'nvidia',
48+
'nvidia.cublas',
49+
'nvidia.cuda_cupti',
50+
'nvidia.cuda_nvrtc',
51+
'nvidia.cuda_runtime',
52+
'nvidia.cudnn',
53+
'nvidia.cufft',
54+
'nvidia.curand',
55+
'nvidia.cusolver',
56+
'nvidia.cusparse',
57+
'nvidia.cusparselt',
58+
'nvidia.nccl',
59+
'nvidia.nvjitlink',
60+
'nvidia.nvtx',
61+
]
62+
63+
64+
a = Analysis(
65+
['src/lwPython/main.py'],
66+
pathex=['src'],
67+
binaries=[],
68+
datas=datas,
69+
hiddenimports=hiddenimports,
70+
hookspath=[],
71+
hooksconfig={},
72+
runtime_hooks=[],
73+
excludes=excludes,
74+
noarchive=False,
75+
optimize=0,
76+
)
77+
pyz = PYZ(a.pure)
78+
79+
exe = EXE(
80+
pyz,
81+
a.scripts,
82+
[],
83+
exclude_binaries=True,
84+
name='main',
85+
debug=False,
86+
bootloader_ignore_signals=False,
87+
strip=True,
88+
upx=True,
89+
console=True,
90+
disable_windowed_traceback=False,
91+
argv_emulation=False,
92+
target_arch=None,
93+
codesign_identity=None,
94+
entitlements_file=None,
95+
)
96+
coll = COLLECT(
97+
exe,
98+
a.binaries,
99+
a.datas,
100+
strip=True,
101+
upx=True,
102+
upx_exclude=[],
103+
name='main',
104+
)

scripts/clean.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
from shutil import rmtree
1010
from from_root import from_root
1111

12-
file = from_root("main.spec")
13-
file.unlink(missing_ok=True)
14-
1512
for name in ("dist", "build"):
1613
directory = from_root(name)
1714
rmtree(directory, ignore_errors=True)

src/lwPython/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import click
22
import json
3+
import multiprocessing
34
from lwPython._utils import *
45

56
@click.group()
@@ -45,4 +46,5 @@ def markitdown_file_to_markdown(input, output):
4546
cli.add_command(textract_to_markdown)
4647

4748
if __name__ == '__main__':
49+
multiprocessing.freeze_support()
4850
cli()

0 commit comments

Comments
 (0)