Skip to content

Commit 1a64db3

Browse files
Consolidate Python module installation
1 parent 61fd0b1 commit 1a64db3

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

utils/build.ps1

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,6 @@ $Components = @{
212212
URL = "https://github.com/lexxmark/winflexbison/releases/download/v$WinFlexBisonVersion/win_flex_bison-$WinFlexBisonVersion.zip"
213213
Hash = "8D324B62BE33604B2C45AD1DD34AB93D722534448F55A16CA7292DE32B6AC135"
214214
}
215-
GnuWin32Make = @{
216-
URL = "https://downloads.sourceforge.net/project/ezwinports/make-4.4.1-without-guile-w32-bin.zip"
217-
Hash = "fb66a02b530f7466f6222ce53c0b602c5288e601547a034e4156a512dd895ee7"
218-
}
219215
packaging = @{
220216
URL = "https://files.pythonhosted.org/packages/08/aa/cc0199a5f0ad350994d660967a8efb233fe0416e4639146c089643407ce6/packaging-24.1-py3-none-any.whl"
221217
Hash = "5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124"
@@ -226,14 +222,6 @@ $Components = @{
226222
URL = "https://files.pythonhosted.org/packages/ff/ae/f19306b5a221f6a436d8f2238d5b80925004093fa3edea59835b514d9057/setuptools-75.1.0-py3-none-any.whl"
227223
Hash = "35ab7fd3bcd95e6b7fd704e4a1539513edad446c097797f2985e0e4b960772f2"
228224
}
229-
psutil = @{
230-
URL = "https://files.pythonhosted.org/packages/11/91/87fa6f060e649b1e1a7b19a4f5869709fbf750b7c8c262ee776ec32f3028/psutil-6.1.0-cp37-abi3-win_amd64.whl"
231-
Hash = "a8fb3752b491d246034fa4d279ff076501588ce8cbcdbb62c32fd7a377d996be"
232-
}
233-
unittest2 = @{
234-
URL = "https://files.pythonhosted.org/packages/72/20/7f0f433060a962200b7272b8c12ba90ef5b903e218174301d0abfd523813/unittest2-1.1.0-py2.py3-none-any.whl"
235-
Hash = "13f77d0875db6d9b435e1d4f41e74ad4cc2eb6e1d5c824996092b3430f088bb8"
236-
}
237225
}
238226

239227
if ($PinnedBuild -eq "") {
@@ -795,37 +783,39 @@ function Fetch-Dependencies {
795783
}
796784
}
797785

798-
function Ensure-PythonModules($Python) {
799-
# First ensure pip is installed, else bootstrap it
800-
try {
801-
Invoke-Program -OutNull $Python -m pip *> $null
802-
} catch {
803-
Write-Output "Installing pip ..."
804-
Invoke-Program -OutNull $Python '-I' -m ensurepip -U --default-pip
805-
}
806-
# 'packaging' is required for building LLVM 18+
807-
try {
808-
Invoke-Program -OutNull $Python -c 'import packaging' *> $null
809-
} catch {
810-
DownloadAndVerify "packaging" "$BinaryCache\python\packaging-24.1-py3-none-any.whl"
811-
Write-Output "Installing 'packaging-24.1-py3-none-any.whl' ..."
812-
Invoke-Program -OutNull $Python '-I' -m pip install "$BinaryCache\python\packaging-24.1-py3-none-any.whl" --disable-pip-version-check
786+
Download-Python $HostArchName
787+
if ($IsCrossCompiling) {
788+
Download-Python $BuildArchName
789+
}
790+
791+
# Ensure pip is installed, else bootstrap it
792+
try {
793+
Invoke-Program -OutNull $Python -m pip *> $null
794+
} catch {
795+
Write-Output "Installing pip ..."
796+
Invoke-Program -OutNull $Python '-I' -m ensurepip -U --default-pip
797+
}
798+
799+
function Ensure-PythonModule($Name) {
800+
$Python = $(Get-PythonExecutable)
801+
$Info = $Components[$Name]
802+
if ($Info -eq $null) {
803+
throw "Unknown component requested"
813804
}
805+
$CanonicalName = [IO.Path]::GetFileNameWithoutExtension($Info.URL)
806+
814807
try {
815-
Invoke-Program -OutNull $Python -c 'import distutils' *> $null
808+
Invoke-Program -OutNull $Python -c 'import $name' *> $null
816809
} catch {
817-
DownloadAndVerify "distutils" "$BinaryCache\python\setuptools-75.1.0-py3-none-any.whl"
818-
Write-Output "Installing 'setuptools-75.1.0-py3-none-any.whl' ..."
819-
Invoke-Program -OutNull $Python '-I' -m pip install "$BinaryCache\python\setuptools-75.1.0-py3-none-any.whl" --disable-pip-version-check
810+
DownloadAndVerify $Name "$BinaryCache\python\$CanonicalName.whl"
811+
Write-Output "Installing '$CanonicalName.whl' ..."
812+
Invoke-Program -OutNull $Python '-I' -m pip install "$BinaryCache\python\$CanonicalName.whl" --disable-pip-version-check
820813
}
821814
}
822815

823-
Download-Python $HostArchName
824-
if ($IsCrossCompiling) {
825-
Download-Python $BuildArchName
826-
}
827816
# Ensure Python modules that are required as host build tools
828-
Ensure-PythonModules "$(Get-PythonExecutable)"
817+
Ensure-PythonModule "packaging"
818+
Ensure-PythonModule "distutils"
829819

830820
if ($Android) {
831821
# Only a specific NDK version is supported right now.

0 commit comments

Comments
 (0)