Skip to content

Commit

Permalink
Error at CMake Configure time for missing python packages
Browse files Browse the repository at this point in the history
Wheel, setuptools and optionall venv are requred.
Installing into --user automatically would fail in some cases, and installing not into user into a not-generated venv is bad form.

Closes #639
  • Loading branch information
ptheywood authored and mondus committed Oct 26, 2022
1 parent c75f408 commit ca4a9e8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/Windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ jobs:
with:
python-version: ${{ env.PYTHON }}

- name: Install python dependencies
if: ${{ env.PYTHON != '' && env.BUILD_SWIG_PYTHON == 'ON' }}
run: |
python3 -m pip install --upgrade wheel
python3 -m pip install --upgrade setuptools
- name: Add custom problem matchers for annotations
run: echo "::add-matcher::.github/problem-matchers.json"

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Optionally:
+ [cpplint](https://github.com/cpplint/cpplint) for linting code
+ [Doxygen](http://www.doxygen.nl/) to build the documentation
+ [Python](https://www.python.org/) `>= 3.7` for python integration
+ With `setuptools`, `wheel` and optionally `venv` python packages installed
+ [swig](http://www.swig.org/) `>= 4.0.2` for python integration
+ Swig `4.x` will be automatically downloaded by CMake if not provided (if possible).
+ [FLAMEGPU2-visualiser](https://github.com/FLAMEGPU/FLAMEGPU2-visualiser) dependencies
Expand Down Expand Up @@ -159,8 +160,8 @@ cmake --build . --target all
| `CMAKE_BUILD_TYPE` | `Release`/`Debug`/`MinSizeRel`/`RelWithDebInfo` | Select the build configuration for single-target generators such as `make` |
| `SEATBELTS` | `ON`/`OFF` | Enable / Disable additional runtime checks which harm performance but increase usability. Default `ON` |
| `CUDA_ARCH` | `"52 60 70 80"` | Select [CUDA Compute Capabilities](https://developer.nvidia.com/cuda-gpus) to build/optimise for, as a space or `;` separated list. Defaults to `""` |
| `BUILD_SWIG_PYTHON` | `ON`/`OFF` | Enable Python target `pyflamegpu` via Swig. Default `OFF` |
| `BUILD_SWIG_PYTHON_VENV` | `ON`/`OFF` | Use a python `venv` when building the python Swig target. Default `ON`. |
| `BUILD_SWIG_PYTHON` | `ON`/`OFF` | Enable Python target `pyflamegpu` via Swig. Default `OFF`. Python packages `setuptools` & `wheel` required |
| `BUILD_SWIG_PYTHON_VENV` | `ON`/`OFF` | Use a python `venv` when building the python Swig target. Default `ON`. Python package `venv` required |
| `BUILD_TESTS` | `ON`/`OFF` | Build the C++/CUDA test suite. Default `OFF`. |
| `BUILD_TESTS_DEV` | `ON`/`OFF` | Build the reduced-scope development test suite. Default `OFF` |
| `VISUALISATION` | `ON`/`OFF` | Enable Visualisation. Default `OFF`. |
Expand Down
19 changes: 8 additions & 11 deletions swig/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ file(GENERATE
OUTPUT ${PYTHON_LIB_OUTPUT_DIRECTORY}/${PYTHON_MODULE_NAME}/__init__.py
INPUT ${PYTHON_LIB_TEMP_DIRECTORY}/__init__.py.in)

# Function to find if python module MODULE_NAME is available, if not then install it to the Python user install directory.
# @todo - we should not be performing user installs/ upgrades of setuptools/wheel. See https://github.com/FLAMEGPU/FLAMEGPU2/issues/639
# Function to find if python module MODULE_NAME is available, and error if it is not available.
function(search_python_module MODULE_NAME)
execute_process(
COMMAND ${Python3_EXECUTABLE} -c "import ${MODULE_NAME}; print(${MODULE_NAME}.__version__) if hasattr(${MODULE_NAME}, '__version__') else print('Unknown');"
Expand All @@ -231,16 +230,14 @@ function(search_python_module MODULE_NAME)
if(${_RESULT} STREQUAL "0")
message(STATUS "Found python module: ${MODULE_NAME} (version \"${MODULE_VERSION}\")")
else()
message(WARNING "Can't find python module \"${MODULE_NAME}\", user install it using pip...")
execute_process(
COMMAND ${Python3_EXECUTABLE} -m pip install --upgrade --user ${MODULE_NAME}
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(FATAL_ERROR
" Unable to find required python module \"${MODULE_NAME}\".\n"
" Please install this to your python environment, e.g.\n"
" python3 -m pip install ${MODULE_NAME}")
endif()
endfunction()

# Look for required python modules to build the python module
# @todo - Do not install into the --user see https://github.com/FLAMEGPU/FLAMEGPU2/issues/639. Either error, or let python error saying wheel is missing instead (or create and use a venv).
# Look for required python modules to build the python module, error if they are not found.
search_python_module(setuptools)
search_python_module(wheel)

Expand Down Expand Up @@ -383,8 +380,8 @@ add_dependencies(${PYTHON_MODULE_TARGET_NAME} ${PYTHON_SWIG_TARGET_NAME})

# Build Virtual Environment for python testing and install the packaged wheel
if(BUILD_SWIG_PYTHON_VENV)
# Look for python module venv
search_python_module(venv) # @todo - do not install if missing, configuration error instead?
# Look for python module venv, error if not found
search_python_module(venv)
# Testing using a virtual environment
set(VENV_EXECUTABLE ${Python3_EXECUTABLE} -m venv)
set(VENV_DIR ${PYTHON_LIB_OUTPUT_DIRECTORY}/venv)
Expand Down

0 comments on commit ca4a9e8

Please sign in to comment.