ci: extract pip bootstrapping into compilation/ensure_pip.py to fix yaml scalar parsing
CI Test Suite / Run Component Tests & Pipeline Verification (push) Failing after 1m29s
CI Test Suite / Run Component Tests & Pipeline Verification (push) Failing after 1m29s
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import sys
|
||||
import subprocess
|
||||
import urllib.request
|
||||
|
||||
def main():
|
||||
try:
|
||||
import pip # noqa: F401
|
||||
print("[+] pip is already installed.")
|
||||
return
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
try:
|
||||
import ensurepip
|
||||
ensurepip.bootstrap()
|
||||
print("[+] Successfully bootstrapped pip via ensurepip.")
|
||||
return
|
||||
except Exception as e:
|
||||
print(f"[*] ensurepip bootstrap skipped ({e}), downloading get-pip.py...")
|
||||
|
||||
ver = f"{sys.version_info.major}.{sys.version_info.minor}"
|
||||
url = f"https://bootstrap.pypa.io/pip/{ver}/get-pip.py" if sys.version_info < (3, 10) else "https://bootstrap.pypa.io/get-pip.py"
|
||||
dest = "/tmp/get-pip.py" if sys.platform != "win32" else "get-pip.py"
|
||||
|
||||
print(f"[*] Downloading get-pip.py from {url} for Python {ver}...")
|
||||
try:
|
||||
urllib.request.urlretrieve(url, dest)
|
||||
cmd = [sys.executable, dest]
|
||||
if sys.version_info >= (3, 11):
|
||||
cmd.append("--break-system-packages")
|
||||
res = subprocess.run(cmd)
|
||||
if res.returncode == 0:
|
||||
print("[+] Successfully installed pip via get-pip.py")
|
||||
else:
|
||||
# Retry without break-system-packages in case old pip version rejected it
|
||||
subprocess.run([sys.executable, dest])
|
||||
except Exception as ex:
|
||||
print(f"[!] Warning during pip bootstrap: {ex}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user