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

feature/print-path #7407

Closed
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
191 changes: 191 additions & 0 deletions crates/uv/src/commands/pip/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,180 @@ impl Changelog {
/// Install a set of requirements into the current environment.
///
/// Returns a [`Changelog`] summarizing the changes made to the environment.
// pub(crate) async fn install(
// resolution: &Resolution,
// site_packages: SitePackages,
// modifications: Modifications,
// reinstall: &Reinstall,
// build_options: &BuildOptions,
// link_mode: LinkMode,
// compile: bool,
// index_urls: &IndexLocations,
// config_settings: &ConfigSettings,
// hasher: &HashStrategy,
// markers: &ResolverMarkerEnvironment,
// tags: &Tags,
// client: &RegistryClient,
// in_flight: &InFlight,
// concurrency: Concurrency,
// build_dispatch: &BuildDispatch<'_>,
// cache: &Cache,
// venv: &PythonEnvironment,
// logger: Box<dyn InstallLogger>,
// dry_run: bool,
// printer: Printer,
// ) -> Result<Changelog, Error> {
// let start = std::time::Instant::now();

// // Extract the requirements from the resolution.
// let requirements = resolution.requirements().collect::<Vec<_>>();

// // Partition into those that should be linked from the cache (`local`), those that need to be
// // downloaded (`remote`), and those that should be removed (`extraneous`).
// let plan = Planner::new(&requirements)
// .build(
// site_packages,
// reinstall,
// build_options,
// hasher,
// index_urls,
// config_settings,
// cache,
// venv,
// markers,
// tags,
// )
// .context("Failed to determine installation plan")?;

// if dry_run {
// report_dry_run(resolution, plan, modifications, start, printer)?;
// return Ok(Changelog::default());
// }

// let Plan {
// cached,
// remote,
// reinstalls,
// extraneous,
// } = plan;

// // If we're in `install` mode, ignore any extraneous distributions.
// let extraneous = match modifications {
// Modifications::Sufficient => vec![],
// Modifications::Exact => extraneous,
// };

// // Nothing to do.
// if remote.is_empty() && cached.is_empty() && reinstalls.is_empty() && extraneous.is_empty() {
// logger.on_audit(resolution.len(), start, printer)?;
// return Ok(Changelog::default());
// }

// // Map any registry-based requirements back to those returned by the resolver.
// let remote = remote
// .iter()
// .map(|dist| {
// resolution
// .get_remote(&dist.name)
// .cloned()
// .expect("Resolution should contain all packages")
// })
// .collect::<Vec<_>>();

// // Download, build, and unzip any missing distributions.
// let wheels = if remote.is_empty() {
// vec![]
// } else {
// let start = std::time::Instant::now();

// let preparer = Preparer::new(
// cache,
// tags,
// hasher,
// build_options,
// DistributionDatabase::new(client, build_dispatch, concurrency.downloads),
// )
// .with_reporter(PrepareReporter::from(printer).with_length(remote.len() as u64));

// let wheels = preparer
// .prepare(remote.clone(), in_flight)
// .await
// .context("Failed to prepare distributions")?;

// logger.on_prepare(wheels.len(), start, printer)?;

// wheels
// };

// // Remove any upgraded or extraneous installations.
// let uninstalls = extraneous.into_iter().chain(reinstalls).collect::<Vec<_>>();
// if !uninstalls.is_empty() {
// let start = std::time::Instant::now();

// for dist_info in &uninstalls {
// match uv_installer::uninstall(dist_info).await {
// Ok(summary) => {
// debug!(
// "Uninstalled {} ({} file{}, {} director{})",
// dist_info.name(),
// summary.file_count,
// if summary.file_count == 1 { "" } else { "s" },
// summary.dir_count,
// if summary.dir_count == 1 { "y" } else { "ies" },
// );
// }
// Err(uv_installer::UninstallError::Uninstall(
// install_wheel_rs::Error::MissingRecord(_),
// )) => {
// warn_user!(
// "Failed to uninstall package at {} due to missing `RECORD` file. Installation may result in an incomplete environment.",
// dist_info.path().user_display().cyan(),
// );
// }
// Err(uv_installer::UninstallError::Uninstall(
// install_wheel_rs::Error::MissingTopLevel(_),
// )) => {
// warn_user!(
// "Failed to uninstall package at {} due to missing `top-level.txt` file. Installation may result in an incomplete environment.",
// dist_info.path().user_display().cyan(),
// );
// }
// Err(err) => return Err(err.into()),
// }
// }

// logger.on_uninstall(uninstalls.len(), start, printer)?;
// }

// // Install the resolved distributions.
// let mut installs = wheels.into_iter().chain(cached).collect::<Vec<_>>();
// if !installs.is_empty() {
// let start = std::time::Instant::now();
// installs = uv_installer::Installer::new(venv)
// .with_link_mode(link_mode)
// .with_cache(cache)
// .with_reporter(InstallReporter::from(printer).with_length(installs.len() as u64))
// // This technically can block the runtime, but we are on the main thread and
// // have no other running tasks at this point, so this lets us avoid spawning a blocking
// // task.
// .install_blocking(installs)?;

// logger.on_install(installs.len(), start, printer)?;
// }

// if compile {
// compile_bytecode(venv, cache, printer).await?;
// }

// // Construct a summary of the changes made to the environment.
// let changelog = Changelog::new(installs, uninstalls);

// // Notify the user of any environment modifications.
// logger.on_complete(&changelog, printer)?;

// Ok(changelog)
// }

pub(crate) async fn install(
resolution: &Resolution,
site_packages: SitePackages,
Expand All @@ -366,6 +540,23 @@ pub(crate) async fn install(
) -> Result<Changelog, Error> {
let start = std::time::Instant::now();

// Print the environment path
let python_executable = venv.python_executable();
let venv_dir = PathBuf::from(".venv");
let venv_dir_canonical = venv_dir.canonicalize().unwrap_or(venv_dir);
let is_outside_working_directory = !(python_executable.starts_with(venv_dir_canonical));
if is_outside_working_directory {
writeln!(
printer.stderr(),
"{}",
format!(
"Installing to environment at {}",
python_executable.user_display()
)
.dimmed()
)?;
}

// Extract the requirements from the resolution.
let requirements = resolution.requirements().collect::<Vec<_>>();

Expand Down
45 changes: 27 additions & 18 deletions crates/uv/tests/branching_urls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ fn branching_urls_disjoint() -> Result<()> {
"# };
make_project(context.temp_dir.path(), "a", deps)?;

uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r###"
uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r#"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
warning: `VIRTUAL_ENV=[WORKSPACE]/.venv` does not match the project environment path `.venv` and will be ignored
Resolved 3 packages in [TIME]
"###
"#
);

Ok(())
Expand All @@ -61,16 +62,17 @@ fn branching_urls_overlapping() -> Result<()> {
"# };
make_project(context.temp_dir.path(), "a", deps)?;

uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r###"
uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r#"
success: false
exit_code: 2
----- stdout -----

----- stderr -----
warning: `VIRTUAL_ENV=[WORKSPACE]/.venv` does not match the project environment path `.venv` and will be ignored
error: Requirements contain conflicting URLs for package `iniconfig` in split `python_full_version == '3.11.*'`:
- https://files.pythonhosted.org/packages/9b/dd/b3c12c6d707058fa947864b67f0c4e0c39ef8610988d7baea9578f3c48f3/iniconfig-1.1.1-py2.py3-none-any.whl
- https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl
"###
"#
);

Ok(())
Expand Down Expand Up @@ -127,16 +129,17 @@ fn root_package_splits_but_transitive_conflict() -> Result<()> {
"# };
make_project(&context.temp_dir.path().join("b2"), "b2", deps)?;

uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r###"
uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r#"
success: false
exit_code: 2
----- stdout -----

----- stderr -----
warning: `VIRTUAL_ENV=[WORKSPACE]/.venv` does not match the project environment path `.venv` and will be ignored
error: Requirements contain conflicting URLs for package `iniconfig` in split `python_full_version < '3.12'`:
- https://files.pythonhosted.org/packages/9b/dd/b3c12c6d707058fa947864b67f0c4e0c39ef8610988d7baea9578f3c48f3/iniconfig-1.1.1-py2.py3-none-any.whl
- https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl
"###
"#
);

Ok(())
Expand Down Expand Up @@ -195,14 +198,15 @@ fn root_package_splits_transitive_too() -> Result<()> {
"# };
make_project(&context.temp_dir.path().join("b2"), "b2", deps)?;

uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r###"
uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r#"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
warning: `VIRTUAL_ENV=[WORKSPACE]/.venv` does not match the project environment path `.venv` and will be ignored
Resolved 10 packages in [TIME]
"###
"#
);

assert_snapshot!(fs_err::read_to_string(context.temp_dir.join("uv.lock"))?, @r###"
Expand Down Expand Up @@ -390,14 +394,15 @@ fn root_package_splits_other_dependencies_too() -> Result<()> {
"# };
make_project(&context.temp_dir.path().join("b2"), "b2", deps)?;

uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r###"
uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r#"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
warning: `VIRTUAL_ENV=[WORKSPACE]/.venv` does not match the project environment path `.venv` and will be ignored
Resolved 9 packages in [TIME]
"###
"#
);

assert_snapshot!(fs_err::read_to_string(context.temp_dir.join("uv.lock"))?, @r###"
Expand Down Expand Up @@ -550,14 +555,15 @@ fn branching_between_registry_and_direct_url() -> Result<()> {
"# };
make_project(context.temp_dir.path(), "a", deps)?;

uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r###"
uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r#"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
warning: `VIRTUAL_ENV=[WORKSPACE]/.venv` does not match the project environment path `.venv` and will be ignored
Resolved 3 packages in [TIME]
"###
"#
);

// We have source dist and wheel for the registry, but only the wheel for the direct URL.
Expand Down Expand Up @@ -635,14 +641,15 @@ fn branching_urls_of_different_sources_disjoint() -> Result<()> {
"# };
make_project(context.temp_dir.path(), "a", deps)?;

uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r###"
uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r#"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
warning: `VIRTUAL_ENV=[WORKSPACE]/.venv` does not match the project environment path `.venv` and will be ignored
Resolved 3 packages in [TIME]
"###
"#
);

// We have source dist and wheel for the registry, but only the wheel for the direct URL.
Expand Down Expand Up @@ -717,16 +724,17 @@ fn branching_urls_of_different_sources_conflict() -> Result<()> {
"# };
make_project(context.temp_dir.path(), "a", deps)?;

uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r###"
uv_snapshot!(context.filters(), context.lock().current_dir(&context.temp_dir), @r#"
success: false
exit_code: 2
----- stdout -----

----- stderr -----
warning: `VIRTUAL_ENV=[WORKSPACE]/.venv` does not match the project environment path `.venv` and will be ignored
error: Requirements contain conflicting URLs for package `iniconfig` in split `python_full_version == '3.11.*'`:
- git+https://github.com/pytest-dev/iniconfig@93f5930e668c0d1ddf4597e38dd0dea4e2665e7a
- https://files.pythonhosted.org/packages/9b/dd/b3c12c6d707058fa947864b67f0c4e0c39ef8610988d7baea9578f3c48f3/iniconfig-1.1.1-py2.py3-none-any.whl
"###
"#
);

Ok(())
Expand Down Expand Up @@ -763,14 +771,15 @@ fn dont_pre_visit_url_packages() -> Result<()> {
" };
make_project(&context.temp_dir.join("c"), "c", deps)?;

uv_snapshot!(context.filters(), context.lock().arg("--offline").current_dir(&context.temp_dir), @r###"
uv_snapshot!(context.filters(), context.lock().arg("--offline").current_dir(&context.temp_dir), @r#"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
warning: `VIRTUAL_ENV=[WORKSPACE]/.venv` does not match the project environment path `.venv` and will be ignored
Resolved 3 packages in [TIME]
"###
"#
);

assert_snapshot!(fs_err::read_to_string(context.temp_dir.join("uv.lock"))?, @r###"
Expand Down
Loading
Loading