Skip to content

Commit

Permalink
Suppress resolver output by default in uv run
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jul 30, 2024
1 parent 3e32902 commit 439fe6c
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 56 deletions.
8 changes: 8 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,10 @@ pub struct RunArgs {
#[arg(long, value_parser = parse_maybe_file_path)]
pub with_requirements: Vec<Maybe<PathBuf>>,

/// Whether to show resolver and installer output from any environment modifications.
#[arg(long)]
pub show_environment: bool,

/// Assert that the `uv.lock` will remain unchanged.
#[arg(long, conflicts_with = "frozen")]
pub locked: bool,
Expand Down Expand Up @@ -2283,6 +2287,10 @@ pub struct ToolRunArgs {
#[arg(long, value_parser = parse_maybe_file_path)]
pub with_requirements: Vec<Maybe<PathBuf>>,

/// Whether to show resolver and installer output from any environment modifications.
#[arg(long)]
pub show_environment: bool,

#[command(flatten)]
pub installer: ResolverInstallerArgs,

Expand Down
13 changes: 7 additions & 6 deletions crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::settings::ResolverInstallerSettings;
pub(crate) async fn run(
command: ExternalCommand,
requirements: Vec<RequirementsSource>,
show_environment: bool,
locked: bool,
frozen: bool,
package: Option<PackageName>,
Expand Down Expand Up @@ -88,7 +89,7 @@ pub(crate) async fn run(
// Initialize any shared state.
let state = SharedState::default();

let reporter = PythonDownloadReporter::single(printer);
let reporter = PythonDownloadReporter::single(printer.filter(show_environment));

let directory = if let Some(directory) = directory {
directory.simple_canonicalize()?
Expand Down Expand Up @@ -151,7 +152,7 @@ pub(crate) async fn run(
concurrency,
native_tls,
cache,
printer,
printer.filter(show_environment),
)
.await?;

Expand Down Expand Up @@ -209,7 +210,7 @@ pub(crate) async fn run(
connectivity,
native_tls,
cache,
printer,
printer.filter(show_environment),
)
.await?;

Expand All @@ -225,7 +226,7 @@ pub(crate) async fn run(
concurrency,
native_tls,
cache,
printer,
printer.filter(show_environment),
)
.await
{
Expand Down Expand Up @@ -254,7 +255,7 @@ pub(crate) async fn run(
concurrency,
native_tls,
cache,
printer,
printer.filter(show_environment),
)
.await?;

Expand Down Expand Up @@ -410,7 +411,7 @@ pub(crate) async fn run(
concurrency,
native_tls,
cache,
printer,
printer.filter(show_environment),
)
.await?,
)
Expand Down
7 changes: 4 additions & 3 deletions crates/uv/src/commands/tool/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::commands::reporters::PythonDownloadReporter;

use crate::commands::project::resolve_names;
use crate::commands::{
project, project::environment::CachedEnvironment, tool::common::matching_packages, tool_list,
project::environment::CachedEnvironment, tool::common::matching_packages, tool_list,
};
use crate::commands::{ExitStatus, SharedState};
use crate::printer::Printer;
Expand Down Expand Up @@ -59,6 +59,7 @@ pub(crate) async fn run(
command: Option<ExternalCommand>,
from: Option<String>,
with: &[RequirementsSource],
show_environment: bool,
python: Option<String>,
settings: ResolverInstallerSettings,
invocation_source: ToolRunCommand,
Expand Down Expand Up @@ -106,7 +107,7 @@ pub(crate) async fn run(
concurrency,
native_tls,
cache,
printer,
printer.filter(show_environment),
)
.await?;

Expand Down Expand Up @@ -315,7 +316,7 @@ async fn get_or_create_environment(

// Resolve the `from` requirement.
let from = {
project::resolve_names(
resolve_names(
vec![RequirementsSpecification::parse_package(from)?],
&interpreter,
settings,
Expand Down
2 changes: 2 additions & 0 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
args.command,
args.from,
&requirements,
args.show_environment,
args.python,
args.settings,
invocation_source,
Expand Down Expand Up @@ -909,6 +910,7 @@ async fn run_project(
commands::run(
args.command,
requirements,
args.show_environment,
args.locked,
args.frozen,
args.package,
Expand Down
10 changes: 10 additions & 0 deletions crates/uv/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ impl Printer {
Self::NoProgress => Stderr::Enabled,
}
}

/// Filter the [`Printer`], casting to [`Printer::Quiet`] if the condition is false.
#[must_use]
pub(crate) fn filter(self, condition: bool) -> Self {
if condition {
self
} else {
Self::Quiet
}
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down
10 changes: 8 additions & 2 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ pub(crate) struct RunSettings {
pub(crate) command: ExternalCommand,
pub(crate) with: Vec<String>,
pub(crate) with_requirements: Vec<PathBuf>,
pub(crate) show_environment: bool,
pub(crate) package: Option<PackageName>,
pub(crate) python: Option<String>,
pub(crate) directory: Option<PathBuf>,
Expand All @@ -203,8 +204,6 @@ impl RunSettings {
#[allow(clippy::needless_pass_by_value)]
pub(crate) fn resolve(args: RunArgs, filesystem: Option<FilesystemOptions>) -> Self {
let RunArgs {
locked,
frozen,
extra,
all_extras,
no_all_extras,
Expand All @@ -213,6 +212,9 @@ impl RunSettings {
command,
with,
with_requirements,
show_environment,
locked,
frozen,
installer,
build,
refresh,
Expand All @@ -235,6 +237,7 @@ impl RunSettings {
.into_iter()
.filter_map(Maybe::into_option)
.collect(),
show_environment,
package,
python,
directory,
Expand All @@ -255,6 +258,7 @@ pub(crate) struct ToolRunSettings {
pub(crate) from: Option<String>,
pub(crate) with: Vec<String>,
pub(crate) with_requirements: Vec<PathBuf>,
pub(crate) show_environment: bool,
pub(crate) python: Option<String>,
pub(crate) refresh: Refresh,
pub(crate) settings: ResolverInstallerSettings,
Expand All @@ -269,6 +273,7 @@ impl ToolRunSettings {
from,
with,
with_requirements,
show_environment,
installer,
build,
refresh,
Expand All @@ -283,6 +288,7 @@ impl ToolRunSettings {
.into_iter()
.filter_map(Maybe::into_option)
.collect(),
show_environment,
python,
refresh: Refresh::from(refresh),
settings: ResolverInstallerSettings::combine(
Expand Down
14 changes: 7 additions & 7 deletions crates/uv/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ impl TestContext {
}

/// Create a `uv tool install` command with options shared across scenarios.
pub fn tool_install(&self) -> std::process::Command {
pub fn tool_install(&self) -> Command {
let mut command = self.tool_install_without_exclude_newer();
command.arg("--exclude-newer").arg(EXCLUDE_NEWER);
command
Expand All @@ -507,16 +507,16 @@ impl TestContext {
/// it can result in tests failing when the index state changes. Therefore,
/// if you use this, there should be some other kind of mitigation in place.
/// For example, pinning package versions.
pub fn tool_install_without_exclude_newer(&self) -> std::process::Command {
let mut command = std::process::Command::new(get_bin());
pub fn tool_install_without_exclude_newer(&self) -> Command {
let mut command = Command::new(get_bin());
command.arg("tool").arg("install");
self.add_shared_args(&mut command);
command
}

/// Create a `uv tool list` command with options shared across scenarios.
pub fn tool_list(&self) -> std::process::Command {
let mut command = std::process::Command::new(get_bin());
pub fn tool_list(&self) -> Command {
let mut command = Command::new(get_bin());
command.arg("tool").arg("list");
self.add_shared_args(&mut command);
command
Expand All @@ -531,8 +531,8 @@ impl TestContext {
}

/// Create a `uv tool uninstall` command with options shared across scenarios.
pub fn tool_uninstall(&self) -> std::process::Command {
let mut command = std::process::Command::new(get_bin());
pub fn tool_uninstall(&self) -> Command {
let mut command = Command::new(get_bin());
command.arg("tool").arg("uninstall");
self.add_shared_args(&mut command);
command
Expand Down
Loading

0 comments on commit 439fe6c

Please sign in to comment.