Skip to content

Commit 9785ca4

Browse files
authored
Update ensurepip bundled dependencies (#251)
* Update ensurepip bundled dependencies * set destination to directory name * Put ensurepip update in finalize step * Add some debugging to the logs * Fix pre-commit * Use \n for newline * Fix name collision with patch_file * Make sure bundle directory exists * Fix patch_file and regex for ensurepip * Build externals on Windows * Pass organization to get_externals.bat * Update ensurepip in the build step * Fix pre-commit errors * Move ensurepip back to finalize * Don't depend on forked cpython-source-deps repo * Get windows building * Install looseversion & packaging on Windows * Fix path to ensurepip on Linux/Darwin
1 parent 2262f9a commit 9785ca4

File tree

6 files changed

+353
-46
lines changed

6 files changed

+353
-46
lines changed

relenv/_resources/xz/config.h

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/* config.h for compiling liblzma (*not* the whole XZ Utils) with MSVC 2019 */
2+
3+
/* Prefix for symbols exported by tuklib_*.c files */
4+
#define TUKLIB_SYMBOL_PREFIX lzma_
5+
6+
/* How many MiB of RAM to assume if the real amount cannot be determined. */
7+
#define ASSUME_RAM 128
8+
9+
/* Define to 1 if crc32 integrity check is enabled. */
10+
#define HAVE_CHECK_CRC32 1
11+
12+
/* Define to 1 if crc64 integrity check is enabled. */
13+
#define HAVE_CHECK_CRC64 1
14+
15+
/* Define to 1 if sha256 integrity check is enabled. */
16+
#define HAVE_CHECK_SHA256 1
17+
18+
/* Define to 1 if any of HAVE_DECODER_foo have been defined. */
19+
#define HAVE_DECODERS 1
20+
21+
/* Define to 1 if arm decoder is enabled. */
22+
#define HAVE_DECODER_ARM 1
23+
24+
/* Define to 1 if armthumb decoder is enabled. */
25+
#define HAVE_DECODER_ARMTHUMB 1
26+
27+
/* Define to 1 if delta decoder is enabled. */
28+
#define HAVE_DECODER_DELTA 1
29+
30+
/* Define to 1 if ia64 decoder is enabled. */
31+
#define HAVE_DECODER_IA64 1
32+
33+
/* Define to 1 if lzma1 decoder is enabled. */
34+
#define HAVE_DECODER_LZMA1 1
35+
36+
/* Define to 1 if lzma2 decoder is enabled. */
37+
#define HAVE_DECODER_LZMA2 1
38+
39+
/* Define to 1 if powerpc decoder is enabled. */
40+
#define HAVE_DECODER_POWERPC 1
41+
42+
/* Define to 1 if sparc decoder is enabled. */
43+
#define HAVE_DECODER_SPARC 1
44+
45+
/* Define to 1 if x86 decoder is enabled. */
46+
#define HAVE_DECODER_X86 1
47+
48+
/* Define to 1 if any of HAVE_ENCODER_foo have been defined. */
49+
#define HAVE_ENCODERS 1
50+
51+
/* Define to 1 if arm encoder is enabled. */
52+
#define HAVE_ENCODER_ARM 1
53+
54+
/* Define to 1 if armthumb encoder is enabled. */
55+
#define HAVE_ENCODER_ARMTHUMB 1
56+
57+
/* Define to 1 if delta encoder is enabled. */
58+
#define HAVE_ENCODER_DELTA 1
59+
60+
/* Define to 1 if ia64 encoder is enabled. */
61+
#define HAVE_ENCODER_IA64 1
62+
63+
/* Define to 1 if lzma1 encoder is enabled. */
64+
#define HAVE_ENCODER_LZMA1 1
65+
66+
/* Define to 1 if lzma2 encoder is enabled. */
67+
#define HAVE_ENCODER_LZMA2 1
68+
69+
/* Define to 1 if powerpc encoder is enabled. */
70+
#define HAVE_ENCODER_POWERPC 1
71+
72+
/* Define to 1 if sparc encoder is enabled. */
73+
#define HAVE_ENCODER_SPARC 1
74+
75+
/* Define to 1 if x86 encoder is enabled. */
76+
#define HAVE_ENCODER_X86 1
77+
78+
/* Define to 1 if you have the <inttypes.h> header file. */
79+
#define HAVE_INTTYPES_H 1
80+
81+
/* Define to 1 if you have the <limits.h> header file. */
82+
#define HAVE_LIMITS_H 1
83+
84+
/* Define to 1 to enable bt2 match finder. */
85+
#define HAVE_MF_BT2 1
86+
87+
/* Define to 1 to enable bt3 match finder. */
88+
#define HAVE_MF_BT3 1
89+
90+
/* Define to 1 to enable bt4 match finder. */
91+
#define HAVE_MF_BT4 1
92+
93+
/* Define to 1 to enable hc3 match finder. */
94+
#define HAVE_MF_HC3 1
95+
96+
/* Define to 1 to enable hc4 match finder. */
97+
#define HAVE_MF_HC4 1
98+
99+
/* Define to 1 if stdbool.h conforms to C99. */
100+
#define HAVE_STDBOOL_H 1
101+
102+
/* Define to 1 if you have the <stdint.h> header file. */
103+
#define HAVE_STDINT_H 1
104+
105+
/* Define to 1 if you have the <stdlib.h> header file. */
106+
#define HAVE_STDLIB_H 1
107+
108+
/* Define to 1 if you have the <string.h> header file. */
109+
#define HAVE_STRING_H 1
110+
111+
/* Define to 1 or 0, depending whether the compiler supports simple visibility
112+
declarations. */
113+
#define HAVE_VISIBILITY 0
114+
115+
/* Define to 1 if the system has the type `_Bool'. */
116+
#define HAVE__BOOL 1
117+
118+
#ifdef _M_IX86
119+
/* Define to 1 when using Windows 95 (and thus XP) compatible threads. This
120+
avoids use of features that were added in Windows Vista.
121+
This is used for 32-bit x86 builds for compatibility reasons since it
122+
makes no measurable difference in performance compared to Vista threads. */
123+
#define MYTHREAD_WIN95 1
124+
#else
125+
/* Define to 1 when using Windows Vista compatible threads. This uses features
126+
that are not available on Windows XP. */
127+
#define MYTHREAD_VISTA 1
128+
#endif
129+
130+
/* Define to 1 to disable debugging code. */
131+
#define NDEBUG 1
132+
133+
/* Define to the full name of this package. */
134+
#define PACKAGE_NAME "XZ Utils"
135+
136+
/* Define to the home page for this package. */
137+
#define PACKAGE_URL "https://tukaani.org/xz/"
138+
139+
/* The size of `size_t', as computed by sizeof. */
140+
#ifdef _WIN64
141+
#define SIZEOF_SIZE_T 8
142+
#else
143+
#define SIZEOF_SIZE_T 4
144+
#endif
145+
146+
/* Define to 1 if the system supports fast unaligned access to 16-bit and
147+
32-bit integers. */
148+
#define TUKLIB_FAST_UNALIGNED_ACCESS 1

relenv/_resources/xz/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The config.h file was removed from XZ-Utils tarting with version 5.5.0.
2+
XZ-Utils seems to build just fine with the config.h file from 5.4.7, so we're
3+
including it here. This will be copied into the src/windows directory in the
4+
extracted source for XZ-Utils.

relenv/build/common.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
runcmd,
3939
work_dirs,
4040
fetch_url,
41+
Version,
4142
)
4243
import relenv.relocate
4344

@@ -358,6 +359,99 @@ def build_sqlite(env, dirs, logfp):
358359
runcmd(["make", "install"], env=env, stderr=logfp, stdout=logfp)
359360

360361

362+
def update_ensurepip(directory):
363+
"""
364+
Update bundled dependencies for ensurepip (pip & setuptools).
365+
"""
366+
# ensurepip bundle location
367+
bundle_dir = directory / "ensurepip" / "_bundled"
368+
369+
# Make sure the destination directory exists
370+
bundle_dir.mkdir(parents=True, exist_ok=True)
371+
372+
# Detect existing whl. Later versions of python don't include setuptools. We
373+
# only want to update whl files that python expects to be there
374+
pip_version = "25.2"
375+
setuptools_version = "80.9.0"
376+
update_pip = False
377+
update_setuptools = False
378+
for file in bundle_dir.glob("*.whl"):
379+
380+
log.debug("Checking whl: %s", str(file))
381+
if file.name.startswith("pip-"):
382+
found_version = file.name.split("-")[1]
383+
log.debug("Found version %s", found_version)
384+
if Version(found_version) >= Version(pip_version):
385+
log.debug("Found correct pip version or newer: %s", found_version)
386+
else:
387+
file.unlink()
388+
update_pip = True
389+
if file.name.startswith("setuptools-"):
390+
found_version = file.name.split("-")[1]
391+
log.debug("Found version %s", found_version)
392+
if Version(found_version) >= Version(setuptools_version):
393+
log.debug(
394+
"Found correct setuptools version or newer: %s", found_version
395+
)
396+
else:
397+
file.unlink()
398+
update_setuptools = True
399+
400+
# Download whl files and update __init__.py
401+
init_file = directory / "ensurepip" / "__init__.py"
402+
if update_pip:
403+
whl = f"pip-{pip_version}-py3-none-any.whl"
404+
whl_path = "b7/3f/945ef7ab14dc4f9d7f40288d2df998d1837ee0888ec3659c813487572faa"
405+
url = f"https://files.pythonhosted.org/packages/{whl_path}/{whl}"
406+
download_url(url=url, dest=bundle_dir)
407+
assert (bundle_dir / whl).exists()
408+
409+
# Update __init__.py
410+
old = "^_PIP_VERSION.*"
411+
new = f'_PIP_VERSION = "{pip_version}"'
412+
patch_file(path=init_file, old=old, new=new)
413+
414+
# setuptools
415+
if update_setuptools:
416+
whl = f"setuptools-{setuptools_version}-py3-none-any.whl"
417+
whl_path = "a3/dc/17031897dae0efacfea57dfd3a82fdd2a2aeb58e0ff71b77b87e44edc772"
418+
url = f"https://files.pythonhosted.org/packages/{whl_path}/{whl}"
419+
download_url(url=url, dest=bundle_dir)
420+
assert (bundle_dir / whl).exists()
421+
422+
# setuptools
423+
old = "^_SETUPTOOLS_VERSION.*"
424+
new = f'_SETUPTOOLS_VERSION = "{setuptools_version}"'
425+
patch_file(path=init_file, old=old, new=new)
426+
427+
log.debug("ensurepip __init__.py contents:")
428+
log.debug(init_file.read_text())
429+
430+
431+
def patch_file(path, old, new):
432+
"""
433+
Search a file line by line for a string to replace.
434+
435+
:param path: Location of the file to search
436+
:type path: str
437+
:param old: The value that will be replaced
438+
:type path: str
439+
:param new: The value that will replace the 'old' value.
440+
:type path: str
441+
"""
442+
log.debug("Patching file: %s", path)
443+
import re
444+
445+
with open(path, "r") as fp:
446+
content = fp.read()
447+
new_content = ""
448+
for line in content.splitlines():
449+
line = re.sub(old, new, line)
450+
new_content += line + "\n"
451+
with open(path, "w") as fp:
452+
fp.write(new_content)
453+
454+
361455
def tarball_version(href):
362456
if href.endswith("tar.gz"):
363457
try:
@@ -1457,6 +1551,9 @@ def find_pythonlib(libdir):
14571551

14581552
pymodules = libdir / find_pythonlib(libdir)
14591553

1554+
# update ensurepip
1555+
update_ensurepip(pymodules)
1556+
14601557
cwd = os.getcwd()
14611558
modname = find_sysconfigdata(pymodules)
14621559
path = sys.path
@@ -1474,6 +1571,7 @@ def find_pythonlib(libdir):
14741571
bindir = pathlib.Path(dirs.prefix) / "bin"
14751572
sitepackages = pymodules / "site-packages"
14761573
install_runtime(sitepackages)
1574+
14771575
# Install pip
14781576
python = dirs.prefix / "bin" / "python3"
14791577
if env["RELENV_HOST_ARCH"] != env["RELENV_BUILD_ARCH"]:

relenv/build/linux.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,11 @@ def build_python(env, dirs, logfp):
379379
)
380380

381381
if pathlib.Path("setup.py").exists():
382-
with tempfile.NamedTemporaryFile(mode="w", suffix="_patch") as patch_file:
383-
patch_file.write(PATCH)
384-
patch_file.flush()
382+
with tempfile.NamedTemporaryFile(mode="w", suffix="_patch") as p_file:
383+
p_file.write(PATCH)
384+
p_file.flush()
385385
runcmd(
386-
["patch", "-p0", "-i", patch_file.name],
386+
["patch", "-p0", "-i", p_file.name],
387387
env=env,
388388
stderr=logfp,
389389
stdout=logfp,

0 commit comments

Comments
 (0)