Skip to content

Commit

Permalink
feat: adds support for python and pypy distribution mirrors
Browse files Browse the repository at this point in the history
  • Loading branch information
axel-kah committed May 2, 2024
1 parent 44d66f5 commit c4d95bc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/plugins/environment/virtual.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Some distributions have [variants](https://gregoryszorc.com/docs/python-build-st
| Linux | <ul><li><code>v1</code></li><li><code>v2</code></li><li><code>v3</code> (default)</li><li><code>v4</code></li></ul> |
| Windows | <ul><li><code>shared</code> (default)</li><li><code>static</code></li></ul> |

You can configure Hatch to use a mirror of these distributions by setting the `HATCH_CUSTOM_CPYTHON_SOURCE` environment variable to your mirror. The custom source is expected to contain the releases following the upstreams structure `<calver>/cpython-X.Y.Z%2B<calver>-aarch64-unknown-linux-gnu-install_only.tar.gz`.

### PyPy

| ID |
Expand All @@ -85,6 +87,8 @@ Some distributions have [variants](https://gregoryszorc.com/docs/python-build-st

The source of distributions is the [PyPy](https://www.pypy.org) project.

You can configure Hatch to use a mirror of these distributions by setting the `HATCH_CUSTOM_PYPY_SOURCE` environment variable to your mirror. The custom source is expected to contain the releases following the upstreams structure `pypyX.Y-vA.B.C-aarch64.tar.bz2`.

## Troubleshooting

### macOS SIP
Expand Down
5 changes: 5 additions & 0 deletions src/hatch/cli/python/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def install(app: Application, *, names: tuple[str, ...], private: bool, update:
```
hatch python install all
```
If you run your own mirror you can tell Hatch to use it by setting these environment variables to your mirrors URL:
* ``HATCH_CUSTOM_CPYTHON_SOURCE``
* ``HATCH_CUSTOM_PYPY_SOURCE``
"""
from hatch.errors import PythonDistributionResolutionError, PythonDistributionUnknownError
from hatch.python.distributions import ORDERED_DISTRIBUTIONS
Expand Down
19 changes: 19 additions & 0 deletions src/hatch/python/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ def python_path(self) -> str:


class CPythonStandaloneDistribution(Distribution):
@property
def source(self) -> str:
source = super().source
custom_source = os.environ.get('HATCH_CUSTOM_CPYTHON_SOURCE')
if custom_source:
source = super().source.replace(
'https://github.com/indygreg/python-build-standalone/releases/download/',
custom_source.rstrip('/') + '/',
)
return source

@cached_property
def version(self) -> Version:
from packaging.version import Version
Expand Down Expand Up @@ -110,6 +121,14 @@ def python_path(self) -> str:


class PyPyOfficialDistribution(Distribution):
@property
def source(self) -> str:
source = super().source
custom_source = os.environ.get('HATCH_CUSTOM_PYPY_SOURCE')
if custom_source:
source = super().source.replace('https://downloads.python.org/pypy/', custom_source.rstrip('/') + '/')
return source

@cached_property
def version(self) -> Version:
from packaging.version import Version
Expand Down

0 comments on commit c4d95bc

Please sign in to comment.