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

Adjust base Python lookup logic for Windows #2121

Merged
merged 3 commits into from
Mar 3, 2024
Merged

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Mar 1, 2024

Summary

When I install via the Windows Store, interpreter.base_prefix contains a bunch of resolved information that leads to a broken environment.

Instead, we now use sys._base_executable on Windows by default, falling back to sys.base_prefix if it doesn't exist. (There are some issues with sys.base_executable that lead to complexity in virtualenv, but they only affect POSIX.) Admittedly, I don't know when sys._base_executable wouldn't exist. It exists in all the environments I've tested.

Additionally, we use the system interpreter directly if we're outside of a virtualenv.

@charliermarsh charliermarsh added the windows Specific to the Windows platform label Mar 1, 2024
Base automatically changed from charlie/keys to main March 1, 2024 21:17
@charliermarsh charliermarsh marked this pull request as draft March 2, 2024 20:16
@charliermarsh
Copy link
Member Author

Moving to draft to (1) add tests and (2) change Windows logic a bit.

@charliermarsh charliermarsh force-pushed the charlie/home branch 2 times, most recently from 85e176c to e57b4ce Compare March 2, 2024 21:59
@charliermarsh charliermarsh marked this pull request as ready for review March 2, 2024 22:00
@charliermarsh charliermarsh changed the title Always use interpreter parent for home Adjust base Python lookup logic for Windows Mar 2, 2024
@charliermarsh charliermarsh added the bug Something isn't working label Mar 2, 2024
@charliermarsh charliermarsh force-pushed the charlie/home branch 2 times, most recently from 8272a19 to 6b1305c Compare March 2, 2024 22:04
crates/uv-virtualenv/src/bare.rs Outdated Show resolved Hide resolved
@charliermarsh charliermarsh enabled auto-merge (squash) March 3, 2024 17:40
@charliermarsh charliermarsh merged commit 46265b7 into main Mar 3, 2024
7 checks passed
@charliermarsh charliermarsh deleted the charlie/home branch March 3, 2024 17:44
@konstin
Copy link
Member

konstin commented Mar 3, 2024

Linking python/cpython#114476 for future reference

charliermarsh added a commit that referenced this pull request Mar 3, 2024
## Summary

After #2121, the only remaining
issue is that calling `canonicalize` on these Pythons returns an error.

Closes #2105.

## Test Plan

Uninstalled all python.org Pythons on my Windows machine, then created a
virtualenv. The resulting config file:

```
Using Python 3.11.8 interpreter at: C:\Users\crmar\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\python.exe
Creating virtualenv at: .venv
Activate with: .venv\Scripts\activate
PS C:\Users\crmar\workspace\puffin> cat .\.venv\pyvenv.cfg
home = C:\Users\crmar\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0
implementation = CPython
version_info = 3.11.8
include-system-site-packages = false
uv = 0.1.13
prompt = puffin
```

Prior to this PR, it would fail with a canonicalization error.

Prior to #2121, it would leave a "bad" Python in the config file:

```
Using Python 3.11.8 interpreter at: C:\Users\crmar\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\python.exe
Creating virtualenv at: .venv
Activate with: .venv\Scripts\activate
PS C:\Users\crmar\workspace\puffin> cat .\.venv\pyvenv.cfg
home = C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2288.0_x64__qbz5n2kfra8p0
implementation = CPython
version_info = 3.11.8
include-system-site-packages = false
uv = 0.1.13
prompt = puffin
```

Which, once activated, would fail with:

```
(venv) PS C:\Users\crmar\workspace\puffin> python
No Python at '"C:\Users\crmar\AppData\Local\Programs\Python\Python312\python.exe'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working windows Specific to the Windows platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants