-
Notifications
You must be signed in to change notification settings - Fork 334
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
Selecting a Python interpreter #2386
Comments
Do we support looking up |
@konstin I think we should explicitly not support that and require a direct path if you want to use an unknown implementation. (edited the post to reflect this) |
(For clarity: we do support that today, I think. The behavior Zanie proposed above would be a change.) |
See #2386 for the motivation. We keep only two behaviours for `-p`, we have an absolute or relative path (containing a system path separator) or `-p <implementation><version>`. Open question: Should `python3.10` or `3.10` force cpython 3.10 or is any python implementation acceptable? My assumption right now is that i assume that a user specifying nothing wouldn't like it if we picked pypy, rather we should force cpython and make pypy explicit. I will add tests tomorrow, please already give the semantics a look.
Another question from #2388: With |
We've got a couple discussions going about this elsewhere:
I think those make it clear that we should support |
That would again we very different from what we currently, this requires us to collect all python implementations and rank! |
I think it's fine to take the first one on the path and not support the historical discovery noted there. We can consider something more complicated if we hear it causes problems? |
When a user provides, e.g., |
I think when an implementation is provided we could
We could also consider behavior specific to the implementation and the binaries we know they ship (this probably makes a lot of sense but I don't know what's common). Since we require you to match a known implementation we could definitely do this. |
Just to add to this... I was having issues today where It seems the issue is that but Not hard to fix, but I would have expected the original command to install the dependencies in the python as referenced by |
Might not be exactly related But how about writing to a file such as If not uv writing to the file, let the user specify it under the toml so that uv can look it up and activate that venv/python on running a python/uv command. This also might blend well with creating a default venv when there's no venv present in the current directory in #2665 and the path of the venv can be added/appended to the toml file. |
A brief proposed addendum on top of the above logic, quoting #3060. When looking at a
|
Moves all of `uv-toolchain` into `uv-interpreter`. We may split these out in the future, but the refactoring I want to do for interpreter discovery is easier if I don't have to deal with entanglement. Includes some restructuring of `uv-interpreter`. Part of #2386
Updates our Python interpreter discovery to conform to the rules described in #2386, please see that issue for a full description of the behavior. Briefly, we now will search for interpreters that satisfy a requested version without stopping at the first Python executable. Additionally, if retrieving information about an interpreter fails we will continue to search for a working interpreter. We also add the plumbing necessary to request Python implementations other than CPython, though we do not add support for other implementations at this time. A major internal goal of this work is to prepare for user-facing managed toolchains i.e. fetching a requested version during `uv run`. These APIs are not introduced, but there is some managed toolchain handling as required for our test suite. Some noteworthy implementation changes: - The `uv_interpreter::find_python` module has been removed in favor of a `uv_interpreter::discovery` module. - There are new types to help structure interpreter requests and track sources - Executable discovery is implemented as a big lazy iterator and is a central authority for source precedence - `uv_interpreter::Error` variants were split into scoped types in each module - There's much more unit test coverage, but not for Windows yet Remaining work: - [x] Write new test cases - [x] Determine correct behavior around executables in the current directory - _Future_: Combine `PythonVersion` and `VersionRequest` - _Future_: Consider splitting `ManagedToolchain` into local and remote variants - _Future_: Add Windows unit test coverage - _Future_: Explore behavior around implementation precedence (i.e. CPython over PyPy) Refactors split into: - #3329 - #3330 - #3331 - #3332 Closes #2386
In #2338 some questions came up around Python interpreter selection. Here we'll summarize our expected behavior and have some discussion around it.
Interpreters can be selected with the following formats:
/bin/python3
3.10
pypy
pypy3.10
orcpython3.10
Using
python
as the implementation should allow any implementation. Its behavior should be equivalent toX.Y
.Python interpreters may be discovered via:
python -m uv
)PATH
When a user does not specify an interpreter, we should do our best to infer one in the order above.
When a user specifies an interpreter via a direct path:
When a user specifies an interpreter via a version:
When a user specifies an interpreter with an implementation (and version):
Interpreters can either belong to a virtual environment or the system.
When an interpreter belongs to the system, we will not modify packages (i.e. install, uninstall) in the interpreter's environment without the
--system
flag or specification of the interpreter with a direct path. We use system interpreters for compiling dependencies without opt-in.Examples
Compile using system Python interpreter discovered by being the spawning intepreter:
Install using system Python interpreter discovered by being the spawning intepreter:
Install using system Python interpreter discovered by direct path:
Compile using system Python interpreter discovered by being the spawning intepreter with matching version:
Compile using Python interpreter discovered on path since spawning intepreter with mismatched version:
Install using Python interpreter in the working directory:
Install using Python interpreter in the active virtual environment:
Install using Python interpreter in the active virtual environment with mismatched version:
Compile using Python interpreter in the active virtual environment with mismatched version:
Install using Python interpreter via direct path with active virtual environment:
Install using Python with an unknown implementation:
Install using Python with an unknown implementation via direct path:
The text was updated successfully, but these errors were encountered: