Merge branch 'staging-next'
This commit is contained in:
@@ -107,10 +107,10 @@ in {
|
||||
sourceVersion = {
|
||||
major = "3";
|
||||
minor = "8";
|
||||
patch = "2";
|
||||
patch = "3";
|
||||
suffix = "";
|
||||
};
|
||||
sha256 = "1ps5v323cp5czfshqjmbsqw7nvrdpcbk06f62jbzaqik4gfffii6";
|
||||
sha256 = "0r2qg4pdvv52ld5dd95fl6lzzsxxxhbsxmymwcphh6624g3mxayz";
|
||||
inherit (darwin) configd;
|
||||
inherit passthruFun;
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -19,10 +19,8 @@ let
|
||||
is_nixenv = "False";
|
||||
is_virtualenv = "False";
|
||||
};
|
||||
} // lib.optionalAttrs (python.isPy3k && !python.isPyPy) {
|
||||
} // lib.optionalAttrs (!python.isPyPy) {
|
||||
# Use virtualenv from a Nix env.
|
||||
# Does not function with Python 2
|
||||
# ValueError: source and destination is the same /nix/store/38kz3j1a87cq5y59k5w7k9yk4cqgc5b2-python-2.7.18/lib/python2.7/os.py
|
||||
nixenv-virtualenv = rec {
|
||||
env = runCommand "${python.name}-virtualenv" {} ''
|
||||
${pythonVirtualEnv.interpreter} -m virtualenv $out
|
||||
@@ -39,7 +37,7 @@ let
|
||||
interpreter = env.interpreter;
|
||||
is_venv = "False";
|
||||
is_nixenv = "True";
|
||||
is_virtualenv = "True";
|
||||
is_virtualenv = "False";
|
||||
};
|
||||
} // lib.optionalAttrs (python.isPy3k && (!python.isPyPy)) rec {
|
||||
# Venv built using plain Python
|
||||
@@ -52,7 +50,7 @@ let
|
||||
interpreter = "${env}/bin/${python.executable}";
|
||||
is_venv = "True";
|
||||
is_nixenv = "False";
|
||||
is_virtualenv = "True";
|
||||
is_virtualenv = "False";
|
||||
};
|
||||
|
||||
} // lib.optionalAttrs (python.pythonAtLeast "3.8") {
|
||||
@@ -66,7 +64,7 @@ let
|
||||
interpreter = "${env}/bin/${pythonEnv.executable}";
|
||||
is_venv = "True";
|
||||
is_nixenv = "True";
|
||||
is_virtualenv = "True";
|
||||
is_virtualenv = "False";
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -43,6 +43,10 @@ class TestCasePython(unittest.TestCase):
|
||||
else:
|
||||
self.assertEqual(sys.prefix, sys.base_prefix)
|
||||
|
||||
@unittest.skipIf(sys.version_info.major==3, "sys.real_prefix is only set by virtualenv in case of Python 2.")
|
||||
def test_real_prefix(self):
|
||||
self.assertTrue(hasattr(sys, "real_prefix") == IS_VIRTUALENV)
|
||||
|
||||
def test_python_version(self):
|
||||
self.assertTrue(platform.python_version().startswith(PYTHON_VERSION))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user