Skip to content

Commit

Permalink
Detect current virtualenv in a more compatible way
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lunkwill42 committed Mar 30, 2023
1 parent 9e21fac commit ccd3042
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion python/nav/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit ccd3042

Please sign in to comment.