Skip to content

Commit

Permalink
CMake: More Pip Control Options
Browse files Browse the repository at this point in the history
- `PY_PIP_OPTIONS`: Passed to `python -m pip ...`
- `PY_PIP_INSTALL_OPTIONS`: Passed to `python -m pip install ...` (formerly `PYINSTALLOPTIONS`)
  • Loading branch information
ax3l committed Aug 12, 2024
1 parent cd1682e commit d189bca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,9 @@ install(CODE "file(CREATE_LINK
# pip helpers for the impactx package #########################################
#
if(ImpactX_PYTHON)
set(PYINSTALLOPTIONS "" CACHE STRING
set(PY_PIP_OPTIONS "-v" CACHE STRING
"Additional parameters to pass to `pip`")
set(PY_PIP_INSTALL_OPTIONS "" CACHE STRING
"Additional parameters to pass to `pip install`")

# add a prefix to custom targets so we do not collide if used as a subproject
Expand All @@ -410,7 +412,7 @@ if(ImpactX_PYTHON)
${CMAKE_COMMAND} -E rm -f -r impactx-whl
COMMAND
${CMAKE_COMMAND} -E env PYIMPACTX_LIBDIR=$<TARGET_FILE_DIR:pyImpactX>
${Python_EXECUTABLE} -m pip wheel -v --no-build-isolation --no-deps --wheel-dir=impactx-whl ${ImpactX_SOURCE_DIR}
${Python_EXECUTABLE} -m pip ${PY_PIP_OPTIONS} wheel --no-build-isolation --no-deps --wheel-dir=impactx-whl ${ImpactX_SOURCE_DIR}
WORKING_DIRECTORY
${ImpactX_BINARY_DIR}
DEPENDS
Expand All @@ -424,7 +426,7 @@ if(ImpactX_PYTHON)
set(pyImpactX_REQUIREMENT_FILE "requirements.txt")
endif()
add_custom_target(${ImpactX_CUSTOM_TARGET_PREFIX}pip_install_requirements
${Python_EXECUTABLE} -m pip install ${PYINSTALLOPTIONS} -r "${ImpactX_SOURCE_DIR}/${pyImpactX_REQUIREMENT_FILE}"
${Python_EXECUTABLE} -m pip ${PY_PIP_OPTIONS} install ${PY_PIP_INSTALL_OPTIONS} -r "${ImpactX_SOURCE_DIR}/${pyImpactX_REQUIREMENT_FILE}"
WORKING_DIRECTORY
${ImpactX_BINARY_DIR}
)
Expand All @@ -441,7 +443,7 @@ if(ImpactX_PYTHON)
# because otherwise pip would also force reinstall all dependencies.
add_custom_target(${ImpactX_CUSTOM_TARGET_PREFIX}pip_install
${CMAKE_COMMAND} -E env IMPACTX_MPI=${ImpactX_MPI}
${Python_EXECUTABLE} -m pip install --force-reinstall --no-index --no-deps ${PYINSTALLOPTIONS} --find-links=impactx-whl impactx
${Python_EXECUTABLE} -m pip ${PY_PIP_OPTIONS} install --force-reinstall --no-index --no-deps ${PY_PIP_INSTALL_OPTIONS} --find-links=impactx-whl impactx
WORKING_DIRECTORY
${ImpactX_BINARY_DIR}
DEPENDS
Expand All @@ -453,7 +455,7 @@ if(ImpactX_PYTHON)
# this is for package managers only
add_custom_target(${ImpactX_CUSTOM_TARGET_PREFIX}pip_install_nodeps
${CMAKE_COMMAND} -E env IMPACTX_MPI=${ImpactX_MPI}
${Python_EXECUTABLE} -m pip install --force-reinstall --no-index --no-deps ${PYINSTALLOPTIONS} --find-links=impactx-whl impactx
${Python_EXECUTABLE} -m pip ${PY_PIP_OPTIONS} install --force-reinstall --no-index --no-deps ${PY_PIP_INSTALL_OPTIONS} --find-links=impactx-whl impactx
WORKING_DIRECTORY
${ImpactX_BINARY_DIR}
DEPENDS
Expand Down
4 changes: 3 additions & 1 deletion docs/source/install/cmake.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Developers could now change the ImpactX source code and then call the install li
.. tip::

If you do *not* develop with :ref:`a user-level package manager <install-dependencies>`, e.g., because you rely on a HPC system's environment modules, then consider to set up a virtual environment via `Python venv <https://docs.python.org/3/library/venv.html>`__.
Otherwise, without a virtual environment, you likely need to add the CMake option ``-DPYINSTALLOPTIONS="--user"``.
Otherwise, without a virtual environment, you likely need to add the CMake option ``-DPY_PIP_INSTALL_OPTIONS="--user"``.


Build Options
Expand All @@ -112,6 +112,8 @@ CMake Option Default & Values Des
``ImpactX_PRECISION`` SINGLE/**DOUBLE** Floating point precision (single/double)
``ImpactX_PYTHON`` ON/**OFF** Python bindings
``Python_EXECUTABLE`` (newest found) Path to Python executable
``PY_PIP_OPTIONS`` ``-v`` Additional options for ``pip``, e.g., ``-vvv``
``PY_PIP_INSTALL_OPTIONS`` Additional options for ``pip install``, e.g., ``--user``
=============================== ============================================ ===========================================================

ImpactX can be configured in further detail with options from AMReX, which are `documented in the AMReX manual <https://amrex-codes.github.io/amrex/docs_html/BuildingAMReX.html#customization-options>`_.
Expand Down

0 comments on commit d189bca

Please sign in to comment.