astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
26.11k stars 763 forks source link

Feature: more graceful handling of `uv run` when CLIs aren't well exposed. #6403

Open strangemonad opened 2 months ago

strangemonad commented 2 months ago

I don't have a great solution but wanted to call out some uvx rough edges. Some popular python packages don't expose conventionally named CLI entrypoints or rely on entrypoints from a transitive dependency.

Some examples:

jupyterlab doesn't provide meaningful info of how to get to a solution.

❯ uvx jupyterlab
Installed 91 packages in 226ms
The executable `jupyterlab` was not found.
warning: An executable named `jupyterlab` is not provided by package `jupyterlab`.
The following executables are provided by `jupyterlab`:
- jlpm
- jupyter-lab
- jupyter-labextension
- jupyter-labhub

~ 3s

jupyter does seem to work but gives a confusing warning

❯ uvx jupyter
Installed 99 packages in 254ms
warning: An executable named `jupyter` is not provided by package `jupyter` but is available via the dependency `jupyter-core`. Consider using `uvx --from jupyter-core jupyter` instead.
... # Successful run otherwise

dbt You sort of have to know that the warning means use --from

❯ uvx dbt-core
The executable `dbt-core` was not found.
warning: An executable named `dbt-core` is not provided by package `dbt-core`.
The following executables are provided by `dbt-core`:
- dbt

~
❯ uvx --from dbt-core dbt
... # Successful run otherwise
charliermarsh commented 2 months ago

Thanks, these are great examples!

The last one seems easiest to fix (we can recommend --from there with a command you can copy-paste).

The Jupyter one is somewhat rough. I think the correct invocation is: uvx --with jupyter --from jupyter-core jupyter notebook. Because jupyter-core ships the executable, and then dynamically figures out which commands are enabled -- so you do need to install jupyter in that environment, but it doesn't contain the executable.

charliermarsh commented 2 months ago

\cc @zanieb

zanieb commented 2 months ago

Thank you!

I wonder what the pipx invocation for Jupyter is?

strangemonad commented 2 months ago

@zanieb it's equally convoluted for pipx, which I know really comes down to how the package authors choose to expose things. What I've done in the past is something like

pipx install --include-deps jupyter # to grap `jupyter` from `jupyter-core`
pipx inject jupyter --include-apps --include-deps jupyter-lab

That ends up installing too many entrypoints but at least it's been reliable across the last few versions.

zanieb commented 2 months ago

😬 Yeah that's pretty wild too. Thanks for sharing!

zanieb commented 2 months ago

Seems like Jupyter should ship a CLI package that does something reasonable.. haha