File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -484,6 +484,16 @@ def evaluate(
484484 )
485485
486486
487+ def _pep440_python_full_version (python_full_version : str ) -> str :
488+ """
489+ Work around platform.python_version() returning something that is not PEP 440
490+ compliant for non-tagged Python builds.
491+ """
492+ if python_full_version .endswith ("+" ):
493+ return f"{ python_full_version } local"
494+ return python_full_version
495+
496+
487497def _repair_python_full_version (
488498 env : dict [str , str | AbstractSet [str ]],
489499) -> dict [str , str | AbstractSet [str ]]:
@@ -492,6 +502,5 @@ def _repair_python_full_version(
492502 compliant for non-tagged Python builds.
493503 """
494504 python_full_version = cast ("str" , env ["python_full_version" ])
495- if python_full_version .endswith ("+" ):
496- env ["python_full_version" ] = f"{ python_full_version } local"
505+ env ["python_full_version" ] = _pep440_python_full_version (python_full_version )
497506 return env
Original file line number Diff line number Diff line change 1616)
1717from urllib .parse import urlparse
1818
19- from .markers import Environment , Marker , default_environment
19+ from .markers import (
20+ Environment ,
21+ Marker ,
22+ _pep440_python_full_version ,
23+ default_environment ,
24+ )
2025from .specifiers import SpecifierSet
2126from .tags import create_compatible_tags_selector , sys_tags
2227from .utils import (
@@ -782,7 +787,7 @@ def select(
782787 ),
783788 ),
784789 )
785- env_python_full_version = (
790+ env_python_full_version = _pep440_python_full_version (
786791 environment ["python_full_version" ]
787792 if environment
788793 else default_environment ()["python_full_version" ]
Original file line number Diff line number Diff line change 77
88import pytest
99
10- from packaging .markers import Marker
10+ from packaging .markers import Marker , default_environment
1111from packaging .pylock import (
1212 Package ,
1313 PackageArchive ,
@@ -369,3 +369,24 @@ def test_extras_and_groups(
369369 )
370370 ]
371371 assert selected_names == expected
372+
373+
374+ def test_python_prerelease () -> None :
375+ """Python pre-release versions are not PEP 440 compliant.
376+ Test that Pylock.requires_python supports that.
377+ """
378+ pylock = Pylock (
379+ lock_version = Version ("1.0" ),
380+ created_by = "repro" ,
381+ requires_python = SpecifierSet (">=3.12" ),
382+ packages = [
383+ Package (
384+ name = cast ("NormalizedName" , "pkga" ),
385+ requires_python = SpecifierSet (">=3.12" ),
386+ directory = PackageDirectory (path = "./pkga" ),
387+ )
388+ ],
389+ )
390+ env = default_environment ()
391+ env ["python_full_version" ] = "3.15.0a8+"
392+ list (pylock .select (environment = env ))
You can’t perform that action at this time.
0 commit comments