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

.python-version overrides inline script metadata required-python for uv run #6883

Closed
dbohdan opened this issue Aug 30, 2024 · 1 comment · Fixed by #6884
Closed

.python-version overrides inline script metadata required-python for uv run #6883

dbohdan opened this issue Aug 30, 2024 · 1 comment · Fixed by #6884
Assignees
Labels
bug Something isn't working

Comments

@dbohdan
Copy link

dbohdan commented Aug 30, 2024

I ran a script with uv run, and .python-version in the current directory overrode required-python in the inline script metadata. The version in .python-version wasn't in the range of required-python. When the script ran with the wrong Python version, it failed. The problem took me five minutes to debug. I am not sure what should happen in this situation, but it confused me, so I am reporting it. (I think I'd prefer uv to either report a conflict in the Python version requirements and not run the script or to ignore .python-version in favor of required-python.)

I encountered this conflict on Ubuntu 24.04 on x86-64. uv was installed with pipx. Here is a POSIX shell script to reproduce it.

#! /bin/sh
set -e

uv --version

cat >demo.py <<EOF
#! /usr/bin/env -S uv run
# /// script
# dependencies = [
#   "httpx<2",
# ]
# requires-python = ">=3.10"
# ///

import sys
print(sys.version)
EOF

chmod +x demo.py

rm .python-version || true
./demo.py

echo 3.7 >.python-version
./demo.py

Output:

uv 0.4.1
Reading inline script metadata from: ./demo.py
Installed 7 packages in 4ms
3.12.1 (main, Jan 31 2024, 04:48:37) [GCC 11.4.0]
Reading inline script metadata from: ./demo.py
Installed 9 packages in 3ms
3.7.17 (default, Oct 16 2023, 22:17:29) 
[GCC 11.4.0]
@charliermarsh charliermarsh added the bug Something isn't working label Aug 30, 2024
@charliermarsh
Copy link
Member

Definitely wrong, 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

Successfully merging a pull request may close this issue.

2 participants