Closed ma-sadeghi closed 5 months ago
Sure. How is it not reliable? What would be better?
VIRTUAL_ENV
is not necessarily exported (for instance here). The documented way is to compare sys.prefix
and sys.base_prefix
. Replacing
with:
vprefix = sys.prefix if sys.prefix != sys.base_prefix else None
Fixes the issue.
Ah cool, yeah a PR for that sounds good. Please include a link to the docs in a comment.
This can also resolve the ambiguity which currently causes and error if both VIRTUAL_ENV and CONDA_PREFIX are set - with this method we are sure that the virtual environment takes precedence (i.e. have created a virtual environment inside a Conda environment and not the other way around).
Just need to double check that the test doesn't pass in a Conda environment.
Would you consider a PR refactoring the way to identify if in a virtualenv? Currently, it's by inspecting
VIRTUAL_ENV
environment variable, which is not reliable.