-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Recursive execution when using uv run
in shebang line of script without .py
extension
#6360
Comments
Thanks! |
You can avoid this with
|
(But the recursion is definitely a bug.) |
Hah, I wondered what would happen if I tried this, didn't get around to it! |
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 On the other hand, we should probably expect Some further things of interest that seem to confirm the above... Python not needing the ./ prefix$ python list-peps
Traceback (most recent call last):
File "/home/nick/list-peps", line 9, in <module>
from rich.pretty import pprint
ModuleNotFoundError: No module named 'rich' Removing the executable bit and using uv run$ uv run ./list-peps
error: Failed to spawn: `./list-peps`
Caused by: Permission denied (os error 13) Attempting to execute a .pyc (which is something that Python can do)This is something that is unlikely to support the PEP 723 stuff, so of much less use. $ python -m compileall list-peps.py
$ python __pycache__/list-peps.cpython-312.pyc
Traceback (most recent call last):
File "list-peps.py", line 9, in <module>
from rich.pretty import pprint
ModuleNotFoundError: No module named 'rich'
$ uv run __pycache__/list-peps.cpython-312.pyc
error: Failed to spawn: `__pycache__/list-peps.cpython-312.pyc`
Caused by: Permission denied (os error 13) |
I'll try to fix this for tomorrow's release. |
When we see `#!/usr/bin/env -S uv run"`, treat the input as a python file to avoid infinite recursion. Tested manually. Fixes #6360
I didn't know that As in I was lead to believe that |
That is the case (we use |
As a minor note, Hatch and Poetry also recursive infinitely when used this way. |
|
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 |
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:
Hope that's helpful. |
The following fixed the recursion bug for me: #!/usr/bin/env -S uv run -s From -s, --script
Run the given path as a Python script.
Using `--script` will attempt to parse the path as a PEP 723 script, irrespective of its extension. With this, I can call just |
Yes. The |
Related to #6313 and astral-sh/ruff#13021 (comment).
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:
The text was updated successfully, but these errors were encountered: