Prioritize PATH over py --list-paths in Windows selection#2057
Prioritize PATH over py --list-paths in Windows selection#2057charliermarsh merged 3 commits intomainfrom
PATH over py --list-paths in Windows selection#2057Conversation
|
\cc @AlexWaygood |
90e3b2d to
2ff1d2e
Compare
PATH over py --list-paths in Windows selection
|
This seems like a good idea to me and what users would expect to happen. |
|
I thought we did this already, maybe it's gone back and forth a bit during development. Makes sense to me. |
|
(Continuing from the issue...) I'm surprised because virtualenv does seem to do registry-based lookups before PATH. But I suppose for virtualenv it matters less, since the priority is getting the right version? |
|
I see Micha's change that added the fallback to |
|
Also great because the overhead of a separate process is eliminated in most cases! I'm very excited for this. |
There was a problem hiding this comment.
This seems like a good idea to me and what users would expect to happen.
I think this is a bit more nuanced and depends on your workflow and how you installed python. Users using py (over python) may have an additional installation on their PATH. For them, picking PATH over the default used by py can be surprising.
The reason virtual doesn't run into this problem is that it always tries to use the current Interpreter (in which it is running) first. It then doesn't matter whether a user uses python or py or a shim to run python.
The challenge we face is that we can't rely on the "current python" instance, so we have to approximate it as best as we can and using PATH first probably does the right thing in more cases than using py first, with the exception for users using py with another python installation on PATH.
Also great because the overhead of a separate process is eliminated in most cases! I'm very excited for this.
We planned to re-implement the registry lookup in Rust, in which case the PATH traversal is most likely slower, especially when we can't find a python installation on PATH and need to fall-back to py
| # - name: "Install Python" | ||
| # run: choco install python |
There was a problem hiding this comment.
(Intentionally kept this change.)
| Ok(None) => { | ||
| // No matching Python version found, continue searching PATH | ||
| } |
There was a problem hiding this comment.
This comment is outdated. We should remove this branch.
| } | ||
| Err(Error::PyList(error)) => { | ||
| if error.kind() == std::io::ErrorKind::NotFound { | ||
| debug!("`py` is not installed. Falling back to searching Python on the path"); |
There was a problem hiding this comment.
This message is outdated. We already tried searching the PATh. We should keep the graceful recovery
|
A minor feature we're losing is that From PEP 514:
In this sense github actions is at odds with the PEP, the versions shouldn't be in the registry if not selected by the setup python action (or setup python should at least ensure that I think either choice of precedence between |
.github/workflows/system-install.yml
Outdated
| name: System Install | ||
|
|
||
| on: | ||
| pull_request: |
There was a problem hiding this comment.
| pull_request: |
(Am i understanding correctly that this should only be running manually?)
There was a problem hiding this comment.
Yup! This is just set so I can test it during development of this PR. It will be removed prior to landing.
|
I agree that this is the right way to go. FWIW, I always tick the "add to PATH" box when installing Python on Windows. I have a vague memory of things going wrong (or, not working the way I expected to) the one time I didn't do that. But that was a very long time ago, and it might very well be that I've just been cargo-culting from old tutorials that predated PEP-514 this whole time |
|
FYI I wrote a bit here #2056 (comment) the relevant part is:
🙂 |
f04bfcf to
620f7aa
Compare
620f7aa to
d8a2b20
Compare
uv --systemis failing in GitHub Actions, becausepy --list-pathsreturns all the pre-cached Pythons:So, our default selector returns the first entry here. But none of these are actually in
PATHexcept the one that the user installed viaactions/setup-python@v5-- that's the point of the action, that it puts the correct versions inPATH.It seems to me like we should prioritize
PATHoverpy --list-paths. Is there a good reason not to do this?Closes: #2056