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

uv run and uv tool run should list available scripts and executables #4024

Closed
charliermarsh opened this issue Jun 4, 2024 · 13 comments · Fixed by #7687
Closed

uv run and uv tool run should list available scripts and executables #4024

charliermarsh opened this issue Jun 4, 2024 · 13 comments · Fixed by #7687
Labels
good first issue Good for newcomers help wanted Contribution especially encouraged

Comments

@charliermarsh
Copy link
Member

Rye has this neat feature: https://rye.astral.sh/guide/commands/run/

@charliermarsh charliermarsh added the preview Experimental behavior label Jun 4, 2024
@Ben-Epstein
Copy link

@charliermarsh what is the difference between uv run and uv tool run? I can't seem to find it in the docs, and they seem to have different behavior.

@charliermarsh
Copy link
Member Author

Neither is documented right now nor intended to be used -- they're both under active development. But uv run is "run a command within this project's environment", while uv tool run is "run a globally-installed tool" (similar to pipx).

@zanieb
Copy link
Member

zanieb commented Jun 10, 2024

uv tool run will also run a tool in an ephemeral environment, it's like pipx run or npx.

@charliermarsh
Copy link
Member Author

I actually don't know if we need this, we have uv tool list. Do we want uv tool run to fall back to this?

@zanieb
Copy link
Member

zanieb commented Jul 9, 2024

It probably makes more sense than starting a python REPL (which I think we should remove?)

@charliermarsh
Copy link
Member Author

I think uv tool run and uv run just show help.

@konstin konstin added the needs-design Needs discussion, investigation, or design label Jul 9, 2024
@charliermarsh
Copy link
Member Author

I think uv tool run should list the available executables, to start. That seems straightforward.

Not sure about uv run, it's a little less obvious what should happen there, since (unlike Rye) we don't have "scripts". We could list entrypoints, but, IDK.

@charliermarsh charliermarsh added help wanted Contribution especially encouraged and removed needs-design Needs discussion, investigation, or design labels Jul 19, 2024
@charliermarsh
Copy link
Member Author

The uv tool run part should be doable now, at least.

@charliermarsh charliermarsh added the good first issue Good for newcomers label Jul 19, 2024
charliermarsh pushed a commit that referenced this issue Jul 29, 2024
)

## Summary

Part of #4024 

## Test Plan

Test cases included.
@zanieb zanieb removed the preview Experimental behavior label Aug 20, 2024
@zanieb
Copy link
Member

zanieb commented Aug 28, 2024

Gosh, I'd sure love this. The error message here, e.g., when I haven't installed django yet is not helpful:


❯ uv run django-admin startproject mysite
Using Python 3.11.7
Creating virtualenv at: .venv
error: Failed to spawn: `django-admin`
  Caused by: No such file or directory (os error 2)

I think we can at least list things in the virtual environment bin?

@charliermarsh
Copy link
Member Author

Agreed. Let's start with that. Help wanted!

@CharlesB2
Copy link

Looks like this got implemented as fallback to uv tool list when uv tool run has no arg, but I find it really unintuitive

$ uv --version
uv 0.4.6 (84f25e8cf 2024-09-05)
$ uv tool run
pytest v8.3.2
- py.test
- pytest

At least add a message before like you didn't specify any command to run, here are the ones you have

@Aditya-PS-05
Copy link
Contributor

Hello team,
I am willing to contribute to this issue,
According to me:
1.) uv tool run should list all the globally installed tools
2.) Not sure about the uv run command and what is the entry-points you discussed earlier?

Can you assign this task to me?

@zanieb
Copy link
Member

zanieb commented Sep 13, 2024

uv tool run already does this.

We're not sure what we we want to do for uv run, but I think we'd want to either list things in .venv/bin or the entrypoints of all the packages in the environment.

https://packaging.python.org/en/latest/specifications/entry-points/

fn get_entrypoints(
from: &PackageName,
site_packages: &SitePackages,
) -> anyhow::Result<Vec<(String, PathBuf)>> {
let installed = site_packages.get_packages(from);
let Some(installed_dist) = installed.first().copied() else {
bail!("Expected at least one requirement")
};
Ok(entrypoint_paths(
site_packages,
installed_dist.name(),
installed_dist.version(),
)?)
}

zanieb pushed a commit that referenced this issue Sep 26, 2024
…hen no arguments are provided (#7641)

## Summary

Adds a helpful context message when `uvx` is run without arguments
To clarify, it is displaying the installed tools.

This addresses confusion, such as the one highlighted in issue #7348,
by making the output more user-friendly and informative.

Related #4024 

## Test Plan

Updated the test snapshots to include the new output.
Running the tests locally with `cargo nextest run` confirms that the
tests pass.
The CI pipeline should also pass.

### Manuel Testing

**uvx**
```shell
# Make sure you have the updated version of uv installed on your path.
# cargo install --path ./crates/uv --force
❯ uvx
Provide a command to invoke with `uvx <command>` or `uvx --from <package> <command>`.

The following tools are already installed:

black v24.8.0
- black
- blackd
ruff v0.6.7
- ruff

See `uvx --help` for more information.
```

**uv tool list**
```shell
# Make sure you have the updated version of uv installed on your path.
# cargo install --path ./crates/uv --force
❯ uv tool list
black v24.8.0
- black
- blackd
ruff v0.6.7
- ruff
```

**uv tool run**
```shell
# Make sure you have the updated version of uv installed on your path.
# cargo install --path ./crates/uv --force
❯ uv tool run
Provide a command to invoke with `uv tool run <command>` or `uv tool run --from <package> <command>`.

The following tools are already installed:

black v24.8.0
- black
- blackd
ruff v0.6.7
- ruff

See `uv tool run --help` for more information.
```
---

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>

---------

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
zanieb added a commit that referenced this issue Oct 8, 2024
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
## Summary

This PR adds the ability to list available scripts in the environment
when `uv run` is invoked without any arguments.
It somewhat mimics the behavior of `rye run` command
(See https://rye.astral.sh/guide/commands/run).

This is an attempt to fix #4024.

## Test Plan

I added test cases. The CI pipeline should pass.

### Manuel Tests

```shell
❯ uv run
Provide a command or script to invoke with `uv run <command>` or `uv run script.py`.

The following scripts are available:

normalizer
python
python3
python3.12

See `uv run --help` for more information.
```

---------

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
Co-authored-by: Zanie Blue <contact@zanie.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Contribution especially encouraged
Projects
No open projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

6 participants