uv/crates/uv-python/src
Meitar Reihan 2b62f73064
Add `UV_PYTHON_DOWNLOADS_JSON_URL` to set custom managed python sources (#10939)
## Summary

Add an option to overwrite the list of available Python downloads from a
local JSON file by using the environment variable
`UV_PYTHON_DOWNLOADS_JSON_URL`

as an experimental support for providing custom sources for Python
distribution binaries #8015

related #10203

I probably should make the JSON to be fetched from a remote URL instead
of a local file.
please let me know what you think and I will modify the code
accordingly.

## Test Plan

### normal run
```
root@75c66494ba8b:/# /code/target/release/uv python list
cpython-3.14.0a4+freethreaded-linux-x86_64-gnu    <download available>
cpython-3.14.0a4-linux-x86_64-gnu                 <download available>
cpython-3.13.1+freethreaded-linux-x86_64-gnu      <download available>
cpython-3.13.1-linux-x86_64-gnu                   <download available>
cpython-3.12.8-linux-x86_64-gnu                   <download available>
cpython-3.11.11-linux-x86_64-gnu                  <download available>
cpython-3.10.16-linux-x86_64-gnu                  <download available>
cpython-3.9.21-linux-x86_64-gnu                   <download available>
cpython-3.8.20-linux-x86_64-gnu                   <download available>
cpython-3.7.9-linux-x86_64-gnu                    <download available>
pypy-3.10.14-linux-x86_64-gnu                     <download available>
pypy-3.9.19-linux-x86_64-gnu                      <download available>
pypy-3.8.16-linux-x86_64-gnu                      <download available>
pypy-3.7.13-linux-x86_64-gnu                      <download available>
```

### empty JSON file
```sh
root@75c66494ba8b:/# export UV_PYTHON_DOWNLOADS_JSON_URL=/code/crates/uv-python/my-download-metadata.json 
root@75c66494ba8b:/# cat $UV_PYTHON_DOWNLOADS_JSON_URL 
{}
root@75c66494ba8b:/# /code/target/release/uv python list
root@75c66494ba8b:/# 
```

### JSON file with valid version
```sh
root@75c66494ba8b:/# export UV_PYTHON_DOWNLOADS_JSON_URL=/code/crates/uv-python/my-download-metadata.json 
root@75c66494ba8b:/# cat $UV_PYTHON_DOWNLOADS_JSON_URL 
{
  "cpython-3.11.9-linux-x86_64-gnu": {
    "name": "cpython",
    "arch": {
      "family": "x86_64",
      "variant": null
    },
    "os": "linux",
    "libc": "gnu",
    "major": 3,
    "minor": 11,
    "patch": 9,
    "prerelease": "",
    "url": "https://github.com/astral-sh/python-build-standalone/releases/download/20240814/cpython-3.11.9%2B20240814-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz",
    "sha256": "daa487c7e73005c4426ac393273117cf0e2dc4ab9b2eeda366e04cd00eea00c9",
    "variant": null
  }
}
root@75c66494ba8b:/# /code/target/release/uv python list
cpython-3.11.9-linux-x86_64-gnu    <download available>
root@75c66494ba8b:/# 
```

### Remote Path

```sh
root@75c66494ba8b:/# export UV_PYTHON_DOWNLOADS_JSON_URL=http://a.com/file.json 
root@75c66494ba8b:/# /code/target/release/uv python list
error: Remote python downloads JSON is not yet supported, please use a local path (without `file://` prefix)
```

---------

Co-authored-by: Aria Desires <aria.desires@gmail.com>
2025-04-07 13:55:00 -04:00
..
sysconfig Bump MSRV to 1.84 (#12670) 2025-04-04 11:49:26 -04:00
cpuinfo.rs Fix hard and soft float libc detection for managed Python distributions on ARM (#8498) 2024-10-29 23:46:21 +00:00
discovery.rs Bump MSRV to 1.84 (#12670) 2025-04-04 11:49:26 -04:00
download-metadata-minified.json Add `UV_PYTHON_DOWNLOADS_JSON_URL` to set custom managed python sources (#10939) 2025-04-07 13:55:00 -04:00
downloads.rs Add `UV_PYTHON_DOWNLOADS_JSON_URL` to set custom managed python sources (#10939) 2025-04-07 13:55:00 -04:00
environment.rs Bump MSRV to 1.84 (#12670) 2025-04-04 11:49:26 -04:00
implementation.rs Prefer Python executable names that match the request over default names (#9066) 2024-11-13 10:00:23 -06:00
installation.rs Add `UV_PYTHON_DOWNLOADS_JSON_URL` to set custom managed python sources (#10939) 2025-04-07 13:55:00 -04:00
interpreter.rs Report the queried executable path in `uv python list` (#12628) 2025-04-02 14:24:58 -05:00
lib.rs Bump MSRV to 1.84 (#12670) 2025-04-04 11:49:26 -04:00
libc.rs Consistently write log messages with capitalized first word (#11111) 2025-01-30 18:56:46 +00:00
macos_dylib.rs Install and remove managed Python to and from the Windows Registry (PEP 514) (#10634) 2025-01-23 14:13:41 +00:00
managed.rs Bump MSRV to 1.84 (#12670) 2025-04-04 11:49:26 -04:00
microsoft_store.rs Install and remove managed Python to and from the Windows Registry (PEP 514) (#10634) 2025-01-23 14:13:41 +00:00
platform.rs Add support for dynamic musl Python distributions on x86-64 Linux (#12121) 2025-03-11 18:14:10 -05:00
pointer_size.rs Change "toolchain" to "python" (#4735) 2024-07-03 07:44:29 -05:00
prefix.rs Add `uv-` prefix to all internal crates (#7853) 2024-10-01 20:15:32 -04:00
python_version.rs Edition 2024 prep: Escape `r#gen` and remove redundant ref (#11922) 2025-03-03 11:13:56 +00:00
target.rs Add `uv-` prefix to all internal crates (#7853) 2024-10-01 20:15:32 -04:00
version_files.rs Add support for global `uv python pin` (#12115) 2025-03-13 13:48:37 +01:00
virtualenv.rs Bump MSRV to 1.84 (#12670) 2025-04-04 11:49:26 -04:00
windows_registry.rs Bump MSRV to 1.84 (#12670) 2025-04-04 11:49:26 -04:00