Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support python virtual environments #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ cgrowth_get_color_flags()

IF ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
# set discovered python local folder
cmake_path(SET PY_LOCAL_DIR "${PY_LOCAL_DIR}")
string(REGEX REPLACE "\\\\" "/" PY_LOCAL_DIR ${PY_LOCAL_DIR})

set( Python3_INSTALL_DIR "${PY_LOCAL_DIR}" )
set( Python3_INSTALL_DIR "${PY_LOCAL_DIR}" CACHE STRING "python install dir" FORCE)
Expand All @@ -93,7 +93,9 @@ IF ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )

# get local user library folder as default install prefix ()
if (Python3_EXECUTABLE MATCHES "conda")
cmake_path(SET CMAKE_INSTALL_PREFIX "$ENV{CONDA_PREFIX}")
set(CMAKE_INSTALL_PREFIX "$ENV{CONDA_PREFIX}")
elseif (EXISTS $ENV{VIRTUAL_ENV})
set(CMAKE_INSTALL_PREFIX "$ENV{VIRTUAL_ENV}")
else ()
execute_process(COMMAND ${Python3_EXECUTABLE} -m site --user-base OUTPUT_VARIABLE CMAKE_INSTALL_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
endif ()
Expand All @@ -109,7 +111,7 @@ IF ( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT )
endif ()
endif ()

cmake_path(SET CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
string(REGEX REPLACE "\\\\" "/" CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})

# cache it
set( CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE STRING "install prefix" FORCE)
Expand All @@ -119,7 +121,7 @@ ELSEIF ( ("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local") AND NOT ("$CACHE{CMAK
ELSE ()
# make sure we get the absolute path
get_filename_component(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" ABSOLUTE)
cmake_path(SET CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
string(REGEX REPLACE "\\\\" "/" CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
ENDIF ()

# set libraries in binaries installation directories
Expand Down
8 changes: 5 additions & 3 deletions cmake/ProcessOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ function( CGROWTH_PROCESS_WITH_PYTHON )
set( HAVE_PYTHON OFF PARENT_SCOPE )
string(REGEX MATCH "^3([.][0-9]+)?" VALID_PYVERSION "${with-python}" )

set(Python_FIND_VIRTUALENV FIRST)

if ( ${with-python} STREQUAL "ON" OR VALID_PYVERSION OR EXISTS ${with-python} )

# Localize the Python interpreter
Expand All @@ -145,7 +147,7 @@ print('.'.join(str(v) for v in sys.version_info));
print(sys.prefix);
print(s.get_python_inc(plat_specific=True));
print(s.get_python_lib(plat_specific=True));
print(s.get_config_var('SO'));
print(s.get_config_var('EXT_SUFFIX'));
print(hasattr(sys, 'gettotalrefcount')+0);
print(struct.calcsize('@P'));
print(s.get_config_var('LDVERSION') or s.get_config_var('VERSION'));
Expand Down Expand Up @@ -217,13 +219,13 @@ print(s.get_config_var('MULTIARCH') or '');
endif ()

# set local install dir for python packages
if (Python3_EXECUTABLE MATCHES "conda")
if (Python3_EXECUTABLE MATCHES "conda" OR EXISTS "$ENV{VIRTUAL_ENV}")
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import site; print([v for v in site.getsitepackages() if v.endswith('site-packages')][0])" OUTPUT_VARIABLE PY_LOCAL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
else ()
execute_process(COMMAND ${Python3_EXECUTABLE} -m site --user-site OUTPUT_VARIABLE PY_LOCAL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
endif ()

cmake_path(SET PY_LOCAL_DIR "${PY_LOCAL_DIR}")
string(REGEX REPLACE "\\\\" "/" PY_LOCAL_DIR ${PY_LOCAL_DIR})

# create the directory if it does not exist
file(MAKE_DIRECTORY "${PY_LOCAL_DIR}")
Expand Down
Loading