Skip to content

Commit

Permalink
Repair the version even if passed in.
Browse files Browse the repository at this point in the history
Closes pypa#678
  • Loading branch information
jaraco committed Aug 16, 2024
1 parent 8b542be commit 936249e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/packaging/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,23 +309,22 @@ def evaluate(self, environment: dict[str, str] | None = None) -> bool:
"""
current_environment = cast("dict[str, str]", default_environment())
current_environment["extra"] = ""
_repair_python_full_version(current_environment)
if environment is not None:
current_environment.update(environment)
# The API used to allow setting extra to None. We need to handle this
# case for backwards compatibility.
if current_environment["extra"] is None:
current_environment["extra"] = ""

return _evaluate_markers(self._markers, current_environment)
return _evaluate_markers(
self._markers, _repair_python_full_version(current_environment)
)


def _repair_python_full_version(env: dict[str, str]) -> dict[str, str]:
"""
Work around platform.python_version() returning something that is not PEP 440
compliant for non-tagged Python builds. Preserve default_environment()'s
behavior of returning platform.python_version() verbatim, and leave it to the
caller to provide a syntactically valid version if they want to override it.
compliant for non-tagged Python builds.
"""
if env["python_full_version"].endswith("+"):
env["python_full_version"] += "local"
Expand Down

0 comments on commit 936249e

Please sign in to comment.