Support environment variables in index URLs in requirements files (#2036)

## Summary

This also preserves the environment variables in the output file, e.g.:

```
Resolved 1 package in 216ms
# This file was autogenerated by uv via the following command:
#    uv pip compile requirements.in --emit-index-url
--index-url https://test.pypi.org/${SUFFIX}

requests==2.5.4.1
```

I'm torn on whether that's correct or undesirable here.

Closes #2035.
This commit is contained in:
Charlie Marsh 2024-02-28 14:36:20 -05:00 committed by GitHub
parent 1df977f86b
commit b873e3e991
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 140 additions and 70 deletions

View file

@ -43,8 +43,8 @@ pub(crate) struct ResolveCliArgs {
cache_args: CacheArgs,
#[arg(long)]
exclude_newer: Option<DateTime<Utc>>,
#[clap(long, short, default_value = IndexUrl::Pypi.as_str(), env = "UV_INDEX_URL")]
index_url: IndexUrl,
#[clap(long, short, env = "UV_INDEX_URL")]
index_url: Option<IndexUrl>,
#[clap(long, env = "UV_EXTRA_INDEX_URL")]
extra_index_url: Vec<IndexUrl>,
#[clap(long)]
@ -56,12 +56,8 @@ pub(crate) async fn resolve_cli(args: ResolveCliArgs) -> Result<()> {
let platform = Platform::current()?;
let venv = PythonEnvironment::from_virtualenv(platform, &cache)?;
let index_locations = IndexLocations::new(
Some(args.index_url),
args.extra_index_url,
args.find_links,
false,
);
let index_locations =
IndexLocations::new(args.index_url, args.extra_index_url, args.find_links, false);
let client = RegistryClientBuilder::new(cache.clone())
.index_urls(index_locations.index_urls())
.build();