From 46158eb5ba68586eb5edde52bc1320cf5e9a4478 Mon Sep 17 00:00:00 2001 From: konstin Date: Fri, 18 Oct 2024 18:06:25 +0200 Subject: [PATCH 1/3] Better missing self update feature Show the user a proper error message when built without self-update instead of pretending the feature doesn't exist. ``` error: uv was installed through an external package manager, and self-update is not available. Please use your package manager to update uv. ``` Fixes #8318 --- crates/uv-cli/src/lib.rs | 4 ---- crates/uv/src/lib.rs | 7 +++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 0177af3e7597..cf4182831f10 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -408,7 +408,6 @@ pub enum Commands { Cache(CacheNamespace), /// Manage the uv executable. #[command(name = "self")] - #[cfg(feature = "self-update")] Self_(SelfNamespace), /// Clear the cache, removing all entries or those linked to specific packages. #[command(hide = true)] @@ -449,21 +448,18 @@ pub struct HelpArgs { } #[derive(Args)] -#[cfg(feature = "self-update")] pub struct SelfNamespace { #[command(subcommand)] pub command: SelfCommand, } #[derive(Subcommand)] -#[cfg(feature = "self-update")] pub enum SelfCommand { /// Update uv. Update(SelfUpdateArgs), } #[derive(Args, Debug)] -#[cfg(feature = "self-update")] pub struct SelfUpdateArgs { /// Update to the specified version. If not provided, uv will update to the latest version. pub target_version: Option, diff --git a/crates/uv/src/lib.rs b/crates/uv/src/lib.rs index fe4aea36d51f..428c40d52ae5 100644 --- a/crates/uv/src/lib.rs +++ b/crates/uv/src/lib.rs @@ -806,6 +806,13 @@ async fn run(mut cli: Cli) -> Result { token, }), }) => commands::self_update(target_version, token, printer).await, + #[cfg(not(feature = "self-update"))] + Commands::Self_(_) => { + anyhow::bail!( + "uv was installed through an external package manager, and self-update \ + is not available. Please use your package manager to update uv." + ); + } Commands::Version { output_format } => { commands::version(output_format, &mut stdout())?; Ok(ExitStatus::Success) From f51e40ab818b0c9f8157074905360009beffd341 Mon Sep 17 00:00:00 2001 From: konstin Date: Fri, 18 Oct 2024 19:06:16 +0200 Subject: [PATCH 2/3] generate-all --- docs/reference/cli.md | 130 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/docs/reference/cli.md b/docs/reference/cli.md index b4f4bc5f4870..64fa7cf06466 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -42,6 +42,8 @@ uv [OPTIONS]
uv cache

Manage uv’s cache

+
uv self

Manage the uv executable

+
uv version

Display uv’s version

uv help

Display documentation for a command

@@ -7854,6 +7856,134 @@ uv cache dir [OPTIONS]
+## uv self + +Manage the uv executable + +

Usage

+ +``` +uv self [OPTIONS] +``` + +

Commands

+ +
uv self update

Update uv

+
+
+ +### uv self update + +Update uv + +

Usage

+ +``` +uv self update [OPTIONS] [TARGET_VERSION] +``` + +

Arguments

+ +
TARGET_VERSION

Update to the specified version. If not provided, uv will update to the latest version

+ +
+ +

Options

+ +
--cache-dir cache-dir

Path to the cache directory.

+ +

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

+ +

May also be set with the UV_CACHE_DIR environment variable.

+
--color color-choice

Control colors in output

+ +

[default: auto]

+

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

+ +
--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, -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-progress

Hide all progress outputs.

+ +

For example, spinners or progress bars.

+ +
--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.

+ +
--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.

+ +
--python-preference python-preference

Whether to prefer uv-managed or system Python installations.

+ +

By default, uv prefers using Python versions it manages. However, it will use system Python installations if a uv-managed Python is not installed. This option allows prioritizing or ignoring system Python installations.

+ +

May also be set with the UV_PYTHON_PREFERENCE environment variable.

+

Possible values:

+ +
    +
  • only-managed: Only use managed Python installations; never use system Python installations
  • + +
  • managed: Prefer managed Python installations over system Python installations
  • + +
  • system: Prefer system Python installations over managed Python installations
  • + +
  • only-system: Only use system Python installations; never use managed Python installations
  • +
+
--quiet, -q

Do not print any output

+ +
--token token

A GitHub token for authentication. A token is not required but can be used to reduce the chance of encountering rate limits

+ +

May also be set with the UV_GITHUB_TOKEN environment variable.

+
--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>)

+ +
--version, -V

Display the uv version

+ +
+ ## uv version Display uv's version From a198e0fbaa474816350347748a5f90624dee5735 Mon Sep 17 00:00:00 2001 From: konstin Date: Fri, 18 Oct 2024 19:27:32 +0200 Subject: [PATCH 3/3] snapshots --- crates/uv/tests/it/help.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/crates/uv/tests/it/help.rs b/crates/uv/tests/it/help.rs index ea6811bfce99..0ef097bae09b 100644 --- a/crates/uv/tests/it/help.rs +++ b/crates/uv/tests/it/help.rs @@ -5,7 +5,7 @@ fn help() { let context = TestContext::new_with_versions(&[]); // The `uv help` command should show the long help message - uv_snapshot!(context.filters(), context.help(), @r#" + uv_snapshot!(context.filters(), context.help(), @r###" success: true exit_code: 0 ----- stdout ----- @@ -29,6 +29,7 @@ fn help() { build Build Python packages into source distributions and wheels publish Upload distributions to an index cache Manage uv's cache + self Manage the uvcutable version Display uv's version generate-shell-completion Generate shell completion help Display documentation for a command @@ -67,14 +68,14 @@ fn help() { ----- stderr ----- - "#); + "###); } #[test] fn help_flag() { let context = TestContext::new_with_versions(&[]); - uv_snapshot!(context.filters(), context.command().arg("--help"), @r#" + uv_snapshot!(context.filters(), context.command().arg("--help"), @r###" success: true exit_code: 0 ----- stdout ----- @@ -98,6 +99,7 @@ fn help_flag() { build Build Python packages into source distributions and wheels publish Upload distributions to an index cache Manage uv's cache + self Manage the uvcutable version Display uv's version help Display documentation for a command @@ -134,14 +136,14 @@ fn help_flag() { Use `uv help` for more details. ----- stderr ----- - "#); + "###); } #[test] fn help_short_flag() { let context = TestContext::new_with_versions(&[]); - uv_snapshot!(context.filters(), context.command().arg("-h"), @r#" + uv_snapshot!(context.filters(), context.command().arg("-h"), @r###" success: true exit_code: 0 ----- stdout ----- @@ -165,6 +167,7 @@ fn help_short_flag() { build Build Python packages into source distributions and wheels publish Upload distributions to an index cache Manage uv's cache + self Manage the uvcutable version Display uv's version help Display documentation for a command @@ -201,7 +204,7 @@ fn help_short_flag() { Use `uv help` for more details. ----- stderr ----- - "#); + "###); } #[test] @@ -672,7 +675,7 @@ fn help_flag_subsubcommand() { fn help_unknown_subcommand() { let context = TestContext::new_with_versions(&[]); - uv_snapshot!(context.filters(), context.help().arg("foobar"), @r#" + uv_snapshot!(context.filters(), context.help().arg("foobar"), @r###" success: false exit_code: 2 ----- stdout ----- @@ -694,11 +697,12 @@ fn help_unknown_subcommand() { build publish cache + self version generate-shell-completion - "#); + "###); - uv_snapshot!(context.filters(), context.help().arg("foo").arg("bar"), @r#" + uv_snapshot!(context.filters(), context.help().arg("foo").arg("bar"), @r###" success: false exit_code: 2 ----- stdout ----- @@ -720,9 +724,10 @@ fn help_unknown_subcommand() { build publish cache + self version generate-shell-completion - "#); + "###); } #[test] @@ -749,7 +754,7 @@ fn help_unknown_subsubcommand() { fn help_with_global_option() { let context = TestContext::new_with_versions(&[]); - uv_snapshot!(context.filters(), context.help().arg("--no-cache"), @r#" + uv_snapshot!(context.filters(), context.help().arg("--no-cache"), @r###" success: true exit_code: 0 ----- stdout ----- @@ -773,6 +778,7 @@ fn help_with_global_option() { build Build Python packages into source distributions and wheels publish Upload distributions to an index cache Manage uv's cache + self Manage the uvcutable version Display uv's version generate-shell-completion Generate shell completion help Display documentation for a command @@ -811,7 +817,7 @@ fn help_with_global_option() { ----- stderr ----- - "#); + "###); } #[test] @@ -853,7 +859,7 @@ fn help_with_no_pager() { // We can't really test whether the --no-pager option works with a snapshot test. // It's still nice to have a test for the option to confirm the option exists. - uv_snapshot!(context.filters(), context.help().arg("--no-pager"), @r#" + uv_snapshot!(context.filters(), context.help().arg("--no-pager"), @r###" success: true exit_code: 0 ----- stdout ----- @@ -877,6 +883,7 @@ fn help_with_no_pager() { build Build Python packages into source distributions and wheels publish Upload distributions to an index cache Manage uv's cache + self Manage the uvcutable version Display uv's version generate-shell-completion Generate shell completion help Display documentation for a command @@ -915,5 +922,5 @@ fn help_with_no_pager() { ----- stderr ----- - "#); + "###); }