Skip to content

Commit 3ee8028

Browse files
authored
Improve performance of uv-python crate's manylinux submodule (#11131)
## Summary This PR makes a few performance improvements: 1. Reduces the need to unpack and repack a `_GLibCVersion` tuple 2. Reduces the doubled call to `_is_compatible(arch, glibc_version)` 3. Moves the assignment of the `tag` variable directly into the yield, reducing memory allocation in case this is never used when `_is_compatible(arch, glibc_version)` is false 4. Combines the check of the `glibc_version` being in `_LEGACY_MANYLINUX_MAP` and the assignment to the variable together. I'm not sure if this is actually better, but using the assignment expression reduces this from 4 lines to 2 ## Test Plan I upstreamed these changes in pypa/packaging#869. Otherwise, I'm pretty confident this is a minor change that works the same
1 parent de64f1d commit 3ee8028

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

crates/uv-python/python/packaging/_manylinux.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def platform_tags(archs: Sequence[str]) -> Iterator[str]:
232232
if set(archs) & {"x86_64", "i686"}:
233233
# On x86/i686 also oldest glibc to be supported is (2, 5).
234234
too_old_glibc2 = _GLibCVersion(2, 4)
235-
current_glibc = _GLibCVersion(*_get_glibc_version())
235+
current_glibc = _get_glibc_version()
236236
glibc_max_list = [current_glibc]
237237
# We can assume compatibility across glibc major versions.
238238
# https://sourceware.org/bugzilla/show_bug.cgi?id=24636
@@ -252,11 +252,8 @@ def platform_tags(archs: Sequence[str]) -> Iterator[str]:
252252
min_minor = -1
253253
for glibc_minor in range(glibc_max.minor, min_minor, -1):
254254
glibc_version = _GLibCVersion(glibc_max.major, glibc_minor)
255-
tag = "manylinux_{}_{}".format(*glibc_version)
256255
if _is_compatible(arch, glibc_version):
257-
yield f"{tag}_{arch}"
258-
# Handle the legacy manylinux1, manylinux2010, manylinux2014 tags.
259-
if glibc_version in _LEGACY_MANYLINUX_MAP:
260-
legacy_tag = _LEGACY_MANYLINUX_MAP[glibc_version]
261-
if _is_compatible(arch, glibc_version):
256+
yield "manylinux_{}_{}_{}".format(*glibc_version, arch)
257+
# Handle the legacy manylinux1, manylinux2010, manylinux2014 tags.
258+
if legacy_tag := _LEGACY_MANYLINUX_MAP.get(glibc_version):
262259
yield f"{legacy_tag}_{arch}"

0 commit comments

Comments
 (0)