Skip to content

Commit eb9e206

Browse files
committed
Move Windows Python packaging to script
Replace the large inline PowerShell packaging block in .github/workflows/build-python.yml with a single invocation of windows/package-for-dart.ps1. Add the new packaging script (windows/package-for-dart.ps1) that encapsulates downloading, building and packaging CPython and uses a new exclude list (windows/python-windows-dart.exclude) to prune files. Remove obsolete files windows/exclude.txt and windows/unattend.xml. This centralizes packaging logic, simplifies the workflow file, and improves maintainability.
1 parent 73f3a5c commit eb9e206

5 files changed

Lines changed: 159 additions & 162 deletions

File tree

.github/workflows/build-python.yml

Lines changed: 1 addition & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -107,142 +107,7 @@ jobs:
107107
- name: Build CPython from sources and package for Dart
108108
shell: pwsh
109109
run: |
110-
$ErrorActionPreference = "Stop"
111-
112-
$pyVer = "${{ env.PYTHON_VERSION }}"
113-
$pyShort = "${{ env.PYTHON_VERSION_SHORT }}"
114-
$workspace = $env:GITHUB_WORKSPACE
115-
116-
$srcRoot = Join-Path $workspace "windows\build"
117-
$srcArchive = Join-Path $srcRoot "Python-$pyVer.tgz"
118-
$srcDir = Join-Path $srcRoot "Python-$pyVer"
119-
$pcbuildDir = Join-Path $srcDir "PCbuild\amd64"
120-
121-
$packageRoot = Join-Path $workspace "windows\python-windows-for-dart-$pyShort"
122-
$zipPath = Join-Path $workspace "windows\python-windows-for-dart-$pyShort.zip"
123-
124-
# Cleanup/include lists kept in one place for visibility and maintenance.
125-
$pruneLibDirs = @("test", "idlelib", "tkinter", "turtledemo", "ensurepip", "pydoc_data", "lib2to3")
126-
$pruneDllPatterns = @("_test*.pyd", "_ctypes_test*.pyd", "_tkinter*.pyd", "xxlimited*.pyd")
127-
$pruneDllFiles = @("tcl86t.dll", "tk86t.dll", "zlib1.dll", "pyshellext.dll", "pyshellext_d.dll")
128-
$keepImportLibs = @("python3.lib", "python3_d.lib", "python312.lib", "python312_d.lib")
129-
$pruneSitePackagesPatterns = @("pip*", "setuptools*", "wheel*")
130-
131-
New-Item -ItemType Directory -Force -Path $srcRoot | Out-Null
132-
133-
Write-Host "Downloading CPython source $pyVer"
134-
Invoke-WebRequest -Uri "https://www.python.org/ftp/python/$pyVer/Python-$pyVer.tgz" -OutFile $srcArchive
135-
tar -xf $srcArchive -C $srcRoot
136-
137-
Push-Location $srcDir
138-
cmd /c "PCbuild\build.bat -e -p x64 -c Release"
139-
cmd /c "PCbuild\build.bat -e -p x64 -c Debug"
140-
Pop-Location
141-
142-
Remove-Item -Recurse -Force $packageRoot -ErrorAction SilentlyContinue
143-
New-Item -ItemType Directory -Force -Path "$packageRoot\DLLs", "$packageRoot\include", "$packageRoot\Lib", "$packageRoot\libs", "$packageRoot\Scripts" | Out-Null
144-
145-
Copy-Item -Path "$srcDir\Include\*" -Destination "$packageRoot\include" -Recurse -Force
146-
Copy-Item -Path "$srcDir\Lib\*" -Destination "$packageRoot\Lib" -Recurse -Force
147-
148-
# Root binaries and symbols.
149-
foreach ($name in @("LICENSE.txt", "NEWS.txt")) {
150-
$src = Join-Path $srcDir $name
151-
if (Test-Path $src) {
152-
Copy-Item -Path $src -Destination $packageRoot -Force
153-
}
154-
}
155-
156-
$rootFiles = @(
157-
"python3.dll",
158-
"python3_d.dll",
159-
"python312.dll",
160-
"python312_d.dll",
161-
"python312_d.pdb",
162-
"python_d.pdb",
163-
"pythonw_d.pdb"
164-
)
165-
foreach ($name in $rootFiles) {
166-
$src = Join-Path $pcbuildDir $name
167-
if (Test-Path $src) {
168-
Copy-Item -Path $src -Destination $packageRoot -Force
169-
}
170-
}
171-
172-
foreach ($name in @("vcruntime140.dll", "vcruntime140_1.dll")) {
173-
$fromBuild = Join-Path $pcbuildDir $name
174-
$fromSystem = Join-Path "$env:WINDIR\System32" $name
175-
if (Test-Path $fromBuild) {
176-
Copy-Item -Path $fromBuild -Destination $packageRoot -Force
177-
} elseif (Test-Path $fromSystem) {
178-
Copy-Item -Path $fromSystem -Destination $packageRoot -Force
179-
}
180-
}
181-
182-
# Extension modules and supporting DLLs.
183-
Get-ChildItem -Path $pcbuildDir -Filter "*.pyd" -File | Copy-Item -Destination "$packageRoot\DLLs" -Force
184-
Get-ChildItem -Path $pcbuildDir -Filter "*.dll" -File |
185-
Where-Object { $_.Name -notin @("python3.dll", "python3_d.dll", "python312.dll", "python312_d.dll", "vcruntime140.dll", "vcruntime140_1.dll") } |
186-
Copy-Item -Destination "$packageRoot\DLLs" -Force
187-
Get-ChildItem -Path $pcbuildDir -Filter "*.lib" -File | Copy-Item -Destination "$packageRoot\libs" -Force
188-
189-
# Cleanup to keep package close to the original installer-based zip size/layout.
190-
foreach ($dirName in $pruneLibDirs) {
191-
$dirPath = Join-Path "$packageRoot\Lib" $dirName
192-
if (Test-Path $dirPath) {
193-
Remove-Item -Recurse -Force $dirPath
194-
}
195-
}
196-
$sitePackagesDir = Join-Path "$packageRoot\Lib" "site-packages"
197-
if (Test-Path $sitePackagesDir) {
198-
foreach ($pattern in $pruneSitePackagesPatterns) {
199-
Get-ChildItem -Path $sitePackagesDir -Filter $pattern -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force
200-
}
201-
}
202-
203-
foreach ($pattern in $pruneDllPatterns) {
204-
Get-ChildItem -Path "$packageRoot\DLLs" -Filter $pattern -File -ErrorAction SilentlyContinue | Remove-Item -Force
205-
}
206-
foreach ($name in $pruneDllFiles) {
207-
$filePath = Join-Path "$packageRoot\DLLs" $name
208-
if (Test-Path $filePath) {
209-
Remove-Item -Force $filePath
210-
}
211-
}
212-
213-
Get-ChildItem -Path "$packageRoot\libs" -Filter "*.lib" -File |
214-
Where-Object { $_.Name -notin $keepImportLibs } |
215-
Remove-Item -Force
216-
217-
# Match existing packaging behavior: bytecode-only stdlib.
218-
py -3 -m compileall -b "$packageRoot\Lib"
219-
Get-ChildItem -Path "$packageRoot\Lib" -Recurse -File -Include *.py,*.typed | Remove-Item -Force
220-
Get-ChildItem -Path "$packageRoot\Lib" -Recurse -Directory -Filter __pycache__ | Remove-Item -Recurse -Force
221-
222-
# Fail fast if required layout entries are missing.
223-
$requiredEntries = @(
224-
"$packageRoot\DLLs",
225-
"$packageRoot\include",
226-
"$packageRoot\Lib",
227-
"$packageRoot\libs",
228-
"$packageRoot\Scripts",
229-
"$packageRoot\python3.dll",
230-
"$packageRoot\python3_d.dll",
231-
"$packageRoot\python312.dll",
232-
"$packageRoot\python312_d.dll",
233-
"$packageRoot\python312_d.pdb",
234-
"$packageRoot\python_d.pdb",
235-
"$packageRoot\pythonw_d.pdb"
236-
)
237-
foreach ($entry in $requiredEntries) {
238-
if (-not (Test-Path $entry)) {
239-
ls $packageRoot
240-
throw "Missing required package entry: $entry"
241-
}
242-
}
243-
244-
Remove-Item -Force $zipPath -ErrorAction SilentlyContinue
245-
7z a $zipPath "$packageRoot\*"
110+
.\windows\package-for-dart.ps1 -PythonVersion "${{ env.PYTHON_VERSION }}" -PythonVersionShort "${{ env.PYTHON_VERSION_SHORT }}"
246111
- uses: actions/upload-artifact@v4
247112
with:
248113
name: python-windows

windows/exclude.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

windows/package-for-dart.ps1

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
param(
2+
[Parameter(Mandatory = $true)]
3+
[string]$PythonVersion,
4+
5+
[Parameter(Mandatory = $true)]
6+
[string]$PythonVersionShort
7+
)
8+
9+
Set-StrictMode -Version Latest
10+
$ErrorActionPreference = "Stop"
11+
12+
$workspace = $env:GITHUB_WORKSPACE
13+
if (-not $workspace) {
14+
$workspace = Split-Path -Parent $PSScriptRoot
15+
}
16+
17+
$srcRoot = Join-Path $workspace "windows\build"
18+
$srcArchive = Join-Path $srcRoot "Python-$PythonVersion.tgz"
19+
$srcDir = Join-Path $srcRoot "Python-$PythonVersion"
20+
$pcbuildDir = Join-Path $srcDir "PCbuild\amd64"
21+
22+
$packageRoot = Join-Path $workspace "windows\python-windows-for-dart-$PythonVersionShort"
23+
$zipPath = Join-Path $workspace "windows\python-windows-for-dart-$PythonVersionShort.zip"
24+
$excludeListPath = Join-Path $workspace "windows\python-windows-dart.exclude"
25+
$keepImportLibs = @("python3.lib", "python3_d.lib", "python312.lib", "python312_d.lib")
26+
27+
New-Item -ItemType Directory -Force -Path $srcRoot | Out-Null
28+
29+
Write-Host "Downloading CPython source $PythonVersion"
30+
Invoke-WebRequest -Uri "https://www.python.org/ftp/python/$PythonVersion/Python-$PythonVersion.tgz" -OutFile $srcArchive
31+
tar -xf $srcArchive -C $srcRoot
32+
33+
Push-Location $srcDir
34+
cmd /c "PCbuild\build.bat -e -p x64 -c Release"
35+
cmd /c "PCbuild\build.bat -e -p x64 -c Debug"
36+
Pop-Location
37+
38+
Remove-Item -Recurse -Force $packageRoot -ErrorAction SilentlyContinue
39+
New-Item -ItemType Directory -Force -Path "$packageRoot\DLLs", "$packageRoot\include", "$packageRoot\Lib", "$packageRoot\libs", "$packageRoot\Scripts" | Out-Null
40+
41+
Copy-Item -Path "$srcDir\Include\*" -Destination "$packageRoot\include" -Recurse -Force
42+
Copy-Item -Path "$srcDir\Lib\*" -Destination "$packageRoot\Lib" -Recurse -Force
43+
44+
# Root binaries and symbols.
45+
foreach ($name in @("LICENSE.txt", "NEWS.txt")) {
46+
$src = Join-Path $srcDir $name
47+
if (Test-Path $src) {
48+
Copy-Item -Path $src -Destination $packageRoot -Force
49+
}
50+
}
51+
52+
$rootFiles = @(
53+
"python3.dll",
54+
"python3_d.dll",
55+
"python312.dll",
56+
"python312_d.dll",
57+
"python312_d.pdb",
58+
"python_d.pdb",
59+
"pythonw_d.pdb"
60+
)
61+
foreach ($name in $rootFiles) {
62+
$src = Join-Path $pcbuildDir $name
63+
if (Test-Path $src) {
64+
Copy-Item -Path $src -Destination $packageRoot -Force
65+
}
66+
}
67+
68+
foreach ($name in @("vcruntime140.dll", "vcruntime140_1.dll")) {
69+
$fromBuild = Join-Path $pcbuildDir $name
70+
$fromSystem = Join-Path "$env:WINDIR\System32" $name
71+
if (Test-Path $fromBuild) {
72+
Copy-Item -Path $fromBuild -Destination $packageRoot -Force
73+
} elseif (Test-Path $fromSystem) {
74+
Copy-Item -Path $fromSystem -Destination $packageRoot -Force
75+
}
76+
}
77+
78+
# Extension modules and supporting DLLs.
79+
Get-ChildItem -Path $pcbuildDir -Filter "*.pyd" -File | Copy-Item -Destination "$packageRoot\DLLs" -Force
80+
Get-ChildItem -Path $pcbuildDir -Filter "*.dll" -File |
81+
Where-Object { $_.Name -notin @("python3.dll", "python3_d.dll", "python312.dll", "python312_d.dll", "vcruntime140.dll", "vcruntime140_1.dll") } |
82+
Copy-Item -Destination "$packageRoot\DLLs" -Force
83+
foreach ($name in $keepImportLibs) {
84+
$src = Join-Path $pcbuildDir $name
85+
if (Test-Path $src) {
86+
Copy-Item -Path $src -Destination "$packageRoot\libs" -Force
87+
}
88+
}
89+
90+
# Cleanup using exclude list.
91+
if (-not (Test-Path $excludeListPath)) {
92+
throw "Exclude list not found: $excludeListPath"
93+
}
94+
$excludePatterns = Get-Content $excludeListPath |
95+
ForEach-Object { $_.Trim() } |
96+
Where-Object { $_ -and -not $_.StartsWith("#") }
97+
foreach ($pattern in $excludePatterns) {
98+
$fullPattern = Join-Path $packageRoot $pattern
99+
$matches = Get-ChildItem -Path $fullPattern -Force -ErrorAction SilentlyContinue
100+
foreach ($item in $matches) {
101+
Remove-Item -Path $item.FullName -Recurse -Force
102+
}
103+
}
104+
105+
# Match existing packaging behavior: bytecode-only stdlib.
106+
py -3 -m compileall -b "$packageRoot\Lib"
107+
Get-ChildItem -Path "$packageRoot\Lib" -Recurse -File -Include *.py,*.typed | Remove-Item -Force
108+
Get-ChildItem -Path "$packageRoot\Lib" -Recurse -Directory -Filter __pycache__ | Remove-Item -Recurse -Force
109+
110+
# Fail fast if required layout entries are missing.
111+
$requiredEntries = @(
112+
"$packageRoot\DLLs",
113+
"$packageRoot\include",
114+
"$packageRoot\Lib",
115+
"$packageRoot\libs",
116+
"$packageRoot\Scripts",
117+
"$packageRoot\python3.dll",
118+
"$packageRoot\python3_d.dll",
119+
"$packageRoot\python312.dll",
120+
"$packageRoot\python312_d.dll",
121+
"$packageRoot\python312_d.pdb",
122+
"$packageRoot\python_d.pdb",
123+
"$packageRoot\pythonw_d.pdb"
124+
)
125+
foreach ($entry in $requiredEntries) {
126+
if (-not (Test-Path $entry)) {
127+
Get-ChildItem $packageRoot
128+
throw "Missing required package entry: $entry"
129+
}
130+
}
131+
132+
Remove-Item -Force $zipPath -ErrorAction SilentlyContinue
133+
7z a $zipPath "$packageRoot\*"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Files and directories to exclude from Windows Dart package.
2+
# Patterns are relative to package root: python-windows-for-dart-<version>/
3+
4+
# Stdlib content not needed for embedded runtime package.
5+
Lib/test
6+
Lib/idlelib
7+
Lib/tkinter
8+
Lib/turtledemo
9+
Lib/ensurepip
10+
Lib/pydoc_data
11+
Lib/lib2to3
12+
Lib/site-packages/pip*
13+
Lib/site-packages/setuptools*
14+
Lib/site-packages/wheel*
15+
16+
# Optional/test/GUI extension modules and DLLs.
17+
DLLs/_test*.pyd
18+
DLLs/_ctypes_test*.pyd
19+
DLLs/_tkinter*.pyd
20+
DLLs/xxlimited*.pyd
21+
DLLs/tcl86t.dll
22+
DLLs/tk86t.dll
23+
DLLs/zlib1.dll
24+
DLLs/pyshellext.dll
25+
DLLs/pyshellext_d.dll

windows/unattend.xml

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)