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 tool dir and toolchain dir commands #4695

Merged
merged 4 commits into from
Jul 1, 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
5 changes: 5 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,8 @@ pub enum ToolCommand {
List(ToolListArgs),
/// Uninstall a tool.
Uninstall(ToolUninstallArgs),
/// Show the tools directory.
Dir,
}

#[derive(Args)]
Expand Down Expand Up @@ -2001,6 +2003,9 @@ pub enum ToolchainCommand {
/// Search for a toolchain
#[command(disable_version_flag = true)]
Find(ToolchainFindArgs),

/// Show the toolchains directory.
Dir,
}

#[derive(Args)]
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/cache_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ use uv_fs::Simplified;

/// Show the cache directory.
pub(crate) fn cache_dir(cache: &Cache) {
anstream::println!("{}", cache.root().user_display().cyan());
anstream::println!("{}", cache.root().simplified_display().cyan());
}
2 changes: 2 additions & 0 deletions crates/uv/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ pub(crate) use project::run::run;
pub(crate) use project::sync::sync;
#[cfg(feature = "self-update")]
pub(crate) use self_update::self_update;
pub(crate) use tool::dir::dir as tool_dir;
pub(crate) use tool::install::install as tool_install;
pub(crate) use tool::list::list as tool_list;
pub(crate) use tool::run::run as tool_run;
pub(crate) use tool::uninstall::uninstall as tool_uninstall;
pub(crate) use toolchain::dir::dir as toolchain_dir;
pub(crate) use toolchain::find::find as toolchain_find;
pub(crate) use toolchain::install::install as toolchain_install;
pub(crate) use toolchain::list::list as toolchain_list;
Expand Down
17 changes: 17 additions & 0 deletions crates/uv/src/commands/tool/dir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use anyhow::Context;
use owo_colors::OwoColorize;
use uv_configuration::PreviewMode;
use uv_fs::Simplified;
use uv_tool::InstalledTools;
use uv_warnings::warn_user_once;

/// Show the tool directory.
pub(crate) fn dir(preview: PreviewMode) -> anyhow::Result<()> {
if preview.is_disabled() {
warn_user_once!("`uv tool dir` is experimental and may change without warning.");
}
let installed_tools =
InstalledTools::from_settings().context("Failed to initialize tools settings")?;
anstream::println!("{}", installed_tools.root().simplified_display().cyan());
Ok(())
}
1 change: 1 addition & 0 deletions crates/uv/src/commands/tool/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub(crate) mod dir;
pub(crate) mod install;
pub(crate) mod list;
pub(crate) mod run;
Expand Down
20 changes: 20 additions & 0 deletions crates/uv/src/commands/toolchain/dir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use anyhow::Context;
use owo_colors::OwoColorize;
use uv_configuration::PreviewMode;
use uv_fs::Simplified;
use uv_toolchain::managed::InstalledToolchains;
use uv_warnings::warn_user_once;

/// Show the toolchain directory.
pub(crate) fn dir(preview: PreviewMode) -> anyhow::Result<()> {
if preview.is_disabled() {
warn_user_once!("`uv toolchain dir` is experimental and may change without warning.");
}
let installed_toolchains =
InstalledToolchains::from_settings().context("Failed to initialize toolchain settings")?;
anstream::println!(
"{}",
installed_toolchains.root().simplified_display().cyan()
);
Ok(())
}
1 change: 1 addition & 0 deletions crates/uv/src/commands/toolchain/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub(crate) mod dir;
pub(crate) mod find;
pub(crate) mod install;
pub(crate) mod list;
12 changes: 12 additions & 0 deletions crates/uv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,12 @@ async fn run() -> Result<ExitStatus> {

commands::tool_uninstall(args.name, globals.preview, printer).await
}
Commands::Tool(ToolNamespace {
command: ToolCommand::Dir,
}) => {
commands::tool_dir(globals.preview)?;
Ok(ExitStatus::Success)
}
Commands::Toolchain(ToolchainNamespace {
command: ToolchainCommand::List(args),
}) => {
Expand Down Expand Up @@ -908,6 +914,12 @@ async fn run() -> Result<ExitStatus> {
)
.await
}
Commands::Toolchain(ToolchainNamespace {
command: ToolchainCommand::Dir,
}) => {
commands::toolchain_dir(globals.preview)?;
Ok(ExitStatus::Success)
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions crates/uv/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,14 @@ impl TestContext {
command
}

/// Create a `uv toolchain dir` command with options shared across scenarios.
pub fn toolchain_dir(&self) -> Command {
let mut command = Command::new(get_bin());
command.arg("toolchain").arg("dir");
self.add_shared_args(&mut command);
command
}

/// Create a `uv run` command with options shared across scenarios.
pub fn run(&self) -> Command {
let mut command = Command::new(get_bin());
Expand Down Expand Up @@ -420,6 +428,14 @@ impl TestContext {
command
}

/// Create a `uv tool dir` command with options shared across scenarios.
pub fn tool_dir(&self) -> Command {
let mut command = Command::new(get_bin());
command.arg("tool").arg("dir");
self.add_shared_args(&mut command);
command
}

/// 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());
Expand Down
25 changes: 25 additions & 0 deletions crates/uv/tests/tool_dir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#![cfg(all(feature = "python", feature = "pypi"))]

use assert_fs::fixture::PathChild;
use common::{uv_snapshot, TestContext};

mod common;

#[test]
fn tool_dir() {
let context = TestContext::new("3.12");
let tool_dir = context.temp_dir.child("tools");
let bin_dir = context.temp_dir.child("bin");

uv_snapshot!(context.filters(), context.tool_dir()
.env("UV_TOOL_DIR", tool_dir.as_os_str())
.env("XDG_BIN_HOME", bin_dir.as_os_str()), @r###"
success: true
exit_code: 0
----- stdout -----
[TEMP_DIR]/tools

----- stderr -----
warning: `uv tool dir` is experimental and may change without warning.
"###);
}
23 changes: 23 additions & 0 deletions crates/uv/tests/toolchain_dir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![cfg(all(feature = "python", feature = "pypi"))]

use assert_fs::fixture::PathChild;
use common::{uv_snapshot, TestContext};

mod common;

#[test]
fn toolchain_dir() {
let context = TestContext::new("3.12");

let toolchain_dir = context.temp_dir.child("toolchains");
uv_snapshot!(context.filters(), context.toolchain_dir()
.env("UV_TOOLCHAIN_DIR", toolchain_dir.as_os_str()), @r###"
success: true
exit_code: 0
----- stdout -----
[TEMP_DIR]/toolchains

----- stderr -----
warning: `uv toolchain dir` is experimental and may change without warning.
"###);
}
Loading