diff options
author | Alyssa Ross <hi@alyssa.is> | 2020-07-13 23:20:04 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2020-07-13 23:21:06 +0000 |
commit | a42c1d6d62656dcf9bd85de620f2e200a5ad22d8 (patch) | |
tree | 7d481fea9872f62a034452612be17f4494159baa /nixpkgs/pkgs/development/interpreters/python/sitecustomize.py | |
parent | 55f69a6b0e53c1c4b3e0396937c53bf5662b5519 (diff) | |
parent | 9480bae337095fd24f61380bce3174fdfe926a00 (diff) | |
download | nixlib-a42c1d6d62656dcf9bd85de620f2e200a5ad22d8.tar nixlib-a42c1d6d62656dcf9bd85de620f2e200a5ad22d8.tar.gz nixlib-a42c1d6d62656dcf9bd85de620f2e200a5ad22d8.tar.bz2 nixlib-a42c1d6d62656dcf9bd85de620f2e200a5ad22d8.tar.lz nixlib-a42c1d6d62656dcf9bd85de620f2e200a5ad22d8.tar.xz nixlib-a42c1d6d62656dcf9bd85de620f2e200a5ad22d8.tar.zst nixlib-a42c1d6d62656dcf9bd85de620f2e200a5ad22d8.zip |
Merge commit '9480bae337095fd24f61380bce3174fdfe926a00'
This is the last nixos-unstable release before 13b2903169f, which I'm a bit nervous about. So I want the update including that one to be as small as possible, hence going to this one first.
Diffstat (limited to 'nixpkgs/pkgs/development/interpreters/python/sitecustomize.py')
-rw-r--r-- | nixpkgs/pkgs/development/interpreters/python/sitecustomize.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/nixpkgs/pkgs/development/interpreters/python/sitecustomize.py b/nixpkgs/pkgs/development/interpreters/python/sitecustomize.py index 72ce951328f1..d79a4696d8ea 100644 --- a/nixpkgs/pkgs/development/interpreters/python/sitecustomize.py +++ b/nixpkgs/pkgs/development/interpreters/python/sitecustomize.py @@ -21,9 +21,11 @@ paths = os.environ.pop('NIX_PYTHONPATH', None) if paths: functools.reduce(lambda k, p: site.addsitedir(p, k), paths.split(':'), site._init_pathinfo()) -# Check whether we are in a venv. -# Note Python 2 does not support base_prefix so we assume we are not in a venv. -in_venv = sys.version_info.major == 3 and sys.prefix != sys.base_prefix +# Check whether we are in a venv or virtualenv. +# For Python 3 we check whether our `base_prefix` is different from our current `prefix`. +# For Python 2 we check whether the non-standard `real_prefix` is set. +# https://stackoverflow.com/questions/1871549/determine-if-python-is-running-inside-virtualenv +in_venv = (sys.version_info.major == 3 and sys.prefix != sys.base_prefix) or (sys.version_info.major == 2 and hasattr(sys, "real_prefix")) if not in_venv: executable = os.environ.pop('NIX_PYTHONEXECUTABLE', None) @@ -32,8 +34,6 @@ if not in_venv: if 'PYTHONEXECUTABLE' not in os.environ and executable is not None: sys.executable = executable if prefix is not None: - # Because we cannot check with Python 2 whether we are in a venv, - # creating a venv from a Nix env won't work as well with Python 2. - # Also, note that sysconfig does not like it when sys.prefix is set to None + # Sysconfig does not like it when sys.prefix is set to None sys.prefix = sys.exec_prefix = prefix site.PREFIXES.insert(0, prefix) |