Skip to content

Add Python distribution mirror environment variables#2283

Open
Lucas-FManager wants to merge 1 commit into
pypa:masterfrom
Lucas-FManager:code/hatch-python-mirror-env-2236
Open

Add Python distribution mirror environment variables#2283
Lucas-FManager wants to merge 1 commit into
pypa:masterfrom
Lucas-FManager:code/hatch-python-mirror-env-2236

Conversation

@Lucas-FManager

Copy link
Copy Markdown

Problem

Hatch can already override individual managed Python distributions with HATCH_PYTHON_CUSTOM_SOURCE_<NAME>, but enterprise mirror setups need a single base URL override for the built-in CPython/PyPy sources. Today that means maintaining one env var per distribution, and the built-in URLs stay coupled to the upstream hosts.

Approach

  • Add HATCH_PYTHON_INSTALL_MIRROR for CPython standalone downloads and HATCH_PYPY_INSTALL_MIRROR for PyPy downloads.
  • Rewrite only known built-in source base URLs and preserve the archive path suffix.
  • Keep explicit source arguments unchanged.
  • Keep per-distribution custom sources higher priority than the mirror behavior.
  • Parse PyPy versions from the archive name so mirrored URLs do not need to contain /pypy/.
  • Document the new mirror variables and correct the custom source env var name in the virtual environment docs.

Security

The new variables are user-controlled in the same trust boundary as the existing custom source variables. Rewriting is intentionally limited to known built-in upstream bases, and users are told to point mirrors only at trusted sources.

Verification

  • .\.venv\Scripts\python.exe -m pytest tests/python/test_resolve.py -q -> 13 passed, 10 skipped
  • uvx ruff format --check src/hatch/config/constants.py src/hatch/python/resolve.py tests/python/test_resolve.py -> passed
  • uvx ruff check src/hatch/config/constants.py src/hatch/python/resolve.py tests/python/test_resolve.py -> passed
  • git diff --check -> passed

Fixes #2236

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for environment variable to manage mirrored Python distributions

1 participant