Use os.path.lexists when checking for virtualenvs #3857
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a fix for a fairly contrived situation I experience because of my particular development environment. For development, I run projects within a Vagrant virtual machine, with the source code living on my host machine (in
project/
), shared in to the virtual machine guest. I create a virtual environment on my host machine in this directory (project/venv
) so that my editor can do code completion, etc. I run, test, and package the code on the the guest machine. When runningpip install -e .
or similar commands on the guest, the code within pip fails to detect the virtual environment created on the host machine as a virtual environment, causing the command to delve down through the virtual environment directories despitepip
attempting to filter virtual environments out. This makes thepip install -e .
command take about a minute to run, compared to the few seconds when the virtual environment is correctly ignored.pip fails to detect the virtual environment in this particular case, as pip uses
os.path.exists()
to check thatproject/venv/bin/python
exists. This file does exist, but is a symlink to thepython
executable provided by the system. On my host, the target file does exist, but in the guest (which may use a different version of Python, or structure its directories differently, or...), the target file does not exist.os.path.exists()
returnsFalse
for dangling symlinks, causing the virtual environment detection code to fail.This change uses
os.path.lexists()
instead ofos.path.exists()
, which returns True for dangling symlinks.