Skip to content

Fix the detection of an unhappy installation path in a venv under Windows#554

Open
tramora wants to merge 1 commit intomainfrom
548-fix-status-pip-on-windows
Open

Fix the detection of an unhappy installation path in a venv under Windows#554
tramora wants to merge 1 commit intomainfrom
548-fix-status-pip-on-windows

Conversation

@tramora
Copy link
Collaborator

@tramora tramora commented Feb 13, 2026

External tools like VSCode can modify the case of the path saved in sys.executable

Fixes #548

The case is indeed reproductible in saving the value of sys.executable and altering its case.

Implementing an automatic test would required extracting a function returning sys.executable and mocking it during the test.
Possible but but a bit overkill.


TODO Before Asking for a Review

  • Rebase your branch to the latest version of main (or main-v10)
  • Make sure all CI workflows are green
  • When adding a public feature/fix: Update the Unreleased section of CHANGELOG.md (no date)
  • Self-Review: Review "Files Changed" tab and fix any problems you find
  • API Docs (only if there are changes in docstrings, rst files or samples):
    • Check the docs build without warning: see the log of the API Docs workflow
    • Check that your changes render well in HTML: download the API Docs artifact and open index.html
    • If there are any problems it is faster to iterate by building locally the API Docs

@tramora tramora requested review from popescu-v and removed request for popescu-v February 13, 2026 17:32
@tramora tramora force-pushed the 548-fix-status-pip-on-windows branch from 1029be1 to 92b1a47 Compare February 16, 2026 15:06
@tramora tramora requested a review from popescu-v February 16, 2026 16:00
Copy link
Collaborator

@popescu-v popescu-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comments.

@tramora tramora force-pushed the 548-fix-status-pip-on-windows branch from 92b1a47 to 3606064 Compare February 17, 2026 18:12
@tramora tramora requested a review from popescu-v February 17, 2026 18:13
Copy link
Collaborator

@popescu-v popescu-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the remaining open comment.

@tramora tramora force-pushed the 548-fix-status-pip-on-windows branch from 3606064 to c088121 Compare February 20, 2026 17:13
@tramora tramora requested a review from popescu-v February 20, 2026 17:18
Copy link
Collaborator

@popescu-v popescu-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few remaining issues (see the comments).

@tramora tramora force-pushed the 548-fix-status-pip-on-windows branch from c088121 to dee6493 Compare February 26, 2026 12:11
@tramora tramora requested a review from popescu-v February 26, 2026 12:11
Parameters
----------
library_root_dir : PosixPath
library_root_dir_path : PosixPath
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a Path rather than a PosixPath IMHO, to account for Windows paths (and their case-insesitiveness).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, depending on the platform the constructor built either a WindowsPath instance or a PosixPath one.
Fixed

Comment on lines 1176 to 1177
library_root_dir = str(library_root_dir_path)
conda_prefix = os.environ["CONDA_PREFIX"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could keep library_root_dir_path as such and comapre it with Path(os.environ["CONDA_PREFIX"]). This should account for Windows case-insensitiveness specifics. Cf. https://docs.python.org/3/library/pathlib.html#general-properties:

>>> PureWindowsPath('foo') == PureWindowsPath('FOO')
True

Copy link
Collaborator Author

@tramora tramora Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This WindowsPath case-insensitivess is very interesting and suggests an appealing and elegant way to improve the tests.

But after a review it appears that the majority of the tests are prefix checking (startswith()) and only for 2 cases we have exact paths comparison.

To my humble opinion it is not worth the hassle and this tolower() way seems the most obvious and readable.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, some of this cases could be tackled by using subpath in path.parents, in case we want to test a certain path starts with a subdirectory, or even subpath == path.parents[-2] :

>>> path = Path("/dir1/dir2/dir3/file.txt")
>>> path.parents[-2]
PosixPath("/dir1") # or WindowsPath("/dir1")

Or we can use Path.parts:

>>> subpath = Path("/dir1")
>>>path = Path("/dir1/dir2/dir3/file.txt")
>>> subpath.parts == path.parts[: len(subpath.parts)] # Check path starts with subpath
True

Etc. So, IMHO it's better to systematize on using pathlib because it:

  • reduces conditional OS-dependent code
  • thus, reduces maintenance costs
  • hence, reducing potential bugs or missing OS-dependent code in this respect.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK let's got for it. The comparisons will have to be exact then (not using startswith() with a prefix any longer).
One must be careful about the exact folder hierarchy to avoid comparison errors.

# the path casing on Windows
sys_base_prefix = sys.base_prefix
sys_prefix = sys.prefix
if platform.system() == "Windows":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using (and comparing) pathlib.Paths directly should account for Windows case-insensitiveness and make OS-conditional code in this respect unneessary.

@tramora tramora force-pushed the 548-fix-status-pip-on-windows branch from dee6493 to 886058e Compare February 26, 2026 19:43
@tramora tramora requested review from popescu-v and removed request for popescu-v February 26, 2026 19:47
- External tools like VSCode can modify for example the case of the path saved in `sys.executable`
- As a general rule a pathlib.Path object is always built. Depending on the OS either a PosixPath or a WindowsPath instance is created. This later sees case-insensitive paths.
@tramora tramora force-pushed the 548-fix-status-pip-on-windows branch from 886058e to 3ed7b8c Compare March 2, 2026 00:34
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.

Spurious Warning Occurs in Binary + Pip installations on Windows

2 participants