←back to thread

Fun with uv and PEP 723

(www.cottongeeks.com)
619 points deepakjois | 1 comments | | HN request time: 0.216s | source
Show context
js2 ◴[] No.44371129[source]
So far I've only run into one minor ergonomic issue when using `uv run --script` with embedded metadata which is that sometimes I want to test changes to the script via the Python REPL, but that's a bit harder to do since you have to run something like:

  $ uv run --python=3.13 --with-requirements <(uv export --script script.py) -- python
  >>> from script import X
I'd love if there were something more ergonomic like:

  $ uv run --with-script script.py python
Edit: this is better:

  $ "$(uv python find --script script.py)"
  >>> from script import X
That fires up the correct python and venv for the script. You probably have to run the script once to create it.
replies(2): >>44371484 #>>44371734 #
1. dkdcio ◴[] No.44371734[source]
I think you're looking for something like this (the important part being embeddeding a REPL call toward the end after whateve rsetup): https://gist.github.com/lostmygithubaccount/77d12d03894953bc...

You can make `--interactive` or whatever you want a CLI flag from the script. I often make these small Typer CLIs with something like that (or in this case, in another dev script like this, I have `--sql` for entering a DuckDB SQL repl)