Skip to content
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
2 changes: 1 addition & 1 deletion crates/uv-install-wheel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ same-file = { workspace = true }
self-replace = { workspace = true }

[dev-dependencies]
anyhow = { version = "1.0.89" }
anyhow = { workspace = true }
assert_fs = { version = "1.1.2" }
indoc = { workspace = true }
14 changes: 10 additions & 4 deletions crates/uv-installer/src/site_packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ impl SitePackages {

for site_packages in interpreter.site_packages() {
// Read the site-packages directory.
let site_packages = match fs::read_dir(site_packages) {
Ok(site_packages) => {
let site_packages = match fs::read_dir(site_packages.as_ref()) {
Ok(read_dir) => {
// Collect sorted directory paths; `read_dir` is not stable across platforms
let dist_likes: BTreeSet<_> = site_packages
let dist_likes: BTreeSet<_> = read_dir
.filter_map(|read_dir| match read_dir {
Ok(entry) => match entry.file_type() {
Ok(file_type) => (file_type.is_dir()
Expand All @@ -71,7 +71,13 @@ impl SitePackages {
},
Err(err) => Some(Err(err)),
})
.collect::<Result<_, std::io::Error>>()?;
.collect::<Result<_, std::io::Error>>()
.with_context(|| {
format!(
"Failed to read site-packages directory contents: {}",
site_packages.user_display()
)
})?;
dist_likes
}
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ windows-result = { workspace = true }
windows-sys = { workspace = true }

[dev-dependencies]
anyhow = { version = "1.0.89" }
anyhow = { workspace = true }
assert_fs = { version = "1.1.2" }
indoc = { workspace = true }
insta = { version = "1.40.0" }
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-requirements-txt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ url = { workspace = true }
http = ["reqwest", "reqwest-middleware"]

[dev-dependencies]
anyhow = { version = "1.0.89" }
anyhow = { workspace = true }
assert_fs = { version = "1.1.2" }
indoc = { workspace = true }
insta = { version = "1.40.0", features = ["filters"] }
Expand Down
12 changes: 8 additions & 4 deletions crates/uv-requirements/src/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ impl RequirementsSource {
let prompt = format!(
"`{name}` looks like a local requirements file but was passed as a package name. Did you mean `-r {name}`?"
);
let confirmation = uv_console::confirm(&prompt, &term, true)?;
let confirmation =
uv_console::confirm(&prompt, &term, true).context("Confirm prompt failed")?;
if confirmation {
return Self::from_requirements_file(name.into());
}
Expand All @@ -190,7 +191,8 @@ impl RequirementsSource {
let prompt = format!(
"`{name}` looks like a local metadata file but was passed as a package name. Did you mean `-r {name}`?"
);
let confirmation = uv_console::confirm(&prompt, &term, true)?;
let confirmation =
uv_console::confirm(&prompt, &term, true).context("Confirm prompt failed")?;
if confirmation {
return Self::from_requirements_file(name.into());
}
Expand Down Expand Up @@ -218,7 +220,8 @@ impl RequirementsSource {
let prompt = format!(
"`{name}` looks like a local requirements file but was passed as a package name. Did you mean `--with-requirements {name}`?"
);
let confirmation = uv_console::confirm(&prompt, &term, true)?;
let confirmation =
uv_console::confirm(&prompt, &term, true).context("Confirm prompt failed")?;
if confirmation {
return Self::from_requirements_file(name.into());
}
Expand All @@ -238,7 +241,8 @@ impl RequirementsSource {
let prompt = format!(
"`{name}` looks like a local metadata file but was passed as a package name. Did you mean `--with-requirements {name}`?"
);
let confirmation = uv_console::confirm(&prompt, &term, true)?;
let confirmation =
uv_console::confirm(&prompt, &term, true).context("Confirm prompt failed")?;
if confirmation {
return Self::from_requirements_file(name.into());
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-trampoline-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ zip = { workspace = true }
[dev-dependencies]
assert_cmd = { version = "2.0.16" }
assert_fs = { version = "1.1.2" }
anyhow = { version = "1.0.89" }
anyhow = { workspace = true }
fs-err = { workspace = true }
which = { workspace = true }
7 changes: 3 additions & 4 deletions crates/uv/src/commands/build_frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ async fn build_impl(
let workspace = match workspace {
Ok(ref workspace) => workspace,
Err(err) => {
return Err(anyhow::Error::from(err)
.context("`--package` was provided, but no workspace was found"));
return Err(err).context("`--package` was provided, but no workspace was found");
}
};

Expand Down Expand Up @@ -289,8 +288,8 @@ async fn build_impl(
let workspace = match workspace {
Ok(ref workspace) => workspace,
Err(err) => {
return Err(anyhow::Error::from(err)
.context("`--all-packages` was provided, but no workspace was found"));
return Err(err)
.context("`--all-packages` was provided, but no workspace was found");
}
};

Expand Down
4 changes: 3 additions & 1 deletion crates/uv/src/commands/pip/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::fmt::Write;
use std::path::PathBuf;
use std::sync::Arc;

use anyhow::Context;
use itertools::Itertools;
use owo_colors::OwoColorize;
use tracing::{debug, enabled, Level};
Expand Down Expand Up @@ -437,7 +438,8 @@ pub(crate) async fn pip_install(
let install_path = std::path::absolute(&pylock)?;
let install_path = install_path.parent().unwrap();
let content = fs_err::tokio::read_to_string(&pylock).await?;
let lock = toml::from_str::<PylockToml>(&content)?;
let lock = toml::from_str::<PylockToml>(&content)
.with_context(|| format!("Not a valid pylock.toml file: {}", pylock.user_display()))?;

let resolution =
lock.to_resolution(install_path, marker_env.markers(), &tags, &build_options)?;
Expand Down
5 changes: 3 additions & 2 deletions crates/uv/src/commands/pip/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::{BTreeMap, BTreeSet};
use std::fmt::Write;
use std::sync::Arc;

use anyhow::Result;
use anyhow::{Context, Result};
use owo_colors::OwoColorize;
use tracing::debug;

Expand Down Expand Up @@ -372,7 +372,8 @@ pub(crate) async fn pip_sync(
let install_path = std::path::absolute(&pylock)?;
let install_path = install_path.parent().unwrap();
let content = fs_err::tokio::read_to_string(&pylock).await?;
let lock = toml::from_str::<PylockToml>(&content)?;
let lock = toml::from_str::<PylockToml>(&content)
.with_context(|| format!("Not a valid pylock.toml file: {}", pylock.user_display()))?;

let resolution =
lock.to_resolution(install_path, marker_env.markers(), &tags, &build_options)?;
Expand Down
20 changes: 12 additions & 8 deletions crates/uv/src/commands/project/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,12 @@ async fn init_script(
}
Err(err) if err.kind() == std::io::ErrorKind::NotFound => None,
Err(err) => {
return Err(anyhow::Error::from(err).context(format!(
"Failed to read script at `{}`",
script_path.simplified_display().cyan()
)));
return Err(err).with_context(|| {
format!(
"Failed to read script at `{}`",
script_path.simplified_display().cyan()
)
});
}
};

Expand Down Expand Up @@ -328,10 +330,12 @@ async fn init_project(
warn!("Ignoring workspace discovery error due to `--no-workspace`: {err}");
None
} else {
return Err(anyhow::Error::from(err).context(format!(
"Failed to discover parent workspace; use `{}` to ignore",
"uv init --no-workspace".green()
)));
return Err(err).with_context(|| {
format!(
"Failed to discover parent workspace; use `{}` to ignore",
"uv init --no-workspace".green()
)
});
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions crates/uv/src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::commands::ExitStatus;
use tokio::process::Child;
use tracing::debug;

use crate::commands::ExitStatus;

/// Wait for the child process to complete, handling signals and error codes.
///
/// Note that this registers handles to ignore some signals in the parent process. This is safe as
Expand Down Expand Up @@ -39,6 +40,7 @@ pub(crate) async fn run_to_completion(mut handle: Child) -> anyhow::Result<ExitS
let status = {
use std::ops::Deref;

use anyhow::Context;
use nix::sys::signal;
use nix::unistd::{getpgid, Pid};
use tokio::select;
Expand Down Expand Up @@ -85,7 +87,7 @@ pub(crate) async fn run_to_completion(mut handle: Child) -> anyhow::Result<ExitS
}

// Get the parent PGID
let parent_pgid = getpgid(None)?;
let parent_pgid = getpgid(None).context("Failed to get current PID")?;
if let Some(child_pid) = *ChildPid::from(&handle) {
debug!("Spawned child {child_pid} in process group {parent_pgid}");
}
Expand Down Expand Up @@ -147,7 +149,7 @@ pub(crate) async fn run_to_completion(mut handle: Child) -> anyhow::Result<ExitS
};

// Check if the child pgid has changed
let child_pgid = getpgid(Some(child_pid))?;
let child_pgid = getpgid(Some(child_pid)).context("Failed to get PID of child process")?;

// Increment the number of interrupts seen
sigint_count += 1;
Expand Down
3 changes: 2 additions & 1 deletion crates/uv/src/commands/tool/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ pub(crate) async fn run(
.iter()
.flat_map(std::env::split_paths),
),
)?;
)
.context("Failed to build new PATH variable")?;
process.env(EnvVars::PATH, new_path);

// Spawn and wait for completion
Expand Down
Loading