-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support python find --script
#11891
base: main
Are you sure you want to change the base?
Support python find --script
#11891
Conversation
505faca
to
61e729f
Compare
How did you choose to exit with a non-zero code if the environment does not exist rather than showing the interpreter we would use to create the environment? I think there's probably a use case for Separately, if we're going to exit with a non-zero code, we need to show a message indicating why we failed. |
@zanieb I was thinking about my use case: An existing environment is needed to power language features. Showing the base interpreter would be misleading, since it won't have access to the dependencies of the script. Additionally, if an environment doesn't exist, the user should have a chance to decide whether it should be created or not. As for the exit code and error messages, I don't have a strong opinion. Maybe exit code 0 should be used even when an interpreter cannot be found. |
For your use-case, why wouldn't you always run a The problem with failing if the environment doesn't exist is that it's inconsistent with how this interface normally behaves, e.g.:
We could consider |
|
If the environment doesn't exist, I would probably expect |
@charliermarsh That is also undesirable: Tools might run the interpreter to retrieve its version. If I recall correctly, both PyCharm and Pyright do this. |
Either way they have to handle the environment not existing, right? |
👍 that's my point.
If all you want is the interpreter for metadata,
If you are trying to provide up-to-date type information, this seems like what you need though? As Charlie said, you need to handle the case where it doesn't exist regardless.
That's not how it works for projects, though I'd be willing to consider changing that. I think it's more like |
In my opinion, such expensive processes should not be run without explicit user consent. Here's how I think the logic should be:
If the installation is known to take a long time, the user might not want to create an environment on their development machine (especially if they don't intend to do any significant changes). Even if they do want to, prompting gives them a chance to check the script metadata block for any potential problems, like a typo in a dependency specifier. The interpreter given must be one that belongs to the environment of that script. Otherwise, tools might have to do things twice, one for the global/base interpreter and one for the new interpreter (PyCharm would reindex the standard library, for example). |
This is roughly the antithesis of the design of this tool. We do these things transparently in the background all the time. We invest in making them fast enough that this is not expensive. Regardless... if we return to your use-case, I think all you need is
|
That's just uv itself. Downloading takes time, and I have seen many complaints about how PyCharm's indexing takes seemingly forever. Using
|
I think this is well within scope for a consumer, but we could definitely add the "supposed" interpreter path to a JSON output format.
I think you'd use a JSON output mode to differentiate between these cases, so it's not fragile. |
That would be right, except Return to the PR at hand: The hypothetical |
I don't think I'm wiling to compromise on the consistency of the |
7c852cd
to
d809b61
Compare
Summary
Resolves #11794.
When
uv python find
is given a--script
option, the existing environment for that script will be returned, if any. If one is not found, the command exits with exit code 1.--script
is incompatible with all other options to the same command.Test Plan
Unit tests.