Skip to content

Commit

Permalink
FCKIT_VENV: enable editable installation of python packages
Browse files Browse the repository at this point in the history
  • Loading branch information
awnawab authored and wdeconinck committed Sep 19, 2024
1 parent f937401 commit 8e07e3d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ ecbuild_add_option( FEATURE FCKIT_VENV
DESCRIPTION "Install Python virtual environment with fypp and a yaml parser"
CONDITION Python3_VERSION VERSION_GREATER_EQUAL 3.8 )

ecbuild_add_option( FEATURE FCKIT_VENV_EDITABLE
DEFAULT OFF
DESCRIPTION "Install editable packages in fckit Python virtual environment"
CONDITION HAVE_FCKIT_VENV )

if( HAVE_FCKIT_VENV )
fckit_install_venv()
else()
Expand Down
19 changes: 14 additions & 5 deletions cmake/fckit_install_venv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

macro( fckit_install_venv )

list( APPEND PIP_OPTIONS "--disable-pip-version-check" )
if( HAVE_FCKIT_VENV_EDITABLE )
# Use checked-out source instead of installing into venv
list( APPEND PIP_OPTIONS "-e" )
endif()

# Create a virtualenv
set( VENV_PATH ${CMAKE_CURRENT_BINARY_DIR}/fckit_venv )
ecbuild_info( "Create Python virtual environment ${VENV_PATH}" )
Expand Down Expand Up @@ -40,16 +46,18 @@ macro( fckit_install_venv )
endif()

ecbuild_info( "Install fckit_yaml_reader in virtual environment ${VENV_PATH}" )
execute_process( COMMAND ${Python3_EXECUTABLE} -m pip install --disable-pip-version-check ${CMAKE_CURRENT_SOURCE_DIR}/src/fckit/${_pkg_name} OUTPUT_QUIET )
execute_process( COMMAND ${Python3_EXECUTABLE} -m pip install ${PIP_OPTIONS} ${CMAKE_CURRENT_SOURCE_DIR}/src/fckit/${_pkg_name} OUTPUT_QUIET )

# install ruamel
ecbuild_info( "Install ruamel.yaml in virtual environment ${VENV_PATH}" )
execute_process( COMMAND ${Python3_EXECUTABLE} -m pip install --disable-pip-version-check ${CMAKE_CURRENT_SOURCE_DIR}/contrib/ruamel.yaml-0.18.6 OUTPUT_QUIET )
execute_process( COMMAND ${Python3_EXECUTABLE} -m pip install ${PIP_OPTIONS} ${CMAKE_CURRENT_SOURCE_DIR}/contrib/ruamel.yaml-0.18.6 OUTPUT_QUIET )

# install fypp
if( NOT HAVE_FCKIT_VENV_EDITABLE )
list( APPEND PIP_OPTIONS "--use-pep517" )
endif()
ecbuild_info( "Install fypp in virtual environment ${VENV_PATH}" )
execute_process( COMMAND ${Python3_EXECUTABLE} -m pip install --use-pep517 --disable-pip-version-check
${CMAKE_CURRENT_SOURCE_DIR}/contrib/fypp-3.2-b8dd58b-20230822 OUTPUT_QUIET )
execute_process( COMMAND ${Python3_EXECUTABLE} -m pip install ${PIP_OPTIONS} ${CMAKE_CURRENT_SOURCE_DIR}/contrib/fypp-3.2-b8dd58b-20230822 OUTPUT_QUIET )

if( ECBUILD_INSTALL_LIBRARY_HEADERS )
install( DIRECTORY ${VENV_PATH} DESTINATION . PATTERN "bin/*" PERMISSIONS ${install_permissions} )
Expand All @@ -66,4 +74,5 @@ macro( fckit_install_venv )
# reset Python3_EXECUTABLE to the system install
set( Python3_EXECUTABLE ${Python3_EXECUTABLE_CACHE} )

endmacro()
endmacro()

0 comments on commit 8e07e3d

Please sign in to comment.