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 a command to append uv's binary directory to PATH #4975

Merged
merged 2 commits into from
Jul 12, 2024

Conversation

charliermarsh
Copy link
Member

Summary

I'll open follow-up tickets for Windows support.

Closes #4953.

Test Plan

❯ cargo run tool install flask
Resolved 7 packages in 353ms
Prepared 7 packages in 392ms
Installed 7 packages in 17ms
 + blinker==1.8.2
 + click==8.1.7
 + flask==3.0.3
 + itsdangerous==2.2.0
 + jinja2==3.1.4
 + markupsafe==2.1.5
 + werkzeug==3.0.3
Installed 1 executable: flask
warning: /Users/crmarsh/.local/bin is not on your PATH. To use installed tools, run:
  export PATH="/Users/crmarsh/.local/bin:$PATH"

Then:

❯ which flask
flask not found

Then:

❯ cargo run tool ensurepath
warning: `uv tool ensurepath` is experimental and may change without warning.
Updated configuration file: /Users/crmarsh/workspace/puffin/bar
Restart your shell for the changes to take effect.

Then:

❯ which flask
/Users/crmarsh/.local/bin/flask

@charliermarsh charliermarsh added enhancement New feature or request preview Experimental behavior labels Jul 10, 2024
@@ -86,6 +86,7 @@ fs2 = { version = "0.4.3" }
futures = { version = "0.3.30" }
glob = { version = "0.3.1" }
hex = { version = "0.4.3" }
home = { version = "0.5.9" }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Already in our dependency tree.)

@charliermarsh charliermarsh force-pushed the charlie/ensure branch 2 times, most recently from 30a8816 to df914fe Compare July 10, 2024 18:43
@@ -2037,6 +2037,8 @@ pub enum ToolCommand {
List(ToolListArgs),
/// Uninstall a tool.
Uninstall(ToolUninstallArgs),
/// Ensure that the tool executable directory is on `PATH`.
Ensurepath,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly about this being the name of the command.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jinx.

crates/uv-cli/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines 47 to 51
// Prepare the command (e.g., `export PATH="$HOME/.cargo/bin:$PATH"`).
let Some(command) = shell.prepend_path(&executable_directory) else {
return Err(anyhow::anyhow!("The executable directory {} is not in PATH, but the necessary command to update {shell} could not be determined.", executable_directory.simplified_display().cyan()));
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also the rustup pattern of a ~/.cargo/env file e.g.

❯ cat ~/.cargo/env
#!/bin/sh
# rustup shell setup
# affix colons on either side of $PATH to simplify matching
case ":${PATH}:" in
    *:"$HOME/.cargo/bin":*)
        ;;
    *)
        # Prepending path in case a system-installed rustc needs to be overridden
        export PATH="$HOME/.cargo/bin:$PATH"
        ;;
esac

then we can suggest source and add that to the shell instead? Idk what the trade-offs are there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I looked at that and the implementation, but I've never seen it before in other tools.

@charliermarsh
Copy link
Member Author

I changed to uv tool update-shell for now with a uv tool ensurepath alias. We can consider a top-level command too once it's relevant. I'm gonna move forward with this for now.

@charliermarsh charliermarsh enabled auto-merge (squash) July 12, 2024 22:04
@charliermarsh charliermarsh merged commit a4cb21e into main Jul 12, 2024
49 checks passed
@charliermarsh charliermarsh deleted the charlie/ensure branch July 12, 2024 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request preview Experimental behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add command to ensure tool binary directory is on path
3 participants