diff --git a/crates/uv-auth/src/store.rs b/crates/uv-auth/src/store.rs index edaebac89..7a981586c 100644 --- a/crates/uv-auth/src/store.rs +++ b/crates/uv-auth/src/store.rs @@ -182,7 +182,7 @@ pub struct TextCredentialStore { impl TextCredentialStore { /// Return the directory for storing credentials. - fn directory_path() -> Result { + pub fn directory_path() -> Result { if let Some(dir) = std::env::var_os(EnvVars::UV_CREDENTIALS_DIR) .filter(|s| !s.is_empty()) .map(PathBuf::from) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 9a5c112b1..c272ea60e 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -4408,6 +4408,17 @@ pub enum AuthCommand { Logout(AuthLogoutArgs), /// Show the authentication token for a service Token(AuthTokenArgs), + /// Show the path to the uv credentials directory. + /// + /// By default, credentials are stored in the uv data directory at + /// `$XDG_DATA_HOME/uv/credentials` or `$HOME/.local/share/uv/credentials` on Unix and + /// `%APPDATA%\uv\data\credentials` on Windows. + /// + /// The credentials directory may be overridden with `$UV_CREDENTIALS_DIR`. + /// + /// Credentials are only stored in this directory when the plaintext backend is used, as + /// opposed to the native backend, which uses the system keyring. + Dir, } #[derive(Args)] diff --git a/crates/uv/src/commands/auth/dir.rs b/crates/uv/src/commands/auth/dir.rs new file mode 100644 index 000000000..0ef4ef479 --- /dev/null +++ b/crates/uv/src/commands/auth/dir.rs @@ -0,0 +1,13 @@ +use anstream::println; +use owo_colors::OwoColorize; + +use uv_auth::TextCredentialStore; +use uv_fs::Simplified; + +/// Show the credentials directory. +pub(crate) fn dir() -> anyhow::Result<()> { + let root = TextCredentialStore::directory_path()?; + println!("{}", root.simplified_display().cyan()); + + Ok(()) +} diff --git a/crates/uv/src/commands/auth/mod.rs b/crates/uv/src/commands/auth/mod.rs index 118c25366..fefdc87c4 100644 --- a/crates/uv/src/commands/auth/mod.rs +++ b/crates/uv/src/commands/auth/mod.rs @@ -2,6 +2,7 @@ use uv_auth::{KeyringProvider, TextCredentialStore, TomlCredentialError}; use uv_configuration::KeyringProviderType; use uv_preview::Preview; +pub(crate) mod dir; pub(crate) mod login; pub(crate) mod logout; pub(crate) mod token; diff --git a/crates/uv/src/commands/mod.rs b/crates/uv/src/commands/mod.rs index c0a9a8ce7..20a09ca65 100644 --- a/crates/uv/src/commands/mod.rs +++ b/crates/uv/src/commands/mod.rs @@ -9,6 +9,7 @@ use anyhow::Context; use owo_colors::OwoColorize; use tracing::debug; +pub(crate) use auth::dir::dir as auth_dir; pub(crate) use auth::login::login as auth_login; pub(crate) use auth::logout::logout as auth_logout; pub(crate) use auth::token::token as auth_token; diff --git a/crates/uv/src/lib.rs b/crates/uv/src/lib.rs index 471f3dbfa..c1aaeb76e 100644 --- a/crates/uv/src/lib.rs +++ b/crates/uv/src/lib.rs @@ -489,6 +489,12 @@ async fn run(mut cli: Cli) -> Result { ) .await } + Commands::Auth(AuthNamespace { + command: AuthCommand::Dir, + }) => { + commands::auth_dir()?; + Ok(ExitStatus::Success) + } Commands::Help(args) => commands::help( args.command.unwrap_or_default().as_slice(), printer, diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 19b9a01a9..3ba8eb2c9 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -49,6 +49,7 @@ uv auth [OPTIONS]
uv auth login

Login to a service

uv auth logout

Logout of a service

uv auth token

Show the authentication token for a service

+
uv auth dir

Show the path to the uv credentials directory

### uv auth login @@ -266,6 +267,70 @@ uv auth token [OPTIONS]

You can configure fine-grained logging using the RUST_LOG environment variable. (https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives)

+### uv auth dir + +Show the path to the uv credentials directory. + +By default, credentials are stored in the uv data directory at `$XDG_DATA_HOME/uv/credentials` or `$HOME/.local/share/uv/credentials` on Unix and `%APPDATA%\uv\data\credentials` on Windows. + +The credentials directory may be overridden with `$UV_CREDENTIALS_DIR`. + +Credentials are only stored in this directory when the plaintext backend is used, as opposed to the native backend, which uses the system keyring. + +

Usage

+ +``` +uv auth dir [OPTIONS] +``` + +

Options

+ +
--allow-insecure-host, --trusted-host allow-insecure-host

Allow insecure connections to a host.

+

Can be provided multiple times.

+

Expects to receive either a hostname (e.g., localhost), a host-port pair (e.g., localhost:8080), or a URL (e.g., https://localhost).

+

WARNING: Hosts included in this list will not be verified against the system's certificate store. Only use --allow-insecure-host in a secure network with verified sources, as it bypasses SSL verification and could expose you to MITM attacks.

+

May also be set with the UV_INSECURE_HOST environment variable.

--cache-dir cache-dir

Path to the cache directory.

+

Defaults to $XDG_CACHE_HOME/uv or $HOME/.cache/uv on macOS and Linux, and %LOCALAPPDATA%\uv\cache on Windows.

+

To view the location of the cache directory, run uv cache dir.

+

May also be set with the UV_CACHE_DIR environment variable.

--color color-choice

Control the use of color in output.

+

By default, uv will automatically detect support for colors when writing to a terminal.

+

Possible values:

+
    +
  • auto: Enables colored output only when the output is going to a terminal or TTY with support
  • +
  • always: Enables colored output regardless of the detected environment
  • +
  • never: Disables colored output
  • +
--config-file config-file

The path to a uv.toml file to use for configuration.

+

While uv configuration can be included in a pyproject.toml file, it is not allowed in this context.

+

May also be set with the UV_CONFIG_FILE environment variable.

--directory directory

Change to the given directory prior to running the command.

+

Relative paths are resolved with the given directory as the base.

+

See --project to only change the project root directory.

+
--help, -h

Display the concise help for this command

+
--managed-python

Require use of uv-managed Python versions.

+

By default, uv prefers using Python versions it manages. However, it will use system Python versions if a uv-managed Python is not installed. This option disables use of system Python versions.

+

May also be set with the UV_MANAGED_PYTHON environment variable.

--native-tls

Whether to load TLS certificates from the platform's native certificate store.

+

By default, uv loads certificates from the bundled webpki-roots crate. The webpki-roots are a reliable set of trust roots from Mozilla, and including them in uv improves portability and performance (especially on macOS).

+

However, in some cases, you may want to use the platform's native certificate store, especially if you're relying on a corporate trust root (e.g., for a mandatory proxy) that's included in your system's certificate store.

+

May also be set with the UV_NATIVE_TLS environment variable.

--no-cache, --no-cache-dir, -n

Avoid reading from or writing to the cache, instead using a temporary directory for the duration of the operation

+

May also be set with the UV_NO_CACHE environment variable.

--no-config

Avoid discovering configuration files (pyproject.toml, uv.toml).

+

Normally, configuration files are discovered in the current directory, parent directories, or user configuration directories.

+

May also be set with the UV_NO_CONFIG environment variable.

--no-managed-python

Disable use of uv-managed Python versions.

+

Instead, uv will search for a suitable Python version on the system.

+

May also be set with the UV_NO_MANAGED_PYTHON environment variable.

--no-progress

Hide all progress outputs.

+

For example, spinners or progress bars.

+

May also be set with the UV_NO_PROGRESS environment variable.

--no-python-downloads

Disable automatic downloads of Python.

+
--offline

Disable network access.

+

When disabled, uv will only use locally cached data and locally available files.

+

May also be set with the UV_OFFLINE environment variable.

--project project

Run the command within the given project directory.

+

All pyproject.toml, uv.toml, and .python-version files will be discovered by walking up the directory tree from the project root, as will the project's virtual environment (.venv).

+

Other command-line arguments (such as relative paths) will be resolved relative to the current working directory.

+

See --directory to change the working directory entirely.

+

This setting has no effect when used in the uv pip interface.

+

May also be set with the UV_PROJECT environment variable.

--quiet, -q

Use quiet output.

+

Repeating this option, e.g., -qq, will enable a silent mode in which uv will write no output to stdout.

+
--verbose, -v

Use verbose output.

+

You can configure fine-grained logging using the RUST_LOG environment variable. (https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives)

+
+ ## uv run Run a command or script.