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 --script - does not parse inline script metadata #10021

Closed
BarrensZeppelin opened this issue Dec 19, 2024 · 3 comments
Closed

uv run --script - does not parse inline script metadata #10021

BarrensZeppelin opened this issue Dec 19, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@BarrensZeppelin
Copy link

BarrensZeppelin commented Dec 19, 2024

I would expect that adding the --script flag didn't disable reading of inline script metadata from stdin, but it seems to be the case.

$ xsel -b
# /// script
# requires-python = ">=3.10"
# dependencies = [
#     "urllib3",
# ]
# ///

import urllib3
$ xsel -b | uv run -v -
DEBUG uv 0.5.10
Reading inline script metadata from `stdin`
DEBUG Using Python request Python >=3.10 from `requires-python` metadata
DEBUG Searching for Python >=3.10 in virtual environments, managed installations, or search path
DEBUG Searching for managed installations at `.local/share/uv/python`
DEBUG Found managed installation `cpython-3.11.9-linux-x86_64-gnu`
DEBUG Found `cpython-3.11.9-linux-x86_64-gnu` at `/home/zii/.local/share/uv/python/cpython-3.11.9-linux-x86_64-gnu/bin/python3.11` (managed installations)
DEBUG Caching via interpreter: `/home/zii/.local/share/uv/python/cpython-3.11.9-linux-x86_64-gnu/bin/python3.11`
DEBUG Using request timeout of 30s
DEBUG Solving with installed Python version: 3.11.9
DEBUG Solving with target Python version: >=3.11.9
DEBUG Adding direct dependency: urllib3*
DEBUG Found stale response for: https://pypi.org/simple/urllib3/
DEBUG Sending revalidation request for: https://pypi.org/simple/urllib3/
DEBUG Found not-modified response for: https://pypi.org/simple/urllib3/
DEBUG Searching for a compatible version of urllib3 (*)
DEBUG Selecting: urllib3==2.2.3 [compatible] (urllib3-2.2.3-py3-none-any.whl)
DEBUG Found fresh response for: https://files.pythonhosted.org/packages/ce/d9/5f4c13cecde62396b0d3fe530a50ccea91e7dfc1ccf0e09c228841bb5ba8/urllib3-2.2.3-py3-none-any.whl.metadata
DEBUG Tried 1 versions: urllib3 1
DEBUG marker environment resolution took 0.043s
Resolved 1 package in 43ms
DEBUG Assessing Python executable as base candidate: /home/zii/.local/share/uv/python/cpython-3.11.9-linux-x86_64-gnu/bin/python3.11
DEBUG Using base executable for virtual environment: /home/zii/.local/share/uv/python/cpython-3.11.9-linux-x86_64-gnu/bin/python3.11
DEBUG Ignoring empty directory
DEBUG Using request timeout of 30s
DEBUG Requirement already cached: urllib3==2.2.3
Installed 1 package in 7ms
 + urllib3==2.2.3
DEBUG Using Python 3.11.9 interpreter at: /home/zii/.cache/uv/archive-v0/BKxFXOwvV9ggZUwFrS0mg/bin/python3
DEBUG Running `python -c`
DEBUG Command exited with code: 0
$ xsel -b | uv run -v --script --isolated -
DEBUG uv 0.5.10
DEBUG No project found; searching for Python interpreter
DEBUG Searching for default Python interpreter in virtual environments, managed installations, or search path
DEBUG Searching for managed installations at `.local/share/uv/python`
DEBUG Found managed installation `cpython-3.11.9-linux-x86_64-gnu`
DEBUG Found `cpython-3.11.9-linux-x86_64-gnu` at `/home/zii/.local/share/uv/python/cpython-3.11.9-linux-x86_64-gnu/bin/python3.11` (managed installations)
DEBUG Creating isolated virtual environment
DEBUG Assessing Python executable as base candidate: /home/zii/.local/share/uv/python/cpython-3.11.9-linux-x86_64-gnu/bin/python3.11
DEBUG Using base executable for virtual environment: /home/zii/.local/share/uv/python/cpython-3.11.9-linux-x86_64-gnu/bin/python3.11
DEBUG Ignoring empty directory
DEBUG Using Python 3.11.9 interpreter at: /home/zii/.cache/uv/builds-v0/.tmp7lfpM3/bin/python
DEBUG Running `python -`
Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
ModuleNotFoundError: No module named 'urllib3'
DEBUG Command exited with code: 1
@BarrensZeppelin
Copy link
Author

Also, is it not supported to read a script from stdin and pass along command line arguments at the same time?

I can't get this to work:

$ echo '# /// script
     # requires-python = ">=3.10"
     # dependencies = [
     #     "urllib3",
     # ]
     # ///

     import sys; print(sys.argv)' | uv run - 1 2 3
Reading inline script metadata from `stdin`
['-c']

Placing a -- before or after - doesn't help either.

@charliermarsh
Copy link
Member

I'm guessing these are bugs.

@BarrensZeppelin
Copy link
Author

Thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants