Skip to content

Commit

Permalink
Update fine-grained versioning for CPython distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed Oct 23, 2023
1 parent 1d9e002 commit ed1a994
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/plugins/environment/virtual.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ If a Python version has been chosen then each resolver will try to find an inter
If no version has been chosen, then each resolver will try to find a version that matches the version of Python that Hatch is currently running on. If not found then each resolver will try to find the highest compatible version.

!!! note
Some external Python paths are considered unstable and are ignored during resolution. For example, if Hatch if installed via Homebrew then `sys.executable` will be ignored because the interpreter could change or be removed at any time.
Some external Python paths are considered unstable and are ignored during resolution. For example, if Hatch is installed via Homebrew then `sys.executable` will be ignored because the interpreter could change or be removed at any time.

!!! note
When resolution finds a match using an [internally managed distribution](#internal-distributions) and an update is available, the latest distribution will automatically be downloaded before environment creation.
Expand Down
8 changes: 6 additions & 2 deletions src/hatch/python/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ class CPythonStandaloneDistribution(Distribution):
def version(self) -> Version:
from packaging.version import Version

*_, remaining = self.source.partition('/download/')
version, *_ = remaining.partition('/')
# .../cpython-3.12.0%2B20231002-...
# .../cpython-3.7.9-...
_, _, remaining = self.source.partition('/cpython-')
# 3.12.0%2B20231002-...
# 3.7.9-...
version = remaining.split('%2B')[0] if '%2B' in remaining else remaining.split('-')[0]
return Version(f'0!{version}')

@cached_property
Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_cpython_standalone(self):
version = dist.version

assert version.epoch == 0
assert version.base_version == '20230507'
assert version.base_version == '3.11.3'

def test_pypy(self):
url = 'https://downloads.python.org/pypy/pypy3.10-v7.3.12-aarch64.tar.bz2'
Expand Down

0 comments on commit ed1a994

Please sign in to comment.