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

Open
charliermarsh opened this issue Jun 4, 2024 · 13 comments
Open
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(),
)?)
}

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
Status: Backlog
Development

No branches or pull requests

6 participants