From de466dcc4a6bd7b7cb758da207ef451e315c9f10 Mon Sep 17 00:00:00 2001
From: Alexis Durgnat <alexis.durgnat@hesge.ch>
Date: Mon, 1 Nov 2021 16:06:31 +0100
Subject: [PATCH] Add doc generation support

---
 Dockerfile            |  7 ++++++-
 Makefile              |  3 +++
 README.md             |  2 ++
 Scripts/entrypoint.sh | 29 +++++++++++++++++++++++++++++
 4 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/Dockerfile b/Dockerfile
index c2b9c09..61242db 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -30,12 +30,17 @@ RUN python3 -m pip install --upgrade pip
 RUN python3 -m pip install cython numpy opencv-python pybind11 build
 # Venv for python-build
 RUN apt-get install -y python3-venv
+
+# Sphinx for documentation
+RUN python3 -m pip install sphinx sphinx_rtd_theme
+
 # Create paths
 RUN mkdir -p /build && mkdir -p /opt/scripts/
 RUN mkdir -p $src_path
+
 WORKDIR $src_path
 # Copy the necessary scripts in
 COPY ./Scripts/* /opt/scripts/
-
+RUN chmod +x /opt/scripts/*
 ENTRYPOINT [ "/opt/scripts/entrypoint.sh" ]
 # ENTRYPOINT [ "./sandbox_docker-builder/entrypoint.sh" ]
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 8702435..b6938f4 100644
--- a/Makefile
+++ b/Makefile
@@ -11,5 +11,8 @@ create: docker-compose.yml Dockerfile
 build: docker-compose.yml
     $(DCR) $(CONTAINER_NAME) build
 
+docs: docker-compose.yml
+    $(DCR) $(CONTAINER_NAME) docs html
+
 clean: docker-compose.yml
     $(DCR) $(CONTAINER_NAME) clean
\ No newline at end of file
diff --git a/README.md b/README.md
index 53eaf04..df304d0 100644
--- a/README.md
+++ b/README.md
@@ -56,6 +56,7 @@ The provided makefile allow simple manipulation of the docker to build, clean an
 | create | `make create` | Build the docker container |
 | build (default) | `make` or `make build` | Build everything |
 | clean | `make clean` | Cleanup |
+| docs | `make docs` | Build the documentation for the python wrapper (Lib and wrapper must be built beforehand) |
 
 
 ## Docker container
@@ -72,6 +73,7 @@ The following arguments are available :
 | Arg | Description |
 |-- |--|
 | `build [lib] [wrapper]` | Will build the indicated component. `wrapper` should be built after `lib`. If none provided, build everything. |
+| `docs [mode] [opts]`  | Build the wrapper documentation using sphinx-build. Everything must be already built. You may override `mode` (default to `html`.). You may override the sphinx-build options by passing `opts` which are relayed to the sphinx-build command. To provide `opts`, `mode` must be set. |
 | `clean [lib] [wrapper]` | Will cleanup the build directories. If no component provided, clean everything. |
 | `bash` or `s` | Execute a bash terminal inside the docker. May or may not be useful. |
 | `exec CMD [ARGS]` or `c [CMD] [ARGS]`  | Execute the command `CMD` with the arguments `ARGS` inside the docker. May or may not be useful. |
\ No newline at end of file
diff --git a/Scripts/entrypoint.sh b/Scripts/entrypoint.sh
index 27b25d7..007faa8 100644
--- a/Scripts/entrypoint.sh
+++ b/Scripts/entrypoint.sh
@@ -81,6 +81,29 @@ function build_all() {
     make_target $SBOX_PYWR
 }
 
+function make_python_docs() {
+    export LD_LIBRARY_PATH=$SBOX_LIB/build/
+    local MODE='html'
+    if [ ! -z $1 ]; then
+        MODE=$1
+        shift
+    fi
+    if [ ! -z $1 ]; then
+        SOPT="$@"
+        echo $SOPT
+    fi
+    echo -e "${GRN}Running sphinx-build in html mode.${NC}"
+    cd $SBOX_PYWR/docs/ && SPHINXOPTS=$SOPT make $MODE
+}
+
+function clean_python_doc() {
+    cd $SBOX_PYWR/docs/ && make clean && rm -rf ./_build
+}
+
+function build_doc() {
+    clean_python_doc
+    make_python_docs $@
+}
 
 ## Main entry of script. Check for arguments
 if [ $# -gt 0 ]; then
@@ -143,11 +166,17 @@ if [ $# -gt 0 ]; then
     elif [ $1 = "test" ]; then
         shift
         /opt/scripts/test-pypackage.sh
+        exit 0
+    elif [ $1 = "docs" ]; then
+        shift
+        build_doc $@
+        exit 0
     elif [ $1 = "bt" ]; then
         shift
         build_all
         copy_artifacts
         /opt/scripts/test-pypackage.sh
+        exit 0
     fi
     exit 1
 fi
-- 
GitLab