Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not install required pip packages on behalf of users #935

Merged
merged 3 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/CMake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ jobs:
if: ${{ env.PYTHON != '' && env.BUILD_SWIG_PYTHON == 'ON' }}
run: |
sudo apt-get install python3-venv
python3 -m pip install --upgrade wheel
python3 -m pip install --upgrade setuptools
python3 -m pip install --upgrade wheel build setuptools

- name: Install Visualisation Dependencies
if: ${{ startswith(env.OS, 'ubuntu') && env.VISUALISATION == 'ON' }}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/Draft-Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ jobs:
if: ${{ env.PYTHON != '' && env.BUILD_SWIG_PYTHON == 'ON' }}
run: |
sudo apt-get install python3-venv
python3 -m pip install --upgrade wheel
python3 -m pip install --upgrade setuptools
python3 -m pip install --upgrade wheel build setuptools

- name: Install Visualisation Dependencies
if: ${{ startswith(env.OS, 'ubuntu') && env.VISUALISATION == 'ON' }}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/Ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ jobs:
if: ${{ env.PYTHON != '' && env.BUILD_SWIG_PYTHON == 'ON' }}
run: |
sudo apt-get install python3-venv
python3 -m pip install --upgrade wheel
python3 -m pip install --upgrade setuptools
python3 -m pip install --upgrade wheel build setuptools

- name: Install Visualisation Dependencies
if: ${{ startswith(env.OS, 'ubuntu') && env.VISUALISATION == 'ON' }}
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/Windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ 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 build setuptools

- name: Add custom problem matchers for annotations
run: echo "::add-matcher::.github/problem-matchers.json"

Expand Down
7 changes: 5 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`, `build` 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 All @@ -93,6 +94,8 @@ Building via CMake is a three step process, with slight differences depending on
2. Configure CMake into the build directory
+ Using the CMake GUI or CLI tools
+ Specifying build options such as the CUDA Compute Capabilities to target, the inclusion of Visualisation or Python components, or performance impacting features such as `SEATBELTS`. See [CMake Configuration Options](#CMake-Configuration-Options) for details of the available configuration options
+ CMake will automatically find and select compilers, libraries and python interpreters based on current environmental variables and default locations. See [Mastering CMake](https://cmake.org/cmake/help/book/mastering-cmake/chapter/Getting%20Started.html#specifying-the-compiler-to-cmake) for more information.
+ Python dependencies must be installed in the selected python environment. If needed you can instruct CMake to use a specific python implementation using the `Python_ROOT_DIR` and `Python_Executable` CMake options at configure time.
3. Build compilation targets using the configured build system
+ See [Available Targets](#Available-targets) for a list of available targets.

Expand Down Expand Up @@ -159,8 +162,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`, `build` & `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
22 changes: 10 additions & 12 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,18 +230,17 @@ 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)
search_python_module(build)

## ------
# Define custom commands to produce files in the current cmake directory, a custom target which the user invokes to build the python wheel with appropraite dependencies configured, and any post-build steps required.
Expand Down Expand Up @@ -365,7 +363,7 @@ add_custom_target(${PYTHON_MODULE_TARGET_NAME}
# Copy the python .pyd/.so file to the working dir
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${PYTHON_SWIG_TARGET_NAME}> ${PYTHON_MODULE_NAME}/$<TARGET_FILE_NAME:${PYTHON_SWIG_TARGET_NAME}>
# Build the wheel in the working dir
COMMAND ${Python3_EXECUTABLE} setup.py bdist_wheel
COMMAND ${Python3_EXECUTABLE} -m build --wheel
WORKING_DIRECTORY ${PYTHON_LIB_OUTPUT_DIRECTORY}
BYPRODUCTS
${PYTHON_LIB_OUTPUT_DIRECTORY}/${PYTHON_MODULE_NAME}
Expand All @@ -383,8 +381,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