diff --git a/src/pystencilssfg/cmake/FindPystencilsSfg.cmake b/src/pystencilssfg/cmake/FindPystencilsSfg.cmake index 40af3f1cfb406daf4dd0d0ebbc4ee738f74827e4..f76fe661cb2c12892116da5d73aaa00a0efc1c1a 100644 --- a/src/pystencilssfg/cmake/FindPystencilsSfg.cmake +++ b/src/pystencilssfg/cmake/FindPystencilsSfg.cmake @@ -27,7 +27,7 @@ if(NOT DEFINED CACHE{PystencilsSfg_PYTHON_INTERPRETER}) set( _sfg_cache_python_init ${PystencilsSfg_PYTHON_PATH} ) elseif (CODEGEN_PRIVATE_VENV) - # ... or create own venv ... + # ... or create an own venv ... set(CODEGEN_VENV_PATH ${CMAKE_CURRENT_BINARY_DIR}/codegen-venv CACHE PATH "Location of the virtual environment used for code generation") set(_venv_python_exe ${CODEGEN_VENV_PATH}/bin/python) @@ -44,14 +44,26 @@ if(NOT DEFINED CACHE{PystencilsSfg_PYTHON_INTERPRETER}) ) endif() - message( STATUS "Installing required Python packages..." ) - set(CODEGEN_VENV_REQUIREMENTS ${PROJECT_SOURCE_DIR}/requirements.txt CACHE PATH "Location of the requirements installed in the virtual environment used for code generation") - execute_process( - COMMAND ${_venv_python_exe} -m pip install -r ${CODEGEN_VENV_REQUIREMENTS} - OUTPUT_QUIET - ) - #TODO automatically install pystencilssfg/pystencils + set(CODEGEN_VENV_REQUIREMENTS ${PROJECT_SOURCE_DIR}/requirements.txt CACHE FILEPATH "Location of the requirements installed in the virtual environment used for code generation") + if (EXISTS ${CODEGEN_VENV_REQUIREMENTS}) + message( STATUS "Installing required Python packages from ${CODEGEN_VENV_REQUIREMENTS}" ) + execute_process( COMMAND ${_venv_python_exe} -m pip install -r ${CODEGEN_VENV_REQUIREMENTS} OUTPUT_QUIET) + else() + set(Pystencils_URL "git+https://i10git.cs.fau.de/pycodegen/pystencils.git@v2.0-dev" CACHE STRING "Location of pystencils to installed in the virtual environment used for code generation") + set(PystencilsSfg_URL "git+https://i10git.cs.fau.de/pycodegen/pystencils-sfg.git" CACHE STRING "Location of pystencils-sfg to installed in the virtual environment used for code generation") + + message( STATUS "Installing required Pystencils from ${Pystencils_URL}" ) + execute_process( + COMMAND ${_venv_python_exe} -m pip install "${Pystencils_URL}" + OUTPUT_QUIET + ) + message( STATUS "Installing required Pystencils-sfg from ${PystencilsSfg_URL}" ) + execute_process( + COMMAND ${_venv_python_exe} -m pip install "${PystencilsSfg_URL}" + OUTPUT_QUIET + ) + endif() set( _sfg_private_venv_done TRUE CACHE BOOL "" ) mark_as_advanced(_sfg_private_venv_done) diff --git a/tests/integration/test_cmake.py b/tests/integration/test_cmake.py index 94853ac1b8143ff7149e5a268e086decfed1af61..05ff2d513f36aac4258770db0ab6b8d41fb99860 100644 --- a/tests/integration/test_cmake.py +++ b/tests/integration/test_cmake.py @@ -18,7 +18,7 @@ def test_cmake_project(tmp_path, config_source): result = subprocess.run(obtain_find_module_cmd, cwd=CMAKE_PROJECT_DIR) assert result.returncode == 0 - cmake_configure_cmd = ["cmake", "-S", CMAKE_PROJECT_DIR, "-B", str(tmp_path)] + cmake_configure_cmd = ["cmake", "-S", CMAKE_PROJECT_DIR, "-B", str(tmp_path), "-DCODEGEN_PRIVATE_VENV=OFF"] if config_source is not None: cmake_configure_cmd.append(f"-D{config_source}=ON") configure_result = subprocess.run(cmake_configure_cmd) @@ -49,3 +49,14 @@ def test_cmake_project(tmp_path, config_source): custom_dir_output = tmp_path / "my-output" / "CustomDirTest.hpp" assert custom_dir_output.exists() assert "#define NOTHING" in custom_dir_output.read_text() + + +def test_cmake_project_autoinstall(tmp_path): + obtain_find_module_cmd = ["sfg-cli", "cmake", "make-find-module"] + + result = subprocess.run(obtain_find_module_cmd, cwd=CMAKE_PROJECT_DIR) + assert result.returncode == 0 + + cmake_configure_cmd = ["cmake", "-S", CMAKE_PROJECT_DIR, "-B", str(tmp_path), "-DCODEGEN_PRIVATE_VENV=ON"] + configure_result = subprocess.run(cmake_configure_cmd) + assert configure_result.returncode == 0