Skip to content

Commit

Permalink
Remove unstable uv lock from pip interface
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jun 3, 2024
1 parent fbf562d commit 9aba38d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 287 deletions.
9 changes: 0 additions & 9 deletions crates/uv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,6 @@ pub(crate) struct PipCompileArgs {
#[arg(long, overrides_with("emit_index_annotation"), hide = true)]
pub(crate) no_emit_index_annotation: bool,

#[arg(long, overrides_with("no_unstable_uv_lock_file"), hide = true)]
pub(crate) unstable_uv_lock_file: bool,

#[arg(long, overrides_with("unstable_uv_lock_file"), hide = true)]
pub(crate) no_unstable_uv_lock_file: bool,

#[command(flatten)]
pub(crate) compat_args: compat::PipCompileCompatArgs,
}
Expand Down Expand Up @@ -1230,9 +1224,6 @@ pub(crate) struct PipInstallArgs {
#[arg(long)]
pub(crate) dry_run: bool,

#[arg(long, hide = true, group = "sources")]
pub(crate) unstable_uv_lock_file: Option<String>,

#[command(flatten)]
pub(crate) compat_args: compat::PipInstallCompatArgs,
}
Expand Down
28 changes: 6 additions & 22 deletions crates/uv/src/commands/pip/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::str::FromStr;

use anstream::{eprint, AutoStream, StripStream};
use anyhow::{anyhow, Result};
use fs_err as fs;
use itertools::Itertools;
use owo_colors::OwoColorize;
use pypi_types::Requirement;
Expand Down Expand Up @@ -94,7 +93,6 @@ pub(crate) async fn pip_compile(
python: Option<String>,
system: bool,
concurrency: Concurrency,
uv_lock: bool,
native_tls: bool,
quiet: bool,
preview: PreviewMode,
Expand Down Expand Up @@ -252,15 +250,7 @@ pub(crate) async fn pip_compile(
(None, Some(python_version)) => Cow::Owned(python_version.markers(interpreter.markers())),
(None, None) => Cow::Borrowed(interpreter.markers()),
};
// The marker environment to use for evaluating requirements. When
// `uv_lock` is enabled, we specifically do environment independent marker
// evaluation. (i.e., Only consider extras.)
let marker_filter = if uv_lock { None } else { Some(&*markers) };
// The Python requirement in "workspace-aware uv" should, I believe, come
// from the pyproject.toml. For now, we just take it from the markers
// (which does have its Python version set potentially from the CLI, which
// I think is spiritually equivalent to setting the Python version in
// pyproject.toml).

let python_requirement = PythonRequirement::from_marker_environment(&interpreter, &markers);

// Generate, but don't enforce hashes for the requirements.
Expand Down Expand Up @@ -430,7 +420,7 @@ pub(crate) async fn pip_compile(

for requirement in requirements
.iter()
.filter(|requirement| requirement.evaluate_markers(marker_filter, &[]))
.filter(|requirement| requirement.evaluate_markers(Some(&markers), &[]))
{
if let Some(origin) = &requirement.origin {
sources.add(
Expand All @@ -442,7 +432,7 @@ pub(crate) async fn pip_compile(

for requirement in constraints
.iter()
.filter(|requirement| requirement.evaluate_markers(marker_filter, &[]))
.filter(|requirement| requirement.evaluate_markers(Some(&markers), &[]))
{
if let Some(origin) = &requirement.origin {
sources.add(
Expand All @@ -454,7 +444,7 @@ pub(crate) async fn pip_compile(

for requirement in overrides
.iter()
.filter(|requirement| requirement.evaluate_markers(marker_filter, &[]))
.filter(|requirement| requirement.evaluate_markers(Some(&markers), &[]))
{
if let Some(origin) = &requirement.origin {
sources.add(
Expand All @@ -480,7 +470,7 @@ pub(crate) async fn pip_compile(
DistributionDatabase::new(&client, &build_dispatch, concurrency.downloads, preview),
)
.with_reporter(ResolverReporter::from(printer))
.resolve(marker_filter)
.resolve(Some(&markers))
.await?
}
DependencyMode::Direct => Vec::new(),
Expand Down Expand Up @@ -511,7 +501,7 @@ pub(crate) async fn pip_compile(
manifest.clone(),
options,
&python_requirement,
marker_filter,
Some(&markers),
&tags,
&flat_index,
&top_level_index,
Expand Down Expand Up @@ -578,12 +568,6 @@ pub(crate) async fn pip_compile(
writeln!(writer, "{}", format!("# {relevant_markers}").green())?;
}

if uv_lock {
let lock = resolution.lock()?;
let encoded = lock.to_toml()?;
fs::tokio::write("uv.lock", encoded.as_bytes()).await?;
}

// Write the index locations to the output channel.
let mut wrote_index = false;

Expand Down
101 changes: 43 additions & 58 deletions crates/uv/src/commands/pip/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::borrow::Cow;
use std::fmt::Write;

use anstream::eprint;
use fs_err as fs;
use itertools::Itertools;
use owo_colors::OwoColorize;
use tracing::{debug, enabled, Level};
Expand All @@ -24,10 +23,9 @@ use uv_fs::Simplified;
use uv_git::GitResolver;
use uv_installer::{SatisfiesResult, SitePackages};
use uv_interpreter::{PythonEnvironment, PythonVersion, SystemPython, Target};
use uv_normalize::PackageName;
use uv_requirements::{RequirementsSource, RequirementsSpecification};
use uv_resolver::{
DependencyMode, ExcludeNewer, FlatIndex, InMemoryIndex, Lock, OptionsBuilder, PreReleaseMode,
DependencyMode, ExcludeNewer, FlatIndex, InMemoryIndex, OptionsBuilder, PreReleaseMode,
ResolutionMode,
};
use uv_types::{BuildIsolation, HashStrategy, InFlight};
Expand Down Expand Up @@ -71,7 +69,6 @@ pub(crate) async fn pip_install(
break_system_packages: bool,
target: Option<Target>,
concurrency: Concurrency,
uv_lock: Option<String>,
native_tls: bool,
preview: PreviewMode,
cache: Cache,
Expand Down Expand Up @@ -172,12 +169,7 @@ pub(crate) async fn pip_install(
// Check if the current environment satisfies the requirements.
// Ideally, the resolver would be fast enough to let us remove this check. But right now, for large environments,
// it's an order of magnitude faster to validate the environment than to resolve the requirements.
if reinstall.is_none()
&& upgrade.is_none()
&& source_trees.is_empty()
&& overrides.is_empty()
&& uv_lock.is_none()
{
if reinstall.is_none() && upgrade.is_none() && source_trees.is_empty() && overrides.is_empty() {
match site_packages.satisfies(&requirements, &constraints)? {
// If the requirements are already satisfied, we're done.
SatisfiesResult::Fresh {
Expand Down Expand Up @@ -335,56 +327,49 @@ pub(crate) async fn pip_install(
)
.with_options(OptionsBuilder::new().exclude_newer(exclude_newer).build());

let options = OptionsBuilder::new()
.resolution_mode(resolution_mode)
.prerelease_mode(prerelease_mode)
.dependency_mode(dependency_mode)
.exclude_newer(exclude_newer)
.index_strategy(index_strategy)
.build();

// Resolve the requirements.
let resolution = if let Some(ref root) = uv_lock {
let root = PackageName::new(root.to_string())?;
let encoded = fs::tokio::read_to_string("uv.lock").await?;
let lock: Lock = toml::from_str(&encoded)?;
lock.to_resolution(&markers, &tags, &root, &[])
} else {
let options = OptionsBuilder::new()
.resolution_mode(resolution_mode)
.prerelease_mode(prerelease_mode)
.dependency_mode(dependency_mode)
.exclude_newer(exclude_newer)
.index_strategy(index_strategy)
.build();

match operations::resolve(
requirements,
constraints,
overrides,
source_trees,
project,
extras,
preferences,
site_packages.clone(),
&hasher,
&reinstall,
&upgrade,
&interpreter,
&tags,
Some(&markers),
&client,
&flat_index,
&index,
&resolve_dispatch,
concurrency,
options,
printer,
preview,
)
.await
{
Ok(resolution) => Resolution::from(resolution),
Err(operations::Error::Resolve(uv_resolver::ResolveError::NoSolution(err))) => {
let report = miette::Report::msg(format!("{err}"))
.context("No solution found when resolving dependencies:");
eprint!("{report:?}");
return Ok(ExitStatus::Failure);
}
Err(err) => return Err(err.into()),
let resolution = match operations::resolve(
requirements,
constraints,
overrides,
source_trees,
project,
extras,
preferences,
site_packages.clone(),
&hasher,
&reinstall,
&upgrade,
&interpreter,
&tags,
Some(&markers),
&client,
&flat_index,
&index,
&resolve_dispatch,
concurrency,
options,
printer,
preview,
)
.await
{
Ok(resolution) => Resolution::from(resolution),
Err(operations::Error::Resolve(uv_resolver::ResolveError::NoSolution(err))) => {
let report = miette::Report::msg(format!("{err}"))
.context("No solution found when resolving dependencies:");
eprint!("{report:?}");
return Ok(ExitStatus::Failure);
}
Err(err) => return Err(err.into()),
};

// Re-initialize the in-flight map.
Expand Down
2 changes: 0 additions & 2 deletions crates/uv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ async fn run() -> Result<ExitStatus> {
args.shared.python,
args.shared.system,
args.shared.concurrency,
args.uv_lock,
globals.native_tls,
globals.quiet,
globals.preview,
Expand Down Expand Up @@ -374,7 +373,6 @@ async fn run() -> Result<ExitStatus> {
args.shared.break_system_packages,
args.shared.target,
args.shared.concurrency,
args.uv_lock,
globals.native_tls,
globals.preview,
cache,
Expand Down
36 changes: 14 additions & 22 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ pub(crate) struct PipCompileSettings {
pub(crate) r#override: Vec<PathBuf>,
pub(crate) refresh: Refresh,
pub(crate) upgrade: Upgrade,
pub(crate) uv_lock: bool,

// Shared settings.
pub(crate) shared: PipSharedSettings,
Expand Down Expand Up @@ -392,8 +391,6 @@ impl PipCompileSettings {
no_emit_marker_expression,
emit_index_annotation,
no_emit_index_annotation,
unstable_uv_lock_file,
no_unstable_uv_lock_file,
compat_args: _,
} = args;

Expand Down Expand Up @@ -422,7 +419,6 @@ impl PipCompileSettings {
r#override,
refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package),
upgrade: Upgrade::from_args(flag(upgrade, no_upgrade), upgrade_package),
uv_lock: flag(unstable_uv_lock_file, no_unstable_uv_lock_file).unwrap_or(false),
overrides_from_workspace,

// Shared settings.
Expand Down Expand Up @@ -613,7 +609,6 @@ pub(crate) struct PipInstallSettings {
pub(crate) reinstall: Reinstall,
pub(crate) refresh: Refresh,
pub(crate) dry_run: bool,
pub(crate) uv_lock: Option<String>,
pub(crate) overrides_from_workspace: Vec<Requirement>,

// Shared settings.
Expand Down Expand Up @@ -675,25 +670,23 @@ impl PipInstallSettings {
no_strict,
exclude_newer,
dry_run,
unstable_uv_lock_file,
compat_args: _,
} = args;

let overrides_from_workspace: Vec<pypi_types::Requirement> =
if let Some(workspace) = &workspace {
workspace
.options
.override_dependencies
.clone()
.unwrap_or_default()
.into_iter()
.map(|requirement| {
Requirement::from(requirement.with_origin(RequirementOrigin::Workspace))
})
.collect()
} else {
Vec::new()
};
let overrides_from_workspace: Vec<Requirement> = if let Some(workspace) = &workspace {
workspace
.options
.override_dependencies
.clone()
.unwrap_or_default()
.into_iter()
.map(|requirement| {
Requirement::from(requirement.with_origin(RequirementOrigin::Workspace))
})
.collect()
} else {
Vec::new()
};

Self {
// CLI-only settings.
Expand All @@ -709,7 +702,6 @@ impl PipInstallSettings {
reinstall: Reinstall::from_args(flag(reinstall, no_reinstall), reinstall_package),
refresh: Refresh::from_args(flag(refresh, no_refresh), refresh_package),
dry_run,
uv_lock: unstable_uv_lock_file,
overrides_from_workspace,

// Shared settings.
Expand Down
Loading

0 comments on commit 9aba38d

Please sign in to comment.