Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add index URL parameters to Project CLI #3984

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions crates/uv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,43 @@ pub(crate) struct RunArgs {
#[arg(long, short = 'P')]
pub(crate) upgrade_package: Vec<PackageName>,

/// The URL of the Python package index (by default: <https://pypi.org/simple>).
///
/// The index given by this flag is given lower priority than all other
/// indexes specified via the `--extra-index-url` flag.
///
/// Unlike `pip`, `uv` will stop looking for versions of a package as soon
/// as it finds it in an index. That is, it isn't possible for `uv` to
/// consider versions of the same package across multiple indexes.
#[arg(long, short, env = "UV_INDEX_URL", value_parser = parse_index_url)]
pub(crate) index_url: Option<Maybe<IndexUrl>>,

/// Extra URLs of package indexes to use, in addition to `--index-url`.
///
/// All indexes given via this flag take priority over the index
/// in `--index-url` (which defaults to PyPI). And when multiple
/// `--extra-index-url` flags are given, earlier values take priority.
///
/// Unlike `pip`, `uv` will stop looking for versions of a package as soon
/// as it finds it in an index. That is, it isn't possible for `uv` to
/// consider versions of the same package across multiple indexes.
#[arg(long, env = "UV_EXTRA_INDEX_URL", value_delimiter = ' ', value_parser = parse_index_url)]
pub(crate) extra_index_url: Option<Vec<Maybe<IndexUrl>>>,

/// Locations to search for candidate distributions, beyond those found in the indexes.
///
/// If a path, the target must be a directory that contains package as wheel files (`.whl`) or
/// source distributions (`.tar.gz` or `.zip`) at the top level.
///
/// If a URL, the page must contain a flat list of links to package files.
#[arg(long, short)]
pub(crate) find_links: Option<Vec<FlatIndexLocation>>,

/// Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those
/// discovered via `--find-links`.
#[arg(long)]
pub(crate) no_index: bool,

/// The Python interpreter to use to build the run environment.
///
/// By default, `uv` uses the virtual environment in the current working directory or any parent
Expand Down Expand Up @@ -1867,6 +1904,43 @@ pub(crate) struct SyncArgs {
#[arg(long)]
pub(crate) refresh_package: Vec<PackageName>,

/// The URL of the Python package index (by default: <https://pypi.org/simple>).
///
/// The index given by this flag is given lower priority than all other
/// indexes specified via the `--extra-index-url` flag.
///
/// Unlike `pip`, `uv` will stop looking for versions of a package as soon
/// as it finds it in an index. That is, it isn't possible for `uv` to
/// consider versions of the same package across multiple indexes.
#[arg(long, short, env = "UV_INDEX_URL", value_parser = parse_index_url)]
pub(crate) index_url: Option<Maybe<IndexUrl>>,

/// Extra URLs of package indexes to use, in addition to `--index-url`.
///
/// All indexes given via this flag take priority over the index
/// in `--index-url` (which defaults to PyPI). And when multiple
/// `--extra-index-url` flags are given, earlier values take priority.
///
/// Unlike `pip`, `uv` will stop looking for versions of a package as soon
/// as it finds it in an index. That is, it isn't possible for `uv` to
/// consider versions of the same package across multiple indexes.
#[arg(long, env = "UV_EXTRA_INDEX_URL", value_delimiter = ' ', value_parser = parse_index_url)]
pub(crate) extra_index_url: Option<Vec<Maybe<IndexUrl>>>,

/// Locations to search for candidate distributions, beyond those found in the indexes.
///
/// If a path, the target must be a directory that contains package as wheel files (`.whl`) or
/// source distributions (`.tar.gz` or `.zip`) at the top level.
///
/// If a URL, the page must contain a flat list of links to package files.
#[arg(long, short)]
pub(crate) find_links: Option<Vec<FlatIndexLocation>>,

/// Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those
/// discovered via `--find-links`.
#[arg(long)]
pub(crate) no_index: bool,

/// The Python interpreter to use to build the run environment.
///
/// By default, `uv` uses the virtual environment in the current working directory or any parent
Expand Down Expand Up @@ -1912,6 +1986,43 @@ pub(crate) struct LockArgs {
#[arg(long, short = 'P')]
pub(crate) upgrade_package: Vec<PackageName>,

/// The URL of the Python package index (by default: <https://pypi.org/simple>).
///
/// The index given by this flag is given lower priority than all other
/// indexes specified via the `--extra-index-url` flag.
///
/// Unlike `pip`, `uv` will stop looking for versions of a package as soon
/// as it finds it in an index. That is, it isn't possible for `uv` to
/// consider versions of the same package across multiple indexes.
#[arg(long, short, env = "UV_INDEX_URL", value_parser = parse_index_url)]
pub(crate) index_url: Option<Maybe<IndexUrl>>,

/// Extra URLs of package indexes to use, in addition to `--index-url`.
///
/// All indexes given via this flag take priority over the index
/// in `--index-url` (which defaults to PyPI). And when multiple
/// `--extra-index-url` flags are given, earlier values take priority.
///
/// Unlike `pip`, `uv` will stop looking for versions of a package as soon
/// as it finds it in an index. That is, it isn't possible for `uv` to
/// consider versions of the same package across multiple indexes.
#[arg(long, env = "UV_EXTRA_INDEX_URL", value_delimiter = ' ', value_parser = parse_index_url)]
pub(crate) extra_index_url: Option<Vec<Maybe<IndexUrl>>>,

/// Locations to search for candidate distributions, beyond those found in the indexes.
///
/// If a path, the target must be a directory that contains package as wheel files (`.whl`) or
/// source distributions (`.tar.gz` or `.zip`) at the top level.
///
/// If a URL, the page must contain a flat list of links to package files.
#[arg(long, short)]
pub(crate) find_links: Option<Vec<FlatIndexLocation>>,

/// Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those
/// discovered via `--find-links`.
#[arg(long)]
pub(crate) no_index: bool,

/// The Python interpreter to use to build the run environment.
///
/// By default, `uv` uses the virtual environment in the current working directory or any parent
Expand Down Expand Up @@ -1980,7 +2091,54 @@ pub(crate) struct ToolRunArgs {
#[arg(long)]
pub(crate) with: Vec<String>,

/// The URL of the Python package index (by default: <https://pypi.org/simple>).
///
/// The index given by this flag is given lower priority than all other
/// indexes specified via the `--extra-index-url` flag.
///
/// Unlike `pip`, `uv` will stop looking for versions of a package as soon
/// as it finds it in an index. That is, it isn't possible for `uv` to
/// consider versions of the same package across multiple indexes.
#[arg(long, short, env = "UV_INDEX_URL", value_parser = parse_index_url)]
pub(crate) index_url: Option<Maybe<IndexUrl>>,

/// Extra URLs of package indexes to use, in addition to `--index-url`.
///
/// All indexes given via this flag take priority over the index
/// in `--index-url` (which defaults to PyPI). And when multiple
/// `--extra-index-url` flags are given, earlier values take priority.
///
/// Unlike `pip`, `uv` will stop looking for versions of a package as soon
/// as it finds it in an index. That is, it isn't possible for `uv` to
/// consider versions of the same package across multiple indexes.
#[arg(long, env = "UV_EXTRA_INDEX_URL", value_delimiter = ' ', value_parser = parse_index_url)]
pub(crate) extra_index_url: Option<Vec<Maybe<IndexUrl>>>,

/// Locations to search for candidate distributions, beyond those found in the indexes.
///
/// If a path, the target must be a directory that contains package as wheel files (`.whl`) or
/// source distributions (`.tar.gz` or `.zip`) at the top level.
///
/// If a URL, the page must contain a flat list of links to package files.
#[arg(long, short)]
pub(crate) find_links: Option<Vec<FlatIndexLocation>>,

/// Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those
/// discovered via `--find-links`.
#[arg(long)]
pub(crate) no_index: bool,

/// The Python interpreter to use to build the run environment.
///
/// By default, `uv` uses the virtual environment in the current working directory or any parent
/// directory, falling back to searching for a Python executable in `PATH`. The `--python`
/// option allows you to specify a different interpreter.
///
/// Supported formats:
/// - `3.10` looks for an installed Python 3.10 using `py --list-paths` on Windows, or
/// `python3.10` on Linux and macOS.
/// - `python3.10` or `python.exe` looks for a binary with the given name in `PATH`.
/// - `/home/ferris/.local/bin/python3.10` uses the exact Python at the given path.
#[arg(long, short, env = "UV_PYTHON", verbatim_doc_comment)]
pub(crate) python: Option<String>,
}
7 changes: 5 additions & 2 deletions crates/uv/src/commands/project/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::printer::Printer;
/// Resolve the project requirements into a lockfile.
#[allow(clippy::too_many_arguments)]
pub(crate) async fn lock(
index_locations: IndexLocations,
upgrade: Upgrade,
exclude_newer: Option<ExcludeNewer>,
preview: PreviewMode,
Expand All @@ -45,6 +46,7 @@ pub(crate) async fn lock(
match do_lock(
&project,
&venv,
&index_locations,
upgrade,
exclude_newer,
preview,
Expand All @@ -67,9 +69,11 @@ pub(crate) async fn lock(
}

/// Lock the project requirements into a lockfile.
#[allow(clippy::too_many_arguments)]
pub(super) async fn do_lock(
project: &ProjectWorkspace,
venv: &PythonEnvironment,
index_locations: &IndexLocations,
upgrade: Upgrade,
exclude_newer: Option<ExcludeNewer>,
preview: PreviewMode,
Expand Down Expand Up @@ -107,7 +111,6 @@ pub(super) async fn do_lock(
let flat_index = FlatIndex::default();
let in_flight = InFlight::default();
let index = InMemoryIndex::default();
let index_locations = IndexLocations::default();
let link_mode = LinkMode::default();
let no_binary = NoBinary::default();
let no_build = NoBuild::default();
Expand All @@ -128,7 +131,7 @@ pub(super) async fn do_lock(
&client,
cache,
&interpreter,
&index_locations,
index_locations,
&flat_index,
&index,
&git,
Expand Down
8 changes: 4 additions & 4 deletions crates/uv/src/commands/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub(crate) fn init_environment(
pub(crate) async fn update_environment(
venv: PythonEnvironment,
requirements: &[RequirementsSource],
index_locations: &IndexLocations,
connectivity: Connectivity,
cache: &Cache,
printer: Printer,
Expand Down Expand Up @@ -172,7 +173,6 @@ pub(crate) async fn update_environment(
let hasher = HashStrategy::default();
let in_flight = InFlight::default();
let index = InMemoryIndex::default();
let index_locations = IndexLocations::default();
let link_mode = LinkMode::default();
let no_binary = NoBinary::default();
let no_build = NoBuild::default();
Expand All @@ -187,7 +187,7 @@ pub(crate) async fn update_environment(
&client,
cache,
&interpreter,
&index_locations,
index_locations,
&flat_index,
&index,
&git,
Expand Down Expand Up @@ -245,7 +245,7 @@ pub(crate) async fn update_environment(
&client,
cache,
&interpreter,
&index_locations,
index_locations,
&flat_index,
&index,
&git,
Expand All @@ -270,7 +270,7 @@ pub(crate) async fn update_environment(
&no_binary,
link_mode,
compile,
&index_locations,
index_locations,
&hasher,
tags,
&client,
Expand Down
27 changes: 24 additions & 3 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::ffi::OsString;
use std::path::PathBuf;

use anyhow::{Context, Result};
use distribution_types::IndexLocations;
use itertools::Itertools;
use tempfile::tempdir_in;
use tokio::process::Command;
Expand All @@ -23,6 +24,7 @@ use crate::printer::Printer;
/// Run a command.
#[allow(clippy::too_many_arguments)]
pub(crate) async fn run(
index_locations: IndexLocations,
extras: ExtrasSpecification,
target: Option<String>,
mut args: Vec<OsString>,
Expand Down Expand Up @@ -64,14 +66,25 @@ pub(crate) async fn run(
let lock = project::lock::do_lock(
&project,
&venv,
&index_locations,
upgrade,
exclude_newer,
preview,
cache,
printer,
)
.await?;
project::sync::do_sync(&project, &venv, &lock, extras, preview, cache, printer).await?;
project::sync::do_sync(
&project,
&venv,
&lock,
&index_locations,
extras,
preview,
cache,
printer,
)
.await?;

Some(venv)
};
Expand Down Expand Up @@ -113,8 +126,16 @@ pub(crate) async fn run(

// Install the ephemeral requirements.
Some(
project::update_environment(venv, &requirements, connectivity, cache, printer, preview)
.await?,
project::update_environment(
venv,
&requirements,
&index_locations,
connectivity,
cache,
printer,
preview,
)
.await?,
)
};

Expand Down
Loading
Loading