uv icon indicating copy to clipboard operation
uv copied to clipboard

`uv run` and `uv tool run` should list available scripts and executables

Open charliermarsh opened this issue 1 year ago • 11 comments

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

charliermarsh avatar Jun 04 '24 21:06 charliermarsh

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

Ben-Epstein avatar Jun 10 '24 01:06 Ben-Epstein

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

charliermarsh avatar Jun 10 '24 01:06 charliermarsh

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

zanieb avatar Jun 10 '24 02:06 zanieb

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?

charliermarsh avatar Jul 09 '24 15:07 charliermarsh

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

zanieb avatar Jul 09 '24 16:07 zanieb

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

charliermarsh avatar Jul 09 '24 16:07 charliermarsh

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 avatar Jul 19 '24 23:07 charliermarsh

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

charliermarsh avatar Jul 19 '24 23:07 charliermarsh

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?

zanieb avatar Aug 28 '24 15:08 zanieb

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

charliermarsh avatar Aug 28 '24 15:08 charliermarsh

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

CharlesB2 avatar Sep 06 '24 09:09 CharlesB2

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?

Aditya-PS-05 avatar Sep 13 '24 10:09 Aditya-PS-05

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/

https://github.com/astral-sh/uv/blob/4f2349119cf341eedf738d06a50ed136a5f207db/crates/uv/src/commands/tool/run.rs#L244-L258

zanieb avatar Sep 13 '24 13:09 zanieb