Skip to content

Commit 0c57612

Browse files
authored
Autodoc to use type hinting (#152)
1 parent ac98e3c commit 0c57612

File tree

9 files changed

+39
-16
lines changed

9 files changed

+39
-16
lines changed

.github/workflows/build_docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ jobs:
1919
- name: install sphinx
2020
run: pip install sphinx sphinx-rtd-theme
2121
- name: install fab
22-
run: pip install .
22+
run: pip install .[docs]
2323
- name: build docs
2424
run: |
2525
cd docs
2626
rm -rf build
27-
sphinx-apidoc -f -o source/apidoc ../source/fab
27+
sphinx-apidoc --separate --module-first -d 3 -f -o source/apidoc ../source/fab
2828
make html
2929
- name: move built docs to docs root
3030
run: |

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,6 @@ venv.bak/
105105

106106
# Profiler stats
107107
.pstats
108+
109+
# apidoc generated output
110+
docs/source/apidoc

docs/readme

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
3+
# these commands build the docs
4+
rm -rf build
5+
rm -rf source/apidoc
6+
sphinx-apidoc --separate --module-first -d 3 -f -o source/apidoc ../source/fab
7+
make html
8+
9+
10+
# all in one
11+
rm -rf build && rm -rf source/apidoc && sphinx-apidoc --separate --module-first -d 3 -f -o source/apidoc ../source/fab && make html
12+
firefox build/html/index.html

docs/source/conf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
'sphinx.ext.graphviz',
3737
'sphinx.ext.intersphinx',
3838
'sphinx.ext.autosectionlabel',
39+
'sphinx_autodoc_typehints',
3940
]
4041

4142
# Add any paths that contain templates here, relative to this directory.
@@ -75,3 +76,7 @@
7576

7677
# create linkable targets from section headings
7778
autosectionlabel_prefix_document = True
79+
80+
81+
# include default values in argument descriptions
82+
typehints_defaults = 'braces-after'

docs/source/glossary.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ Glossary
99

1010
Artefact Store
1111
At the start of a build run, Fab creates an empty ``artefact_store``.
12-
An entry in this store is called a :term:`Named Collection`, which is a mapping from a name string
12+
An entry in this store is called an :term:`Artefact Collection`, which is a mapping from a name string
1313
to, usually, a collection of :term:`Artefact` - but can be anything.
1414

1515
Fab passes the growing artefact store to each step in turn,
16-
where they typically read a :term:`Named Collection` and create a new one for subsequent steps to read.
16+
where they typically read an :term:`Artefact Collection` and create a new one for subsequent steps to read.
1717

1818
See also :ref:`Artefacts Overview <artefacts_overview>`
1919

@@ -43,7 +43,7 @@ Glossary
4343
Fab's built-in steps come with sensible defaults so the user doesn't have to write unnecessary config.
4444

4545
As an example, the Fortran preprocessor has a default artefact getter which reads *".F90"* files
46-
from the :term:`Named Collection` called _"all_source"_.
46+
from the :term:`Artefact Collection` called _"all_source"_.
4747

4848
Artefact getters are derived from :class:`~fab.artefacts.ArtefactsGetter`.
4949

docs/source/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ Indices and tables
2727
Api Reference <apidoc/modules>
2828
development
2929
glossary
30+
genindex
31+
modindex

docs/source/overview.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Example Config
4242
==============
4343

4444
Build configs are written in Python. Fab is designed to minimise user input by
45-
by providing sensible defaults::
45+
by providing sensible defaults.
4646

4747
.. code-block::
4848

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
python_requires='>=3.7, <4',
4848
install_requires=['fparser', 'svn'],
4949
extras_require={
50-
'dev': ['flake8', 'mypy'],
51-
'tests': ['pytest', 'pytest-cov', 'pytest-mock']
50+
'dev': ['flake8', 'mypy', 'sphinx-autodoc-typehints'],
51+
'tests': ['pytest', 'pytest-cov', 'pytest-mock'],
52+
'docs': ['sphinx-autodoc-typehints'],
5253
}
5354
)

source/fab/build_config.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ class BuildConfig(object):
3434
"""
3535

3636
def __init__(self, project_label: str, source_root: Optional[Path] = None, steps: Optional[List[Step]] = None,
37-
multiprocessing=True, n_procs: int = None, reuse_artefacts=False,
38-
fab_workspace: Optional[Path] = None, verbose=False, prebuild_folder: Optional[Path] = None):
37+
multiprocessing: bool = True, n_procs: int = None, reuse_artefacts: bool = False,
38+
fab_workspace: Optional[Path] = None, verbose: bool = False, prebuild_folder: Optional[Path] = None):
3939
"""
40-
:param str project_label:
40+
:param project_label:
4141
Name of the build project. The project workspace folder is created from this name, with spaces replaced
4242
by underscores.
43-
:param Path source_root:
43+
:param source_root:
4444
Optional argument to allow the config to find source code outside it's project workspace.
4545
This is useful, for example, when the :py:mod:`fab.steps.grab <grab>` is in a separate script to be run
4646
less frequently. In this scenario, the source code will be found in a different project workspace folder.
47-
:param List[Step] steps:
47+
:param steps:
4848
The list of build steps to run.
49-
:param bool multiprocessing:
49+
:param multiprocessing:
5050
An option to disable multiprocessing to aid debugging.
51-
:param int n_procs:
51+
:param n_procs:
5252
The number of cores to use for multiprocessing operations. Defaults to the number of available cores.
53-
:param bool reuse_artefacts:
53+
:param reuse_artefacts:
5454
A flag to avoid reprocessing certain files on subsequent runs.
5555
WARNING: Currently unsophisticated, this flag should only be used by Fab developers.
5656
The logic behind flag will soon be improved, in a work package called "incremental build".

0 commit comments

Comments
 (0)