Skip to content

Commit

Permalink
chore: Only install dependencies once
Browse files Browse the repository at this point in the history
  • Loading branch information
sindre-nistad committed Jan 8, 2024
1 parent 4b3531a commit 181ba88
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions cmake/python-venv.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
set(VENV_INITIALIZED ON)
if (NOT EXISTS ${CMAKE_BINARY_DIR}/venv)
message(STATUS "Creating a new venv in ${CMAKE_BINARY_DIR}/venv")
find_package(Python3 ${Python3_VERSION} EXACT REQUIRED COMPONENTS Interpreter)
Expand All @@ -6,25 +7,27 @@ if (NOT EXISTS ${CMAKE_BINARY_DIR}/venv)
COMMAND_ERROR_IS_FATAL ANY
)
unset(${Python3_EXECUTABLE})
set(VENV_INITIALIZED OFF)
endif ()
message(STATUS "Installing necessary dependencies in ${CMAKE_BINARY_DIR}/venv")
set(Python3_EXECUTABLE "${CMAKE_BINARY_DIR}/venv/bin/python")
find_package(Python3 REQUIRED COMPONENTS Interpreter)
message(STATUS ${Python3_EXECUTABLE})

# Ensure pip ins up do date
execute_process(
COMMAND ${Python3_EXECUTABLE} -m pip install --upgrade pip
COMMAND_ERROR_IS_FATAL ANY
)
# For very old version of pip, we may need to update it twice (e.g. Python 3.6)
execute_process(
COMMAND ${Python3_EXECUTABLE} -m pip install --upgrade pip
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(
# Ensure toml / tomllib is installed
COMMAND ${Python3_EXECUTABLE} -c "
if (NOT VENV_INITIALIZED)
message(STATUS "Installing necessary dependencies in ${CMAKE_BINARY_DIR}/venv")

# Ensure pip ins up do date
execute_process(
COMMAND ${Python3_EXECUTABLE} -m pip install --upgrade pip
COMMAND_ERROR_IS_FATAL ANY
)
# For very old version of pip, we may need to update it twice (e.g. Python 3.6)
execute_process(
COMMAND ${Python3_EXECUTABLE} -m pip install --upgrade pip
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(
# Ensure toml / tomllib is installed
COMMAND ${Python3_EXECUTABLE} -c "
try:
# Newer versions of Python come with tomllib preinstalled
import tomllib
Expand All @@ -46,10 +49,11 @@ except ImportError:
check=True,
)
"
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/pyproject.toml pyproject.toml
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/bin/install-build-requirements.py
COMMAND_ERROR_IS_FATAL ANY
)
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/pyproject.toml pyproject.toml
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/bin/install-build-requirements.py
COMMAND_ERROR_IS_FATAL ANY
)
endif ()

0 comments on commit 181ba88

Please sign in to comment.