Skip to content

Commit

Permalink
Introduce the infrastructure for auto-generating API documentation vi…
Browse files Browse the repository at this point in the history
…a sphinx and doxygen (#383)

* [doxygen] Update doxygen config file

* [doxygen] Make generated pages readable again

* [sphinx] Add baic sphinx setup and make it pick up doxygen output for c++ API

* [sphinx] Make sphinx generate API docs for python bindings

* [doc] Remove no longer necessary html and style files

* Integrate generation back into cmake

* Add a workflow for building the docs

* Make the documentation target depend on the necessary libs
  • Loading branch information
tmadlener authored Jan 19, 2024
1 parent ec6c092 commit a1e14d5
Show file tree
Hide file tree
Showing 18 changed files with 881 additions and 648 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: publish-doc

on:
push:
branches:
- 'master'
tags:
- v*-*
workflow_dispatch:

concurrency:
group: pages
cancel-in-progress: true

jobs:
build-doc:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: cvmfs-contrib/github-action-cvmfs@v3
- uses: aidasoft/run-lcg-view@v4
with:
container: el9
view-path: /cvmfs/sw-nightlies.hsf.org/key4hep
run: |
echo "::group::Install dependencies"
python3 -m pip install -r doc/requirements.txt
export PATH=/root/.local/bin:$PATH
export PYTHONPATH=/root/.local/lib/python3.10/site-packages:$PYTHONPATH
echo -e "::endgroup::\n::group::Build podio"
cmake -B build . --install-prefix=$(pwd)/install \
-GNinja -DENABLE_SIO=ON -DENABLE_RNTUPLE=ON \
-DBUILD_TESTING=OFF \
-DCMAKE_CXX_STANDARD=17
cmake --build build --target install
export PYTHONPATH=$(pwd)/install/python:$PYTHONPATH
export LD_LIBRARY_PATH=$(pwd)/install/lib*/:$LD_LIBRARY_PATH
export ROOT_INCLUDE_PATH=$(pwd)/install/include
echo -e "::endgroup::\n::group::build doc"
sphinx-build -M html doc doc_output
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: doc_output/html

publish-doc:
needs: build-doc
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
ref: gh-pages
- uses: actions/download-artifact@v4
with:
name: github-pages
path: doc_artifact

- name: Update documentation
env:
TARGET_DIR: ${{ github.ref_name }}
run: |
mkdir -p ${TARGET_DIR}
rm -rf ${TARGET_DIR}/*
tar -xvf doc_artifact/artifact.tar --directory ${TARGET_DIR}
rm -r doc_artifact
- name: Commit and push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET_DIR: ${{ github.ref_name }}
run: |
git config --global user.email ${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com
git config --global user.name ${GITHUB_ACTOR}
git add ${TARGET_DIR}
git diff-index --quiet HEAD 2>&1 > /dev/null || git commit -m "Update documentation for ${TARGET_DIR}" && git push
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ spack*
/python/podio/__version__.py
/python/podio_version.py

# Populated by doc generation
/doc/py_api
/doc/_build
/doc/cpp_api/

# CLion artifacts
.idea/
cmake-build*/
8 changes: 8 additions & 0 deletions cmake/FindSphinx.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
find_program(SPHINX_BUILD_EXECUTABLE
NAMES sphinx-build
DOC "Path to sphinx-build executable")

include(FindPackageHandleStandardArgs)

# Handle standard arguments to find_package
find_package_handle_standard_args(Sphinx "Failed to find sphinx executable" SPHINX_BUILD_EXECUTABLE)
38 changes: 19 additions & 19 deletions cmake/podioDoxygen.cmake
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
find_package(Doxygen)
if(DOXYGEN_FOUND)
# temporarily override the version for doxy generation (for nightly snapshots)
set(tmp ${podio_VERSION})
if(DOXYVERSION)
set(podio_VERSION ${DOXYVERSION})
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/doxy-boot.js.in
${PROJECT_BINARY_DIR}/doxygen/html/doxy-boot.js)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM)
find_package(Sphinx)

install( DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doxygen DESTINATION doxygen OPTIONAL)
# revert version to old value
set(podio_VERSION ${tmp})
unset(tmp)
endif(DOXYGEN_FOUND)
if(DOXYGEN_FOUND AND SPHINX_FOUND)
set(SPHINX_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/doc/_build)

add_custom_target(documentation
COMMAND
${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src/:$ENV{LD_LIBRARY_PATH};ROOT_INCLUDE_PATH=${CMAKE_SOURCE_DIR}/include;"
${SPHINX_BUILD_EXECUTABLE} -M html
${CMAKE_SOURCE_DIR}/doc ${SPHINX_OUTPUT_DIRECTORY}
COMMENT "Building documentation" VERBATIM
DEPENDS podio::podio podio::podioRootIO
)

install(DIRECTORY ${SPHINX_OUTPUT_DIRECTORY}/
DESTINATION ${CMAKE_INSTALL_DOCDIR}
OPTIONAL)
else()
message(WARNING "Could not generate documentation because either Doxygen or Sphinx could not be found")
endif()
Loading

0 comments on commit a1e14d5

Please sign in to comment.