From ccd3042924b336bb138693d6f619af6c296d76ad Mon Sep 17 00:00:00 2001 From: Morten Brekkevold Date: Thu, 9 Feb 2023 15:44:33 +0100 Subject: [PATCH] Detect current virtualenv in a more compatible way This broke down horribly during a bit of reorganization of how the tests are run, and under which versions of virtualenv they run. See https://stackoverflow.com/a/1883251 for details on why this needs to change. --- python/nav/config.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/python/nav/config.py b/python/nav/config.py index 340195aef2..9a500a93b9 100644 --- a/python/nav/config.py +++ b/python/nav/config.py @@ -42,7 +42,14 @@ '/etc/nav', os.path.join(buildconf.datadir, 'conf'), ] -_venv = os.getenv('VIRTUAL_ENV') +# If running inside a virtualenv, add that virtualenv to the search path as well: +_base_prefix = ( + # Detect the base prefix in a manner compatible with both old and new virtualenv + getattr(sys, "base_prefix", None) + or getattr(sys, "real_prefix", None) + or sys.prefix +) +_venv = sys.prefix if sys.prefix != _base_prefix else None if _venv: CONFIG_LOCATIONS = [ os.path.join(_venv, 'etc'),