-
Notifications
You must be signed in to change notification settings - Fork 19
/
python.cmake
77 lines (70 loc) · 2.97 KB
/
python.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Checks for
# - Python
# - Pip
# - Pipenv if using virtual environment (option below)
# OUTPUTS
# PYTHON_COMMAND: The command to run python scripts
# PIP_COMMAND: The command to run pip
option(NO_VENV "Disable invoking python scripts from virtual environment" OFF)
message("")
message("🐍 Python Configuration")
# ====== Generate PYTHON_COMMAND ======
IF (NO_VENV)
find_package(Python3 3.10.0...3.11.12 COMPONENTS Interpreter REQUIRED)
message(" ℹ️ Found Python ${Python3_VERSION}")
set(PYTHON_COMMAND ${Python3_EXECUTABLE})
ELSE ()
find_program(PIPENV_COMMAND pipenv REQUIRED)
IF (NOT PIPENV_COMMAND)
message(FATAL_ERROR "❌ pipenv not found. Please install it with \"pip install pipenv\"")
ENDIF ()
message(" 📟 Using pipenv command: ${PIPENV_COMMAND}")
IF (WIN32)
set(PYTHON_BASE_COMMAND python)
ELSE ()
set(PYTHON_BASE_COMMAND python3)
ENDIF ()
set(PYTHON_COMMAND ${PIPENV_COMMAND} run ${PYTHON_BASE_COMMAND})
ENDIF ()
message(" 📟 Using Python Command: \"${PYTHON_COMMAND}\"")
# ============== PIP PACKAGES and PIPENV ==============
message(" 📦 Update Python Dependencies")
IF (NO_VENV)
message(" 🔍 Finding pip...")
set(PIP_COMMAND ${PYTHON_COMMAND} -m pip)
execute_process(COMMAND ${PIP_COMMAND} --version RESULT_VARIABLE PIP_CHECK_STATUS)
IF (NOT ${PIP_CHECK_STATUS} EQUAL 0)
message(FATAL_ERROR "❌ Could not find pip. Please install pip and try again.")
ENDIF ()
message(" 📟 Using pip with \"${PIP_COMMAND}\"")
execute_process(COMMAND ${PIP_COMMAND} install -r ${CMAKE_SOURCE_DIR}/environment/requirements.txt
RESULT_VARIABLE PIP_INSTALL_STATUS
COMMAND_ERROR_IS_FATAL ANY
)
IF (NOT ${PIP_INSTALL_STATUS} EQUAL 0)
message(FATAL_ERROR "❌ Could not successfully install Python dependencies")
ENDIF ()
message(" 📦 Pip packages collected")
ELSE ()
# check that pipenv exists
message(" 🔍 Finding pipenv...")
execute_process(COMMAND ${PIPENV_COMMAND} --venv
OUTPUT_VARIABLE FIND_PIPENV_OUTPUT
RESULT_VARIABLE FIND_PIPENV_RESULT
ERROR_VARIABLE FIND_PIPENV_ERROR
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE)
IF (${FIND_PIPENV_RESULT})
message(FATAL_ERROR "Pipenv path report error: ${FIND_PIPENV_RESULT} ${FIND_PIPENV_ERROR}
Make sure that you have ran \"pipenv install\" in the root directory")
ENDIF ()
message(" 🛣 Pipenv path: ${FIND_PIPENV_OUTPUT}")
# check that dependencies are installed with pipenv
message(" 📦 Updating Pipenv dependencies...")
execute_process(COMMAND ${PIPENV_COMMAND} install RESULT_VARIABLE PIPENV_STATUS OUTPUT_QUIET)
IF (NOT ${PIPENV_STATUS} EQUAL 0)
message(FATAL_ERROR "❌ Error setting up pipenv. Please install/fix pipenv and try again.")
ENDIF ()
message(" 📦 Pipenv Dependencies Updated")
ENDIF ()
message(" ✅ Python dependencies installed")