Skip to content

Commit 5fe5728

Browse files
authored
Merge pull request #59 from AhmedBasem20/api-docs
Generate API documentation using Sphinx.
2 parents f72525e + ab9354b commit 5fe5728

File tree

6 files changed

+203
-1
lines changed

6 files changed

+203
-1
lines changed

.github/workflows/documentation.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build & Deploy Documentation
2+
3+
on:
4+
workflow_run:
5+
workflows: [Algorithm Analysis]
6+
types:
7+
- completed
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
jobs:
13+
build:
14+
environment:
15+
name: github-pages
16+
url: ${{ steps.deployment.outputs.page_url }}
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Setup Pages
21+
uses: actions/configure-pages@v4
22+
- name: Set up Python
23+
id: setup_python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: "3.11"
27+
- name: Cache pip
28+
uses: actions/cache@v3
29+
id: pip-cache
30+
with:
31+
key: ${{ runner.os }}-${{ env.pythonLocation }}-pip-${{ hashFiles('**/requirements.txt') }}
32+
path: ${{ env.pythonLocation }}
33+
if: steps.pip-cache.outputs.cache-hit != 'true'
34+
35+
- name: Install dependencies
36+
run: |
37+
pip install -r requirements.txt
38+
39+
# Action to download artifacts from a different workflow (analysis.yml)
40+
- name: 'Download artifact'
41+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
42+
uses: actions/github-script@v6
43+
with:
44+
script: |
45+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
run_id: context.payload.workflow_run.id,
49+
});
50+
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
51+
return artifact.name == "Figures"
52+
})[0];
53+
let download = await github.rest.actions.downloadArtifact({
54+
owner: context.repo.owner,
55+
repo: context.repo.repo,
56+
artifact_id: matchArtifact.id,
57+
archive_format: 'zip',
58+
});
59+
let fs = require('fs');
60+
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/Figures.zip`, Buffer.from(download.data));
61+
62+
- name: 'Unzip artifact'
63+
run: unzip Figures.zip
64+
65+
- name: Build html
66+
run: |
67+
mkdir docs/_static
68+
mv *.pdf docs/_static/
69+
sphinx-apidoc -o docs src
70+
cd docs/
71+
make html
72+
73+
- name: Upload docs artifact
74+
uses: actions/upload-pages-artifact@v3
75+
with:
76+
path: 'docs/_build/html'
77+
78+
- name: Deploy to GitHub Pages
79+
id: deployment
80+
uses: actions/deploy-pages@v4

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/conf.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# For the full list of built-in configuration values, see the documentation:
4+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
5+
6+
# -- Project information -----------------------------------------------------
7+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8+
9+
import os
10+
import sys
11+
12+
sys.path.insert(0, os.path.abspath(".."))
13+
14+
project = 'TF2.4 IVIM MRI Code Collection'
15+
copyright = '2024, OSIPI'
16+
author = 'OSIPI team'
17+
18+
# -- General configuration ---------------------------------------------------
19+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
20+
21+
extensions = ["sphinx.ext.todo", "sphinx.ext.viewcode", "sphinx.ext.autodoc"]
22+
23+
templates_path = ['_templates']
24+
exclude_patterns = ['Thumbs.db', '.DS_Store']
25+
26+
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
27+
html_show_sphinx = False
28+
29+
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
30+
html_show_copyright = False
31+
32+
# -- Options for HTML output -------------------------------------------------
33+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
34+
35+
html_theme = 'sphinx_rtd_theme'
36+
html_static_path = ['_static']

docs/figures.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Algorithm Analysis Figures
2+
===========
3+
4+
.. raw:: html
5+
6+
<!DOCTYPE html>
7+
<html lang="en">
8+
<head>
9+
<meta charset="UTF-8">
10+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
11+
<title>Algorithm Analysis Figures</title>
12+
<style>
13+
14+
embed {
15+
width: 90%;
16+
margin-bottom: 4rem;
17+
height: 100vh;
18+
}
19+
</style>
20+
</head>
21+
<body>
22+
<h4>Diffusion grid for limited algorithms:</h4>
23+
<embed src="_static/D_limited.pdf" type="application/pdf" frameborder="0" scrolling="auto">
24+
<h4>Diffusion grid for all algorithms:</h4>
25+
<embed src="_static/D.pdf" type="application/pdf" frameborder="0" scrolling="auto">
26+
27+
<h4>Perfusion grid for limited algorithms:</h4>
28+
<embed src="_static/Dp_limited.pdf" type="application/pdf" frameborder="0" scrolling="auto">
29+
<h4>Perfusion grid for all algorithms:</h4>
30+
<embed src="_static/Dp.pdf" type="application/pdf" frameborder="0" scrolling="auto">
31+
32+
<h4>Perfusion fraction grid for limited algorithms:</h4>
33+
<embed src="_static/f_limited.pdf" type="application/pdf" frameborder="0" scrolling="auto">
34+
<h4>Perfusion fraction grid for all algorithms:</h4>
35+
<embed src="_static/f.pdf" type="application/pdf" frameborder="0" scrolling="auto">
36+
37+
<h4>Fitted curves:</h4>
38+
<embed src="_static/fitted_curves.pdf" type="application/pdf" frameborder="0" scrolling="auto">
39+
<h4>Curve plot:</h4>
40+
<embed src="_static/curve_plot.pdf" type="application/pdf" frameborder="0" scrolling="auto">
41+
<h4>Algorithm Fitting duration:</h4>
42+
<embed src="_static/durations.pdf" type="application/pdf" frameborder="0" scrolling="auto">
43+
44+
</body>
45+
</html>

docs/index.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.. TF2.4 IVIM MRI Code Collection documentation master file, created by
2+
sphinx-quickstart on Wed Mar 6 00:06:13 2024.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Welcome to TF2.4 IVIM MRI Code Collection's documentation!
7+
==========================================================
8+
9+
.. toctree::
10+
:maxdepth: 4
11+
:caption: Contents:
12+
13+
figures
14+
modules
15+
16+
Indices and tables
17+
==================
18+
19+
* :ref:`modindex`

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ scienceplots
1010
cvxpy
1111
zenodo-get
1212
pytest
13-
tqdm
13+
tqdm
14+
sphinx
15+
sphinx_rtd_theme

0 commit comments

Comments
 (0)