-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_exe_py38.ps1
More file actions
126 lines (113 loc) · 3.98 KB
/
Copy pathbuild_exe_py38.ps1
File metadata and controls
126 lines (113 loc) · 3.98 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
$ErrorActionPreference = "Stop"
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$EnvName = "checksim_py38"
$AppName = -join (0x6807, 0x4E66, 0x6587, 0x4EF6, 0x67E5, 0x91CD, 0x5DE5, 0x5177 | ForEach-Object { [char]$_ })
$BundleOcr = if ($env:CHECKSIM_BUNDLE_OCR) { $env:CHECKSIM_BUNDLE_OCR } else { "1" }
$OcrModelDir = if ($env:CHECKSIM_OCR_MODEL_DIR) { $env:CHECKSIM_OCR_MODEL_DIR } else { "packaging\ocr_models" }
function Invoke-BuildPython {
param(
[Parameter(Mandatory = $true)]
[string[]]$Arguments
)
if ($env:CHECKSIM_PYTHON) {
$Python = Get-Command $env:CHECKSIM_PYTHON -ErrorAction SilentlyContinue
if ($Python) {
& $Python.Source @Arguments
return
}
Write-Host "CHECKSIM_PYTHON is set but not found: $env:CHECKSIM_PYTHON" -ForegroundColor Yellow
}
$Conda = Get-Command conda -ErrorAction SilentlyContinue
if ($Conda) {
& $Conda.Source run -n $EnvName python @Arguments
return
}
Write-Host "Python runtime not found." -ForegroundColor Yellow
Write-Host "Set CHECKSIM_PYTHON to a Python 3.8 executable, or create the default conda environment:" -ForegroundColor Yellow
Write-Host " conda create -n $EnvName python=3.8 -y"
exit 1
}
function Invoke-BuildPythonText {
param(
[Parameter(Mandatory = $true)]
[string[]]$Arguments
)
$Output = $null
if ($env:CHECKSIM_PYTHON) {
$Python = Get-Command $env:CHECKSIM_PYTHON -ErrorAction SilentlyContinue
if ($Python) {
$Output = & $Python.Source @Arguments
}
}
else {
$Conda = Get-Command conda -ErrorAction SilentlyContinue
if ($Conda) {
$Output = & $Conda.Source run -n $EnvName python @Arguments
}
}
if ($null -eq $Output) {
return ""
}
return ($Output | Where-Object { "$_".Trim() } | Select-Object -Last 1)
}
Invoke-BuildPython @("-m", "pip", "install", "-r", "requirements-win38.txt")
if ($BundleOcr -eq "1") {
Invoke-BuildPython @("scripts\cache_ppocr_models.py", "--output", $OcrModelDir)
}
Remove-Item -Recurse -Force build, dist -ErrorAction SilentlyContinue
$PyInstallerArgs = @(
"-m", "PyInstaller",
"--noconfirm",
"--clean",
"--onefile",
"--windowed",
"--name", $AppName,
"--collect-submodules", "docx",
"--collect-submodules", "PIL",
"--collect-submodules", "pypdf"
)
if ($BundleOcr -eq "1") {
$PyInstallerArgs += @(
"--collect-all", "paddleocr",
"--collect-all", "paddlex",
"--collect-all", "onnxruntime",
"--collect-all", "cv2",
"--collect-all", "pypdfium2",
"--collect-all", "imagesize",
"--collect-all", "pyclipper",
"--collect-all", "bidi",
"--collect-all", "shapely",
"--copy-metadata", "imagesize",
"--copy-metadata", "opencv-contrib-python",
"--copy-metadata", "pyclipper",
"--copy-metadata", "pypdfium2",
"--copy-metadata", "python-bidi",
"--copy-metadata", "shapely",
"--add-data", "$OcrModelDir;ocr_models"
)
$ShapelyGeosDll = Invoke-BuildPythonText @("-c", "from pathlib import Path; import shapely; root = Path(shapely.__file__).resolve().parent.parent / 'shapely.libs'; dlls = sorted(root.glob('geos_c*.dll')); print(dlls[0] if dlls else '')")
if ($ShapelyGeosDll) {
$PyInstallerArgs += @("--add-binary", "$ShapelyGeosDll;shapely.libs")
}
}
$PyInstallerArgs += @(
"--hidden-import", "win32com.client",
"--hidden-import", "pythoncom",
"--hidden-import", "pywintypes",
"run_app.py"
)
$BuildPatchPath = (Resolve-Path "packaging\build_sitecustomize").Path
$PreviousPythonPath = $env:PYTHONPATH
if ($PreviousPythonPath) {
$env:PYTHONPATH = "$BuildPatchPath;$PreviousPythonPath"
}
else {
$env:PYTHONPATH = $BuildPatchPath
}
try {
Invoke-BuildPython $PyInstallerArgs
}
finally {
$env:PYTHONPATH = $PreviousPythonPath
}
Write-Host "Build complete: dist\$AppName.exe" -ForegroundColor Green