-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-python.ps1
More file actions
79 lines (64 loc) · 2.32 KB
/
Copy pathbuild-python.ps1
File metadata and controls
79 lines (64 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
$ErrorActionPreference = 'Stop'
$projectRoot = Split-Path -Parent $PSScriptRoot
$pythonExe = Join-Path $projectRoot '.venv\Scripts\python.exe'
if (-not (Test-Path $pythonExe)) {
throw "Python virtualenv not found in .venv. Run 'python -m venv .venv' and install dependencies before building."
}
$pyInstallerCheck = & $pythonExe -c "import importlib.util, sys; sys.exit(0 if importlib.util.find_spec('PyInstaller') else 1)"
if ($LASTEXITCODE -ne 0) {
throw "PyInstaller not found in .venv. Run '.\\.venv\\Scripts\\python.exe -m pip install pyinstaller' before building."
}
$distPath = Join-Path $projectRoot 'build\python-dist'
$workPath = Join-Path $projectRoot 'build\pyinstaller\work'
$specPath = Join-Path $projectRoot 'build\pyinstaller\spec'
if (Test-Path $distPath) {
Remove-Item $distPath -Recurse -Force
}
if (Test-Path (Split-Path $workPath -Parent)) {
Remove-Item (Split-Path $workPath -Parent) -Recurse -Force
}
New-Item -ItemType Directory -Path $distPath | Out-Null
New-Item -ItemType Directory -Path $workPath | Out-Null
New-Item -ItemType Directory -Path $specPath | Out-Null
$commonArgs = @(
'-m', 'PyInstaller',
'--noconfirm',
'--clean',
'--distpath', $distPath,
'--workpath', $workPath,
'--specpath', $specPath,
'--additional-hooks-dir', (Join-Path $PSScriptRoot 'pyinstaller-hooks')
)
$cudaCollectArgs = @()
$optionalCollectModules = @(
'nvidia.cublas',
'nvidia.cudnn',
'nvidia.cuda_runtime'
)
foreach ($module in $optionalCollectModules) {
& $pythonExe -c "import importlib.util, sys; sys.exit(0 if importlib.util.find_spec('$module') else 1)"
if ($LASTEXITCODE -eq 0) {
$cudaCollectArgs += @('--collect-all', $module)
}
}
& $pythonExe @commonArgs @cudaCollectArgs `
'--name' 'dictation_service' `
'--hidden-import' 'sounddevice' `
'--collect-all' 'faster_whisper' `
'--collect-all' 'ctranslate2' `
'--collect-all' 'tokenizers' `
'--collect-all' 'huggingface_hub' `
'--collect-all' 'sounddevice' `
'--collect-binaries' 'sounddevice' `
'python\dictation_service.py'
if ($LASTEXITCODE -ne 0) {
throw 'Failed to build dictation_service.exe'
}
& $pythonExe @commonArgs `
'--name' 'hotkey_listener' `
'--collect-submodules' 'pynput' `
'python\hotkey_listener.py'
if ($LASTEXITCODE -ne 0) {
throw 'Failed to build hotkey_listener.exe'
}
Write-Host "Python workers built in $distPath"