Skip to content

Commit

Permalink
Use better pattern for scikit-build extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavezac committed May 26, 2020
1 parent ce22ceb commit 1b01524
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 26 deletions.
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,8 @@ if(NOT Python3_FOUND AND NOT Python2_FOUND)
endif()

if(Python3_FOUND)
function(Python_add_library)
Python3_add_library(${ARGV})
endfunction()
set(PYVER PY3)
else()
function(Python_add_library)
Python2_add_library(${ARGV})
endfunction()
set(PYVER PY2)
endif()

Expand Down
21 changes: 11 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ The simplest approach is to install via

.. code:: bash
mkvirtualenv --system-site-packages pylada
python -m venv pylada
source pylada/bin/activate
pip install git+https://github.com/pylada/pylada-light
This last approach is recommended since it keeps the pylada environment
isolated from the rest of the system. Susbsequently, this environment can
be accessed by running the second line.
Expand All @@ -62,19 +62,20 @@ Installation for development

.. code:: bash
mkvirtualenv --system-site-packages pylada
python -m venv pylada
source pylada/bin/activate
git clone https://github.com/pylada/pylada-light
cd pylada-light
pip install cython setuptools wheel scikit-build cmake ninja numpy
python setup.py develop
python -m pip install cython setuptools wheel scikit-build cmake ninja numpy
python -m pip install -e .[dev]
python setup.py test
ln -s src/pylada . # because https://github.com/scikit-build/scikit-build/issues/363
The above creates a virtual environment and installs pylada inside it in
development mode. This means that the virtual environment will know about
the pylada flavor in development. It is possible to edit a file, do
:bash:`make`, launch python and debug. One just needs to active the virtual
environment once per session.
:bash:`make`, launch python and debug. One just needs to active the
virtual environment once per session.

When modifying files that are built (`.pyx`, `.cc`, `.h`), it is necessary to run `python
setup.py develop` again.
When modifying files that are built (`.pyx`, `.cc`, `.h`), it may be
necessary to run `python setup.py develop` again.
1 change: 1 addition & 0 deletions src/pylada/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/_version.py"
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/_version.py" DESTINATION ${PY_ROOT_DIR})

include_directories("${PYTHON_INCLUDE_DIR}")
add_subdirectory(crystal)
add_subdirectory(decorations)
add_subdirectory(ewald)
10 changes: 6 additions & 4 deletions src/pylada/crystal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ set(cython_sources
foreach(filename ${cython_sources})
get_filename_component(name "${filename}" NAME_WE)
add_cython_target(cython_${name} ${filename} CXX ${PYVER}})
Python_add_library(${name} MODULE ${cython_${name}})
target_link_libraries(${name} PRIVATE Eigen3::Eigen)
add_library(${name} MODULE ${cython_${name}})
python_extension_module(${name})
target_link_libraries(${name} Eigen3::Eigen)
target_include_directories(${name} PRIVATE "${PY_HEADER_DIR}" "${NumPy_INCLUDE_DIRS}")
install(TARGETS ${name} LIBRARY DESTINATION ${PY_ROOT_DIR}/crystal)
endforeach()

add_cython_target(cython_cutilities cutilities.pyx CXX ${PYVER})
Python_add_library(cutilities MODULE ${cython_cutilities} smith_normal_form.cc gruber.cc noopt.cc)
add_library(cutilities MODULE ${cython_cutilities} smith_normal_form.cc gruber.cc noopt.cc)
python_extension_module(cutilities)
target_include_directories(cutilities PRIVATE "${PY_HEADER_DIR}" "${NumPy_INCLUDE_DIRS}")
target_link_libraries(cutilities PRIVATE Eigen3::Eigen)
target_link_libraries(cutilities Eigen3::Eigen)
install(TARGETS cutilities LIBRARY DESTINATION ${PY_ROOT_DIR}/crystal)

add_subdirectory(defects)
10 changes: 7 additions & 3 deletions src/pylada/crystal/defects/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
###############################

add_cython_target(defects_cython _defects.pyx CXX ${PYVER})
Python_add_library(_defects MODULE ${defects_cython} third_order.cc)
target_link_libraries(_defects PRIVATE Eigen3::Eigen)
target_include_directories(_defects PRIVATE "${PY_HEADER_DIR}" "${NumPy_INCLUDE_DIRS}")
add_library(_defects MODULE ${defects_cython} third_order.cc)
python_extension_module(_defects)
target_link_libraries(_defects Eigen3::Eigen)
target_include_directories(
_defects PRIVATE
"${PY_HEADER_DIR}" "${NumPy_INCLUDE_DIRS}" "${PYTHON_INCLUDE_DIR}"
)
install(TARGETS _defects LIBRARY DESTINATION ${PY_ROOT_DIR}/crystal/defects)
8 changes: 6 additions & 2 deletions src/pylada/decorations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
###############################

add_cython_target(decorations_cython _decorations.pyx CXX ${PYVER}})
Python_add_library(_decorations MODULE ${decorations_cython})
target_include_directories(_decorations PRIVATE "${PY_HEADER_DIR}" "${NumPy_INCLUDE_DIRS}")
add_library(_decorations MODULE ${decorations_cython})
python_extension_module(_decorations)
target_include_directories(
_decorations PRIVATE
"${PY_HEADER_DIR}" "${NumPy_INCLUDE_DIRS}" "${PYTHON_INCLUDE_DIR}"
)
install(TARGETS _decorations LIBRARY DESTINATION ${PY_ROOT_DIR}/decorations)
3 changes: 2 additions & 1 deletion src/pylada/ewald/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
# <http://www.gnu.org/licenses/>.
###############################
add_cython_target(ewald_cython ewald.pyx CXX ${PYVER})
Python_add_library(ewald MODULE
add_library(ewald MODULE
${ewald_cython} ep_com.f90 erfc.cc ewaldf.f90 ewald.cc)
python_extension_module(ewald)
target_include_directories(ewald PRIVATE "${PY_HEADER_DIR}")
install(TARGETS ewald LIBRARY DESTINATION ${PY_ROOT_DIR}/ewald)

0 comments on commit 1b01524

Please sign in to comment.