Skip to content

Commit 24dc55e

Browse files
rohan-pandeyyrahulharpal1603
authored andcommitted
chore(ci-cd): switch PyInstaller workflow to spec file
1 parent 0b1a50a commit 24dc55e

2 files changed

Lines changed: 65 additions & 24 deletions

File tree

.github/workflows/build-and-release.yml

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,7 @@ jobs:
3232
- name: Build executable with PyInstaller
3333
run: |
3434
cd backend
35-
pyinstaller main.py --name PictoPy_Server --onedir --distpath dist
36-
37-
- name: Copy app folder
38-
run: |
39-
cd backend
40-
mkdir dist/PictoPy_Server/images
41-
robocopy app dist\PictoPy_Server\app /e
42-
if ($LASTEXITCODE -le 1) { exit 0 }
35+
pyinstaller PictoPy.spec
4336
4437
- name: Create ZIP package
4538
run: |
@@ -74,14 +67,7 @@ jobs:
7467
- name: Build executable with PyInstaller
7568
run: |
7669
cd backend
77-
pyinstaller main.py --name PictoPy_Server --onedir --distpath dist
78-
79-
- name: Copy app folder
80-
run: |
81-
cd backend
82-
mkdir -p dist/PictoPy_Server/images
83-
mkdir -p dist/PictoPy_Server/app
84-
cp -r app/* dist/PictoPy_Server/app/
70+
pyinstaller PictoPy.spec
8571
8672
- name: Create ZIP package
8773
run: |
@@ -114,14 +100,7 @@ jobs:
114100
- name: Build executable with PyInstaller
115101
run: |
116102
cd backend
117-
pyinstaller main.py --name PictoPy_Server --onedir --distpath dist
118-
119-
- name: Copy app folder
120-
run: |
121-
cd backend
122-
mkdir -p dist/PictoPy_Server/images
123-
mkdir -p dist/PictoPy_Server/app
124-
cp -r app/* dist/PictoPy_Server/app/
103+
pyinstaller PictoPy.spec
125104
126105
- name: Create ZIP package
127106
run: |

backend/PictoPy.spec

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
import os
3+
4+
a = Analysis(
5+
['main.py'],
6+
pathex=[],
7+
binaries=[],
8+
datas=[('app', 'app')],
9+
hiddenimports=['uvicorn.logging', 'uvicorn.loops', 'uvicorn.loops.auto', 'uvicorn.protocols', 'uvicorn.protocols.http', 'uvicorn.protocols.http.auto', 'uvicorn.protocols.websockets', 'uvicorn.protocols.websockets.auto', 'uvicorn.lifespan', 'uvicorn.lifespan.on', 'uvicorn.lifespan.off', 'psutil', 'platformdirs', 'httpx'],
10+
hookspath=[],
11+
hooksconfig={},
12+
runtime_hooks=[],
13+
excludes=[],
14+
win_no_prefer_redirects=False,
15+
win_private_assemblies=False,
16+
noarchive=False,
17+
)
18+
19+
# Filter out models from the build in case any linger in the development directory
20+
# We ensure the distribution bundle remains lightweight.
21+
def exclude_models(datas):
22+
filtered_datas = []
23+
for data in datas:
24+
# data is a tuple (dest, source, type)
25+
dest = data[0].replace(os.sep, '/')
26+
if 'app/models/' in dest and dest.endswith('.onnx'):
27+
continue
28+
filtered_datas.append(data)
29+
return filtered_datas
30+
31+
a.datas = exclude_models(a.datas)
32+
33+
pyz = PYZ(a.pure, a.zipped_data)
34+
35+
exe = EXE(
36+
pyz,
37+
a.scripts,
38+
[],
39+
exclude_binaries=True,
40+
name='PictoPy_Server',
41+
debug=False,
42+
bootloader_ignore_signals=False,
43+
strip=False,
44+
upx=False, # disabled until DLL compatibility is validated
45+
console=True,
46+
disable_windowed_traceback=False,
47+
argv_emulation=False,
48+
target_arch=None,
49+
codesign_identity=None,
50+
entitlements_file=None,
51+
)
52+
53+
coll = COLLECT(
54+
exe,
55+
a.binaries,
56+
a.zipfiles,
57+
a.datas,
58+
strip=False,
59+
upx=False, # disabled until DLL compatibility is validated
60+
upx_exclude=[],
61+
name='PictoPy_Server',
62+
)

0 commit comments

Comments
 (0)