Open ngnpope opened 3 weeks ago
Thanks!
$ uv run list-peps
error: Failed to spawn: `list-peps`
Caused by: No such file or directory (os error 2)
You can avoid this with uv run ./list-peps
. I'm not sure whether that's a bug or working as intended, given that running list-peps
in the terminal is interpreted the same way:
❯ list-peps
zsh: command not found: list-peps
(But the recursion is definitely a bug.)
Hah, I wondered what would happen if I tried this, didn't get around to it!
You can avoid this with
uv run ./list-peps
. I'm not sure whether that's a bug or working as intended, given that runninglist-peps
in the terminal is interpreted the same way
Hmm. I'm not sure that "command not found" is really the same as the "failed to spawn" case. The former is basically because the current directory is not on $PATH
(a good thing) so you have to specify a path where the executable is found, hence ./list-peps
.
On the other hand, we should probably expect uv run list-peps
to work in a similar vein to python list-peps
where we don't need to do python ./list-peps
. I've not attempted to look at what uv run
does, but it seems as though it's treating files ending in .py
as something to be run with a Python interpreter and anything else as execute directly, irrespective of whether it has the executable bit or not. I realise that fixing this might require some sort of file type detection instead of only relying on the extension.
Some further things of interest that seem to confirm the above...
I'll try to fix this for tomorrow's release.
I didn't know that uv run
could also run binaries, my expectation for its behaviour was actually in line with what I found on this documentation page:
As in I was lead to believe that uv run example.py
or uv run --python 3.12 example.py
would work like python example.py
or python3.12 example.py
That is the case (we use python
for .py
files), but it can run any command in the environment context e.g. uv add ruff && uv run ruff
— this is really important.
As a minor note, Hatch and Poetry also recursive infinitely when used this way.
As a minor note, Hatch and Poetry also recursive infinitely when used this way.
pipx run
doesn't for me
A perhaps surprising consequence to the current behaviour is that symlinks to working scripts might themselves not work, depending on the symlink name. For example, if I start with the working version of ./list-peps.py
in the original report, and create ./list-peps
as a symlink to it, I also get the recursion bug but only when invoking through the symlink. I think if the script filename was canonicalized prior to choosing whether to invoke it as a Python source or a binary, this would be less of a problem and perhaps serve as a viable workaround.
Not sure if linked, sorry if not, couldn't find another issue and sorry again if I've got confused - the documentation says "uv run file.py is equivalent to uv run python file.py", but it doesn't appear to be, and it gets confused with/without extension:
~/test $ cat noextension
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "click",
# ]
# ///
import click
~/test $ cat extension.py
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "click",
# ]
# ///
import click
~/test $ uv run noextension # This error is expected
error: Failed to spawn: `noextension`
Caused by: No such file or directory (os error 2)
~/test $ uv run ./noextension
Traceback (most recent call last):
File "/Users/m/test/./noextension", line 8, in <module>
import click
ModuleNotFoundError: No module named 'click'
~/test $ uv run python3 ./noextension
Traceback (most recent call last):
File "/Users/m/test/./noextension", line 8, in <module>
import click
ModuleNotFoundError: No module named 'click'
~/test $ uv run extension.py
Reading inline script metadata from: extension.py
~/test $ uv run ./extension.py
Reading inline script metadata from: ./extension.py
~/test $ uv run python3 ./extension.py
Traceback (most recent call last):
File "/Users/m/test/./extension.py", line 8, in <module>
import click
ModuleNotFoundError: No module named 'click'
Hope that's helpful.
Related to https://github.com/astral-sh/uv/pull/6313 and https://github.com/astral-sh/ruff/issues/13021#issuecomment-2302585295.
Using the example from here with the shebang line added and saved to a file named
list-peps
:On execution, it keeps attempting to execute itself:
If executing without an extension using
uv run
:For comparison, if the script has the extension: