summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorSebastian Müller <gsenpo@gmail.com>2019-12-20 12:24:54 (GMT)
committerSebastian Müller <gsenpo@gmail.com>2019-12-21 14:38:00 (GMT)
commit776d27d4a4eb27f5618e682dafc1d44fba8598c6 (patch)
tree671560defc90f6bec639982692c36dbe5cbebca7 /Tests
parent9f75f9974f974611ab899675aa7bb987078e3b0d (diff)
downloadCMake-776d27d4a4eb27f5618e682dafc1d44fba8598c6.zip
CMake-776d27d4a4eb27f5618e682dafc1d44fba8598c6.tar.gz
CMake-776d27d4a4eb27f5618e682dafc1d44fba8598c6.tar.bz2
FindPython: Extend virtual environment handling by considering conda
- Add functionality to recognize and use CONDA_PREFIX environment variable - Add tests for conda virtual environments - Fixes: #20111
Diffstat (limited to 'Tests')
-rw-r--r--Tests/CMakeLists.txt2
-rw-r--r--Tests/FindPython/CMakeLists.txt13
-rw-r--r--Tests/FindPython/VirtualEnv/CMakeLists.txt4
-rw-r--r--Tests/FindPython/VirtualEnvConda/CMakeLists.txt46
-rw-r--r--Tests/FindPython/VirtualEnvConda/VirtualEnvDefault.cmake6
-rw-r--r--Tests/FindPython/VirtualEnvConda/VirtualEnvOnly.cmake16
-rw-r--r--Tests/FindPython/VirtualEnvConda/VirtualEnvStandard.cmake7
7 files changed, 93 insertions, 1 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 59f5c73..90eed4f 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -1449,7 +1449,7 @@ ${CMake_SOURCE_DIR}/Utilities/Release/push.bash --dir dev -- '${CMake_BUILD_NIGH
add_subdirectory(GoogleTest)
endif()
- if(CMake_TEST_FindPython OR CMake_TEST_FindPython_NumPy)
+ if(CMake_TEST_FindPython OR CMake_TEST_FindPython_NumPy OR CMake_TEST_FindPython_Conda)
add_subdirectory(FindPython)
endif()
diff --git a/Tests/FindPython/CMakeLists.txt b/Tests/FindPython/CMakeLists.txt
index 10c98c5..5e20dd3 100644
--- a/Tests/FindPython/CMakeLists.txt
+++ b/Tests/FindPython/CMakeLists.txt
@@ -172,3 +172,16 @@ if(CMake_TEST_FindPython_NumPy)
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
endif()
+
+ if(CMake_TEST_FindPython_Conda)
+ add_test(NAME FindPython.VirtualEnvConda COMMAND
+ ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindPython/VirtualEnvConda"
+ "${CMake_BINARY_DIR}/Tests/FindPython/VirtualEnvConda"
+ ${build_generator_args}
+ --build-project TestVirtualEnvConda
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+ )
+ endif()
diff --git a/Tests/FindPython/VirtualEnv/CMakeLists.txt b/Tests/FindPython/VirtualEnv/CMakeLists.txt
index 64ba201..9e8c673 100644
--- a/Tests/FindPython/VirtualEnv/CMakeLists.txt
+++ b/Tests/FindPython/VirtualEnv/CMakeLists.txt
@@ -21,22 +21,26 @@ endif()
add_test(NAME FindPython3.VirtualEnvDefault
COMMAND "${CMAKE_COMMAND}" -E env --unset=PYTHONHOME
+ --unset=CONDA_PREFIX
"VIRTUAL_ENV=${Python3_VIRTUAL_ENV}"
"${CMAKE_COMMAND}" "-DPYTHON3_VIRTUAL_ENV=${Python3_VIRTUAL_ENV}"
-P "${CMAKE_CURRENT_LIST_DIR}/VirtualEnvDefault.cmake")
add_test(NAME FindPython3.VirtualEnvOnly
COMMAND "${CMAKE_COMMAND}" -E env --unset=PYTHONHOME
+ --unset=CONDA_PREFIX
"VIRTUAL_ENV=${Python3_VIRTUAL_ENV}"
"${CMAKE_COMMAND}" "-DPYTHON3_VIRTUAL_ENV=${Python3_VIRTUAL_ENV}"
-P "${CMAKE_CURRENT_LIST_DIR}/VirtualEnvOnly.cmake")
add_test(NAME FindPython3.UnsetVirtualEnvOnly
COMMAND "${CMAKE_COMMAND}" -E env --unset=PYTHONHOME
--unset=VIRTUAL_ENV
+ --unset=CONDA_PREFIX
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_LIST_DIR}/VirtualEnvOnly.cmake")
add_test(NAME FindPython3.VirtualEnvStandard
COMMAND "${CMAKE_COMMAND}" -E env --unset=PYTHONHOME
+ --unset=CONDA_PREFIX
"VIRTUAL_ENV=${Python3_VIRTUAL_ENV}"
"${CMAKE_COMMAND}" "-DPYTHON3_VIRTUAL_ENV=${Python3_VIRTUAL_ENV}"
-P "${CMAKE_CURRENT_LIST_DIR}/VirtualEnvStandard.cmake")
diff --git a/Tests/FindPython/VirtualEnvConda/CMakeLists.txt b/Tests/FindPython/VirtualEnvConda/CMakeLists.txt
new file mode 100644
index 0000000..565095a
--- /dev/null
+++ b/Tests/FindPython/VirtualEnvConda/CMakeLists.txt
@@ -0,0 +1,46 @@
+cmake_minimum_required(VERSION 3.1)
+
+project(TestVirtualEnvConda LANGUAGES NONE)
+
+include(CTest)
+
+find_program(CONDA_EXECUTABLE conda)
+if (CONDA_EXECUTABLE EQUAL NOTFOUND)
+ message (FATAL_ERROR "Fail to found Conda")
+endif()
+
+set (Python3_VIRTUAL_ENV "${CMAKE_CURRENT_BINARY_DIR}/condaenv")
+
+execute_process (COMMAND "${CONDA_EXECUTABLE}" create --no-default-packages --prefix "${Python3_VIRTUAL_ENV}" --yes python=3
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE outputs
+ ERROR_VARIABLE outputs)
+if (result)
+ message (FATAL_ERROR "Fail to create virtual environment: ${outputs}")
+endif()
+
+add_test(NAME FindPython3.VirtualEnvDefaultConda
+ COMMAND "${CMAKE_COMMAND}" -E env --unset=PYTHONHOME
+ --unset=VIRTUAL_ENV
+ "CONDA_PREFIX=${Python3_VIRTUAL_ENV}"
+ "${CMAKE_COMMAND}" "-DPYTHON3_VIRTUAL_ENV=${Python3_VIRTUAL_ENV}"
+ -P "${CMAKE_CURRENT_LIST_DIR}/VirtualEnvDefault.cmake")
+
+add_test(NAME FindPython3.VirtualEnvOnlyConda
+ COMMAND "${CMAKE_COMMAND}" -E env --unset=PYTHONHOME
+ --unset=VIRTUAL_ENV
+ "CONDA_PREFIX=${Python3_VIRTUAL_ENV}"
+ "${CMAKE_COMMAND}" "-DPYTHON3_VIRTUAL_ENV=${Python3_VIRTUAL_ENV}"
+ -P "${CMAKE_CURRENT_LIST_DIR}/VirtualEnvOnly.cmake")
+add_test(NAME FindPython3.UnsetVirtualEnvOnlyConda
+ COMMAND "${CMAKE_COMMAND}" -E env --unset=PYTHONHOME
+ --unset=CONDA_PREFIX
+ --unset=VIRTUAL_ENV
+ "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_LIST_DIR}/VirtualEnvOnly.cmake")
+
+add_test(NAME FindPython3.VirtualEnvStandardConda
+ COMMAND "${CMAKE_COMMAND}" -E env --unset=PYTHONHOME
+ --unset=VIRTUAL_ENV
+ "CONDA_PREFIX=${Python3_VIRTUAL_ENV}"
+ "${CMAKE_COMMAND}" "-DPYTHON3_VIRTUAL_ENV=${Python3_VIRTUAL_ENV}"
+ -P "${CMAKE_CURRENT_LIST_DIR}/VirtualEnvStandard.cmake")
diff --git a/Tests/FindPython/VirtualEnvConda/VirtualEnvDefault.cmake b/Tests/FindPython/VirtualEnvConda/VirtualEnvDefault.cmake
new file mode 100644
index 0000000..020ecac
--- /dev/null
+++ b/Tests/FindPython/VirtualEnvConda/VirtualEnvDefault.cmake
@@ -0,0 +1,6 @@
+
+find_package (Python3 REQUIRED)
+
+if (NOT Python3_EXECUTABLE MATCHES "^${PYTHON3_VIRTUAL_ENV}/.+")
+ message (FATAL_ERROR "Fail to use virtual environment")
+endif()
diff --git a/Tests/FindPython/VirtualEnvConda/VirtualEnvOnly.cmake b/Tests/FindPython/VirtualEnvConda/VirtualEnvOnly.cmake
new file mode 100644
index 0000000..29a4924
--- /dev/null
+++ b/Tests/FindPython/VirtualEnvConda/VirtualEnvOnly.cmake
@@ -0,0 +1,16 @@
+
+#
+# Virtual environment is defined for python3
+# Trying to find a python2 using only virtual environment
+# It is expecting to fail if a virtual environment is active and to success otherwise.
+#
+set (Python2_FIND_VIRTUALENV ONLY)
+find_package (Python2 QUIET)
+
+if (PYTHON3_VIRTUAL_ENV AND Python2_FOUND)
+ message (FATAL_ERROR "Python2 unexpectedly found.")
+endif()
+
+if (NOT PYTHON3_VIRTUAL_ENV AND NOT Python2_FOUND)
+ message (FATAL_ERROR "Fail to find Python2.")
+endif()
diff --git a/Tests/FindPython/VirtualEnvConda/VirtualEnvStandard.cmake b/Tests/FindPython/VirtualEnvConda/VirtualEnvStandard.cmake
new file mode 100644
index 0000000..89f27d8
--- /dev/null
+++ b/Tests/FindPython/VirtualEnvConda/VirtualEnvStandard.cmake
@@ -0,0 +1,7 @@
+
+set (Python3_FIND_VIRTUALENV STANDARD)
+find_package (Python3 REQUIRED)
+
+if (Python3_EXECUTABLE MATCHES "^${PYTHON3_VIRTUAL_ENV}/.+")
+ message (FATAL_ERROR "Python3 virtual env unexpectedly found.")
+endif()