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

Issue-11796: Provide more descriptive message for uv run pythonx.xx #12201

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

JWLee89
Copy link

@JWLee89 JWLee89 commented Mar 16, 2025

Related Issue

#11796

Summary

  1. Add meaningful message when user invokes uv with run python<valid-python-version>.
    ✅ "python", "python3", "python3.9", "python4", "python3.10", "python3.13.3", "python39" (yes, python39 might still be released in 100 years 😆 )

❌ "python3abc", "python3.12b3", "", "python-foo"

  1. Contextual information added depending on whether the command was run inside of a uv project or not. See: https://github.com/astral-sh/uv/pull/12201/files#diff-423c3a82aab6dba4068dd7675391fc9328a66682131dbf2043e7847ab4ba8661R1092

Automated Tests

  1. Added unit test for new functions created for parsing and validating python executable entered by user
  2. TODO: Once specs are finalized through discussions in PR, will create integration tests if necessary

Need to Discuss

  1. Invoking python via its patch version - E.g. python3.11.9 is invalid. However, uv supports uv run -p 3.11.9 python, which is why when we do the following:
uv run python3.11.9

We will get the following error:

error: Failed to spawn: `python3.11.9`
  Caused by: `python3.11.9` not available in the environment, which uses python `3.11.9`. Did you mean to search for a Python 3.11.9 environment with `uv run -p 3.11.9 python`?

Is this okay? If not, we need to define the specs in the PR here.

  1. Supported python executable specs are defined as:
  • is stable version
  • is not post version

See:https://github.com/astral-sh/uv/pull/12201/files#diff-423c3a82aab6dba4068dd7675391fc9328a66682131dbf2043e7847ab4ba8661R1572-R1574

Would this be okay?
We can change the specs if needed. Lets discuss.

Manual Test

Case 1: run outside of project

  1. Case where no project is created. Look for a python executable version that is not available in my local machine (in my case, it was python3.9)
  2. Run cargo run -- run python3.9.3
error: Failed to spawn: `python3.9.3`
  Caused by: `python3.9.3` not available in the environment, which uses python `3.11.9`. Did you mean to search for a Python 3.9.3 environment with `uv run -p 3.9.3 python`?
  1. Run cargo run -- run python3.9
error: Failed to spawn: `python3.9`
  Caused by: `python3.9` not available in the environment, which uses python `3.11.9`. Did you mean to search for a Python 3.9 environment with `uv run -p 3.9 python`?
  1. Run cargo run -- run python3.11
Running `target/debug/uv run python3.11`
Python 3.11.9 (main, Apr  2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
  1. Run cargo run -- run python3.11.9
 Running `target/debug/uv run python3.11.9`
error: Failed to spawn: `python3.11.9`
  Caused by: `python3.11.9` not available in the environment, which uses python `3.11.9`. Did you mean to search for a Python 3.11.9 environment with `uv run -p 3.11.9 python`?

IMPORTANT: Is this acceptable? Invoking python by its patch version is not supported, so this is the expected behavior, but we need to discuss whether this behavior is acceptable.

Case 2: run inside of project

Create project using uv init example-app

  1. uv run python3.13
error: Failed to spawn: `python3.13`
  Caused by: `python3.13` not available in the project environment, which uses python `3.12.5`. Did you mean to change the environment to Python 3.13 with `uv run -p 3.13 python`?
  1. uv run python3
uv run python3
Python 3.12.5 (main, Aug  6 2024, 19:08:49) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants