Skip to content

Commit 76c3da6

Browse files
authored
Fix support for CPython development releases. (#2655)
Fix a long-standing bug handling development versions of CPython (any non-tagged release of the interpreter). These interpreters report a full version of `X.Y.Z+` and the trailing `+` leads to a non PEP-440 compliant version number. This, in turn, causes issues with the `packaging` library leading to failures to evaluate markers for these interpreters which surface as inscrutable Pex errors. Apply the same workaround as used in packaging >= 24.1. See: + pypa/packaging#802 + pypa/packaging#825
1 parent 740a218 commit 76c3da6

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

CHANGES.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Release Notes
22

3+
## 2.32.1
4+
5+
This release fixes a long-standing bug handling development versions of
6+
CPython (any non-tagged release of the interpreter). These interpreters
7+
report a full version of `X.Y.Z+` and the trailing `+` leads to a non
8+
PEP-440 compliant version number. This, in turn, causes issues with the
9+
`packaging` library leading to failures to evaluate markers for these
10+
interpreters which surface as inscrutable Pex errors.
11+
12+
* Fix support for CPython development releases. (#2655)
13+
314
## 2.32.0
415

516
This release adds support for Pip 25.0.

pex/pep_508.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@
1515
from pex.third_party import attr
1616

1717

18+
def _convert_non_pep_440_dev_versions(python_full_version):
19+
# type: (Optional[str]) -> Optional[str]
20+
21+
# This applies the same workaround that exists in packaging as of its 24.1 release.
22+
# See:
23+
# + https://github.com/pypa/packaging/pull/802
24+
# + https://github.com/pypa/packaging/pull/825
25+
#
26+
# N.B.: We can't simply upgrade to packaging >= 24.1 since those changes unconditionally access
27+
# the `python_full_version` marker and our `AbbreviatedPlatform` can lead to marker environments
28+
# without that marker filled in. Even if we could upgrade packaging though, that would only help
29+
# Pex users on Python >= 3.8 whereas this fix applies to all Pex users.
30+
if python_full_version and python_full_version.endswith("+"):
31+
return python_full_version + "local"
32+
33+
return python_full_version
34+
35+
1836
@attr.s(frozen=True)
1937
class MarkerEnvironment(object):
2038
"""A PEP-508 marker environment.
@@ -125,7 +143,9 @@ def from_platform(cls, platform):
125143
platform_release = attr.ib(default=None) # type: Optional[str]
126144
platform_system = attr.ib(default=None) # type: Optional[str]
127145
platform_version = attr.ib(default=None) # type: Optional[str]
128-
python_full_version = attr.ib(default=None) # type: Optional[str]
146+
python_full_version = attr.ib(
147+
default=None, converter=_convert_non_pep_440_dev_versions
148+
) # type: Optional[str]
129149
python_version = attr.ib(default=None) # type: Optional[str]
130150
sys_platform = attr.ib(default=None) # type: Optional[str]
131151

pex/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Copyright 2015 Pex project contributors.
22
# Licensed under the Apache License, Version 2.0 (see LICENSE).
33

4-
__version__ = "2.32.0"
4+
__version__ = "2.32.1"

tests/test_pep_508.py

+8
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,11 @@ def assert_platform_machine(
9999

100100
assert_platform_machine("x86_64", "macosx-10.15-x86_64-cp-38-m")
101101
assert_platform_machine("arm64", "macosx-11.0-arm64-cp-39-cp39")
102+
103+
104+
def test_cpython_dev_release():
105+
env = MarkerEnvironment(python_full_version="3.10.16+").as_dict()
106+
assert evaluate_marker("python_full_version >= '3.10.16'", env)
107+
assert evaluate_marker("python_full_version <= '3.10.17'", env)
108+
assert evaluate_marker("python_full_version == '3.10.16'", env)
109+
assert not evaluate_marker("python_full_version === '3.10.16'", env)

0 commit comments

Comments
 (0)