Skip to content

Commit 4f08320

Browse files
authored
Merge pull request #1 from DiamondLightSource/docs
Adding documentation
2 parents 79812d7 + 451a5ad commit 4f08320

File tree

12 files changed

+514
-6
lines changed

12 files changed

+514
-6
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: HTTomo-backends docs
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- main
8+
push:
9+
branches:
10+
- main
11+
12+
jobs:
13+
build-docs-publish:
14+
runs-on: ubuntu-latest
15+
defaults:
16+
run:
17+
shell: bash -el {0}
18+
steps:
19+
- name: Checkout repository code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Python 3.10
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: '3.10'
26+
27+
- name: httomo-backends-docs
28+
uses: conda-incubator/setup-miniconda@v2
29+
with:
30+
auto-update-conda: false
31+
activate-environment: httomo-backends-docs
32+
environment-file: ./docs/source/doc-conda-requirements.yml
33+
34+
- name: Build api docs
35+
run: sphinx-apidoc -feT -t=./docs/source/_templates -o ./docs/source/api ./httomo_backends
36+
37+
- name: Generate yaml templates
38+
run: |
39+
pip install httomolib
40+
pip install httomolibgpu --no-deps
41+
42+
- name: Generate yaml templates
43+
run: |
44+
python ./httomo_backends/scripts/yaml_templates_generator.py -i ./httomo_backends/methods_database/backends/tomopy/tomopy_modules.yaml -o ./docs/build/yaml_templates/tomopy
45+
python ./httomo_backends/scripts/yaml_unsupported_tomopy_remove.py -t ./docs/build/yaml_templates/tomopy -l ./httomo_backends/methods_database/backends/tomopy/tomopy.yaml
46+
python ./httomo_backends/scripts/yaml_templates_generator.py -i ./httomo_backends/methods_database/backends/httomolib/httomolib_modules.yaml -o ./docs/build/yaml_templates/httomolib
47+
python ./httomo_backends/scripts/yaml_templates_generator.py -i ./httomo_backends/methods_database/backends/httomolibgpu/httomolibgpu_modules.yaml -o ./docs/build/yaml_templates/httomolibgpu
48+
49+
- name: Generate yml docs
50+
run: python ./docs/source/yaml_doc_generator.py
51+
52+
- name: Build html
53+
run: sphinx-build -a -E -b html ./docs/source/ ./docs/build/
54+
55+
- name: Publish docs
56+
if: github.ref_type == 'tag' || github.ref_name == 'main'
57+
run: ghp-import -n -p -f ./docs/build
58+
env:
59+
GITHUB_TOKEN: ${{ github.token }}

.github/workflows/httomo_backends_pypi_publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ jobs:
2525
$CONDA/bin/conda install conda-forge::pyyaml
2626
$CONDA/bin/pip install setuptools wheel
2727
$CONDA/bin/pip install build
28-
$CONDA/bin/pip install httomolib==2.1
29-
$CONDA/bin/pip install --no-deps httomolibgpu==2.1.1
28+
$CONDA/bin/pip install httomolib
29+
$CONDA/bin/pip install --no-deps httomolibgpu
3030
$CONDA/bin/conda list
3131
- name: Generate yaml templates
3232
run: |

README.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ Purpose of HTTomo-backends
66

77
**HTTomo-backends** is a package to support `HTTomo <https://diamondlightsource.github.io/httomo/>`_ software and it contains the following elements:
88

9-
* YAML templates for backends methods
10-
* Scripts that automatically generate YAML templates
9+
* YAML templates for `backends <https://diamondlightsource.github.io/httomo/backends/list.html/>`_ methods.
10+
* Scripts that automatically generate YAML templates during documentation build
1111
* Supporting scripts to calculate memory, size and padding estimators of the methods
1212

1313

1414
Install HTTomo-backends
1515
=======================
16-
HTTomo backends is released to support a specific version of `HTTomo <https://diamondlightsource.github.io/httomo/>`_. Install it to provide the same version of HTTomo that is currently installed.
1716

1817
.. code-block:: console
1918
20-
$ pip install httomo-backends==*version_number*
19+
$ pip install httomo-backends
2120

docs/source/__init__.py

Whitespace-only changes.

docs/source/_templates/module.rst_t

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{%- if show_headings %}:mod:`{{ basename }}`
2+
============================================
3+
{%- endif %}
4+
.. automodule:: {{ qualname }}
5+
{%- for option in automodule_options %}
6+
:{{ option }}:
7+
{%- endfor %}

docs/source/backends/templates.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. _reference_templates:
2+
3+
======================
4+
Methods YAML Templates
5+
======================
6+
7+
This section contains YAML templates for `backends <https://diamondlightsource.github.io/httomo/backends/list.html/>`_. These are ready-to-use templates can be either copy-pasted or
8+
directy accessed by installing `httomo-backends` package.
9+
10+
.. note:: When you click on a module you can find a link to the API of that module. This is where the description of the method and its arguments can be found.
11+
12+
13+
.. _reference_templates_tomopy:
14+
15+
TomoPy Modules
16+
---------------
17+
18+
.. toctree::
19+
:glob:
20+
21+
../api/tomopy*
22+
23+
.. _reference_templates_httomolibgpu:
24+
25+
HTTomolibgpu Modules
26+
--------------------
27+
28+
.. toctree::
29+
:glob:
30+
31+
../api/httomolibgpu*
32+
33+
.. _reference_templates_httomolib:
34+
35+
HTTomolib Modules
36+
------------------
37+
38+
.. toctree::
39+
:glob:
40+
41+
../api/httomolib.*

docs/source/conf.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
# ---------------------------------------------------------------------------
4+
# Copyright 2024 Diamond Light Source Ltd.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either ecpress or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
# ---------------------------------------------------------------------------
18+
# Created By : Tomography Team at DLS <[email protected]>
19+
20+
# -- General configuration ------------------------------------------------
21+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
22+
23+
import os
24+
import sys
25+
from datetime import date
26+
from unittest import mock
27+
28+
# If extensions (or modules to document with autodoc) are in another directory,
29+
# add these directories to sys.path here. If the directory is relative to the
30+
# documentation root, use os.path.abspath to make it absolute, like shown here.
31+
32+
sys.path.insert(0, os.path.abspath("../.."))
33+
34+
# -- Mock imports -------------------------------------------------------------
35+
36+
37+
# Mock imports instead of full environment in readthedocs
38+
MOCK_MODULES = [
39+
"click",
40+
"yaml",
41+
]
42+
43+
for mod_name in MOCK_MODULES:
44+
sys.modules[mod_name] = mock.Mock()
45+
46+
# ------------------------------------------------------------------------------
47+
48+
project = "httomo-backends"
49+
copyright = f"{date.today().year}, Diamond Light Source"
50+
51+
# Specify a base language to help assistive technology
52+
language = "en"
53+
54+
# Save the commit hash, this is displayed in the page title
55+
release = os.popen('git log -1 --format="%H"').read().strip()
56+
57+
# Set version as the latest tag in the current branch
58+
version = os.popen("git describe --tags --abbrev=0").read().strip()
59+
60+
# Add any Sphinx extension module names here, as strings. They can be extensions
61+
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
62+
extensions = [
63+
# Generates api files
64+
"sphinx.ext.autodoc",
65+
# Generates a short summary from docstring
66+
"sphinx.ext.autosummary",
67+
# Allows parsing of google style docstrings
68+
"sphinx.ext.napoleon",
69+
# Add links to highlighted source code
70+
"sphinx.ext.viewcode",
71+
# Allows a grid layout and dropdown boxes
72+
"sphinx_panels",
73+
# copy to clipboard button
74+
"sphinx_copybutton",
75+
# use jupyter notebooks
76+
"nbsphinx",
77+
#'IPython.sphinxext.ipython_console_highlighting',
78+
"sphinx.ext.githubpages",
79+
# Generate .nojekyll file for git pages build
80+
]
81+
82+
autosummary_generate = True
83+
numfig = True
84+
template_patterns = ["_templates"]
85+
86+
# The name of the Pygments (syntax highlighting) style to use.
87+
pygments_style = "sphinx"
88+
89+
# -- Options for HTML output --------------------------------------------------
90+
91+
html_theme = "sphinx_book_theme"
92+
html_title = "httomo-backends documentation page"
93+
html_copy_source = True
94+
html_last_updated_fmt = ""
95+
html_use_smartypants = True
96+
97+
html_theme_options = {
98+
"show_toc_level": 1,
99+
"navbar_align": "left", # [left, content, right] For testing that the navbar items align properly
100+
}
101+
102+
103+
html_context = {
104+
"github_user": "HTTomo",
105+
"github_repo": "https://github.com/DiamondLightSource/httomo-backends",
106+
"github_version": "main",
107+
"doc_path": "docs",
108+
}
109+
110+
111+
def setup(app):
112+
app.add_css_file("css/general.css")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: httomo-backends-docs
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- python>=3.10
6+
- numpy
7+
- tomopy==1.15
8+
- sphinx
9+
- sphinx-book-theme
10+
- nbsphinx
11+
- pandoc
12+
- jinja2
13+
- sphinx-panels
14+
- sphinx-copybutton
15+
- pyyaml
16+
- ipython
17+
- ghp-import
18+
- loguru
19+
- graypy
20+
- tqdm

docs/source/index.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. include:: ../../README.rst
2+
3+
.. _backends_content:
4+
5+
.. toctree::
6+
:caption: YAML Templates
7+
:maxdepth: 2
8+
9+
backends/templates
10+
11+
.. _utilities_content:
12+
13+
.. toctree::
14+
:caption: Utilities
15+
:maxdepth: 2
16+
17+
utilities/yaml_generator
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.. _utilities_yamlgenerator:
2+
3+
Templates generator
4+
*******************
5+
:ref:`backends_content` can be generated automatically using the YAML generator tool `provided <https://github.com/DiamondLightSource/httomo/tree/main/scripts/yaml_templates_generator.py>`_ in the Github repo.
6+
7+
The script does the following:
8+
9+
* Generates a list of YAML files for all accessible on import methods in a chosen software package, e.g., TomoPy.
10+
* Modifies and/or removes some extracted parameters in YAML templates to make the templates compatible with HTTomo.
11+
12+
How does it work:
13+
14+
* The user would need to provide a YAML file with the listed *modules* you would like to inspect and extract the methods from. For instance, for the TomoPy package this would be:
15+
16+
.. code-block:: yaml
17+
18+
- tomopy.misc.corr
19+
- tomopy.misc.morph
20+
21+
* The generator can be applied using the following command:
22+
23+
.. code-block:: console
24+
25+
$ python -m yaml_templates_generator -i /path/to/modules.yaml -o /path/to/outputfolder/
26+
27+
Please note that the package from which the modules are extracted, must be installed into your conda environment.
28+
29+
**For TomoPy templates only.** After templates have been generated for TomoPy, we need to remove the ones that are not currently supported by HTTomo. We do that by looking into the library file that exists in HTTomo for TomoPy.
30+
31+
.. code-block:: console
32+
33+
$ python -m remove_unsupported_templates -t /path/to/templates/ -l /path/to/library/file

0 commit comments

Comments
 (0)