Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for CPython development releases. #2655

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Release Notes

## 2.32.1

This release fixes 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.

* Fix support for CPython development releases. (#2655)

## 2.32.0

This release adds support for Pip 25.0.
Expand Down
22 changes: 21 additions & 1 deletion pex/pep_508.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@
from pex.third_party import attr


def _convert_non_pep_440_dev_versions(python_full_version):
# type: (Optional[str]) -> Optional[str]

# This applies the same workaround that exists in packaging as of its 24.1 release.
# See:
# + https://github.com/pypa/packaging/pull/802
# + https://github.com/pypa/packaging/pull/825
#
# N.B.: We can't simply upgrade to packaging >= 24.1 since those changes unconditionally access
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# the `python_full_version` marker and our `AbbreviatedPlatform` can lead to marker environments
# without that marker filled in. Even if we could upgrade packaging though, that would only help
# Pex users on Python >= 3.8 whereas this fix applies to all Pex users.
if python_full_version and python_full_version.endswith("+"):
return python_full_version + "local"

return python_full_version


@attr.s(frozen=True)
class MarkerEnvironment(object):
"""A PEP-508 marker environment.
Expand Down Expand Up @@ -125,7 +143,9 @@ def from_platform(cls, platform):
platform_release = attr.ib(default=None) # type: Optional[str]
platform_system = attr.ib(default=None) # type: Optional[str]
platform_version = attr.ib(default=None) # type: Optional[str]
python_full_version = attr.ib(default=None) # type: Optional[str]
python_full_version = attr.ib(
default=None, converter=_convert_non_pep_440_dev_versions
) # type: Optional[str]
python_version = attr.ib(default=None) # type: Optional[str]
sys_platform = attr.ib(default=None) # type: Optional[str]

Expand Down
2 changes: 1 addition & 1 deletion pex/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2015 Pex project contributors.
# Licensed under the Apache License, Version 2.0 (see LICENSE).

__version__ = "2.32.0"
__version__ = "2.32.1"
8 changes: 8 additions & 0 deletions tests/test_pep_508.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,11 @@ def assert_platform_machine(

assert_platform_machine("x86_64", "macosx-10.15-x86_64-cp-38-m")
assert_platform_machine("arm64", "macosx-11.0-arm64-cp-39-cp39")


def test_cpython_dev_release():
env = MarkerEnvironment(python_full_version="3.10.16+").as_dict()
assert evaluate_marker("python_full_version >= '3.10.16'", env)
assert evaluate_marker("python_full_version <= '3.10.17'", env)
assert evaluate_marker("python_full_version == '3.10.16'", env)
assert not evaluate_marker("python_full_version === '3.10.16'", env)