Skip to content
Snippets Groups Projects
Commit e6d72f8f authored by Andreas Dedner's avatar Andreas Dedner
Browse files

use an external venv if active

parent 79359e69
Branches
Tags
1 merge request!960refactor the way python is used in dune
......@@ -82,6 +82,16 @@ set(DUNE_PYTHON_EXTERNAL_VIRTUALENV_FOR_ABSOLUTE_BUILDDIR ON CACHE BOOL
"Place Python virtualenv in top-level directory \"dune-python-env\" when using an absolute build directory"
)
# check if we are in a venv already
if(DUNE_PYTHON_VIRTUALENV_PATH STREQUAL "")
dune_execute_process(COMMAND ${Python3_EXECUTABLE}
${scriptdir}/venvpath.py
OUTPUT_VARIABLE DUNE_PYTHON_VIRTUALENV_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
# if no virtual env path set so far check dune modules
if(DUNE_PYTHON_VIRTUALENV_PATH STREQUAL "")
foreach(mod ${ALL_DEPENDENCIES})
if(IS_DIRECTORY ${${mod}_DIR}/dune-env)
......
......@@ -3,6 +3,7 @@ install(FILES
conf.py.in
CreateDoxyFile.cmake
envdetect.py
venvpath.py
FinalizeHeadercheck.cmake
index.rst.in
InstallFile.cmake
......
import sys,os
def inVEnv():
# check whether we are in a anaconda environment
# were the checks based on prefix and base_prefix
# seem to fail
if "CONDA_DEFAULT_ENV" in os.environ:
return 1
# If sys.real_prefix exists, this is a virtualenv set up with the virtualenv package
real_prefix = hasattr(sys, 'real_prefix')
if real_prefix:
return 1
# If a virtualenv is set up with pyvenv, we check for equality of base_prefix and prefix
if hasattr(sys, 'base_prefix'):
return (sys.prefix != sys.base_prefix)
# If none of the above conditions triggered, this is probably no virtualenv interpreter
return 0
if __name__ == "__main__":
if not inVEnv():
print("")
else:
print(sys.prefix)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment