Skip to content

Commit eb6218e

Browse files
committed
Move ensurepip back to finalize
1 parent 6097847 commit eb6218e

File tree

4 files changed

+35
-36
lines changed

4 files changed

+35
-36
lines changed

relenv/build/common.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -358,40 +358,50 @@ def build_sqlite(env, dirs, logfp):
358358
runcmd(["make", "install"], env=env, stderr=logfp, stdout=logfp)
359359

360360

361-
def update_ensurepip(source_dir):
361+
def update_ensurepip(lib_dir):
362362
"""
363363
Update bundled dependencies for ensurepip (pip & setuptools).
364364
"""
365365
# ensurepip bundle location
366-
bundle_dir = source_dir / "Lib" / "ensurepip" / "_bundled"
366+
bundle_dir = lib_dir / "ensurepip" / "_bundled"
367367

368368
# Make sure the destination directory exists
369369
bundle_dir.mkdir(parents=True, exist_ok=True)
370370

371-
# Remove existing whl files
371+
# Detect existing whl files and delete them. Later versions of python don't
372+
# include setuptools. We only want to update whl files that are a part of
373+
# python
374+
update_pip = False
375+
update_setuptools = False
372376
for file in bundle_dir.glob("*.whl"):
373-
if file.is_file():
377+
if "pip" in file:
378+
update_pip = True
379+
file.unlink()
380+
if "setuptools" in file:
381+
update_setuptools = True
374382
file.unlink()
375383

376384
# Download whl files
377385
# pip
378-
pip_version = "25.2"
379-
whl = f"pip-{pip_version}-py3-none-any.whl"
380-
whl_path = "b7/3f/945ef7ab14dc4f9d7f40288d2df998d1837ee0888ec3659c813487572faa"
381-
url = f"https://files.pythonhosted.org/packages/{whl_path}/{whl}"
382-
download_url(url=url, dest=bundle_dir)
383-
assert (bundle_dir / whl).exists()
386+
if update_pip:
387+
pip_version = "25.2"
388+
whl = f"pip-{pip_version}-py3-none-any.whl"
389+
whl_path = "b7/3f/945ef7ab14dc4f9d7f40288d2df998d1837ee0888ec3659c813487572faa"
390+
url = f"https://files.pythonhosted.org/packages/{whl_path}/{whl}"
391+
download_url(url=url, dest=bundle_dir)
392+
assert (bundle_dir / whl).exists()
384393

385394
# setuptools
386-
setuptools_version = "80.9.0"
387-
whl = f"setuptools-{setuptools_version}-py3-none-any.whl"
388-
whl_path = "a3/dc/17031897dae0efacfea57dfd3a82fdd2a2aeb58e0ff71b77b87e44edc772"
389-
url = f"https://files.pythonhosted.org/packages/{whl_path}/{whl}"
390-
download_url(url=url, dest=bundle_dir)
391-
assert (bundle_dir / whl).exists()
395+
if update_setuptools:
396+
setuptools_version = "80.9.0"
397+
whl = f"setuptools-{setuptools_version}-py3-none-any.whl"
398+
whl_path = "a3/dc/17031897dae0efacfea57dfd3a82fdd2a2aeb58e0ff71b77b87e44edc772"
399+
url = f"https://files.pythonhosted.org/packages/{whl_path}/{whl}"
400+
download_url(url=url, dest=bundle_dir)
401+
assert (bundle_dir / whl).exists()
392402

393403
# Update __init__.py
394-
init_file = source_dir / "Lib" / "ensurepip" / "__init__.py"
404+
init_file = lib_dir / "ensurepip" / "__init__.py"
395405
# pip
396406
old = "^_PIP_VERSION.*"
397407
new = f'_PIP_VERSION = "{pip_version}"'
@@ -425,7 +435,7 @@ def patch_file(path, old, new):
425435
new_content = ""
426436
for line in content.splitlines():
427437
line = re.sub(old, new, line)
428-
new_content += line + os.linesep
438+
new_content += line + "\n"
429439
with open(path, "w") as fp:
430440
fp.write(new_content)
431441

@@ -1521,6 +1531,9 @@ def finalize(env, dirs, logfp):
15211531
# Install relenv-sysconfigdata module
15221532
libdir = pathlib.Path(dirs.prefix) / "lib"
15231533

1534+
# update ensurepip
1535+
update_ensurepip(libdir)
1536+
15241537
def find_pythonlib(libdir):
15251538
for root, dirs, files in os.walk(libdir):
15261539
for _ in dirs:

relenv/build/darwin.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
import io
77

88
from ..common import arches, DARWIN, MACOS_DEVELOPMENT_TARGET
9-
from .common import (
10-
runcmd,
11-
finalize,
12-
build_openssl,
13-
build_sqlite,
14-
builds,
15-
update_ensurepip,
16-
)
9+
from .common import runcmd, finalize, build_openssl, build_sqlite, builds
1710

1811
ARCHES = arches[DARWIN]
1912

@@ -52,9 +45,6 @@ def build_python(env, dirs, logfp):
5245
:param logfp: A handle for the log file
5346
:type logfp: file
5447
"""
55-
# update ensurepip
56-
update_ensurepip(dirs.prefix)
57-
5848
env["LDFLAGS"] = "-Wl,-rpath,{prefix}/lib {ldflags}".format(
5949
prefix=dirs.prefix, ldflags=env["LDFLAGS"]
6050
)

relenv/build/linux.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,6 @@ def build_python(env, dirs, logfp):
353353
:param logfp: A handle for the log file
354354
:type logfp: file
355355
"""
356-
# update ensurepip
357-
update_ensurepip(dirs.prefix)
358-
359356
ldflagopt = f"-Wl,--rpath={dirs.prefix}/lib"
360357
if ldflagopt not in env["LDFLAGS"]:
361358
env["LDFLAGS"] = f"{ldflagopt} {env['LDFLAGS']}"

relenv/build/windows.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ def build_python(env, dirs, logfp):
8383
new = 'get_externals.bat --organization saltstack"'
8484
patch_file(dirs.source / "PCbuild" / "build.bat", old=old, new=new)
8585

86-
# update ensurepip
87-
update_ensurepip(dirs.source)
88-
8986
arch_to_plat = {
9087
"amd64": "x64",
9188
"x86": "win32",
@@ -197,9 +194,11 @@ def finalize(env, dirs, logfp):
197194
"""
198195
# Lay down site customize
199196
sitepackages = dirs.prefix / "Lib" / "site-packages"
200-
201197
install_runtime(sitepackages)
202198

199+
# update ensurepip
200+
update_ensurepip(dirs.prefix / "Lib")
201+
203202
# Install pip
204203
python = dirs.prefix / "Scripts" / "python.exe"
205204
runcmd([str(python), "-m", "ensurepip"], env=env, stderr=logfp, stdout=logfp)

0 commit comments

Comments
 (0)