capsul.sphinxext module¶
Extension to sphinx to document Capsul processes
This module allows to make sphinx source to automatically document Capsul processes and pipelines. The module can be used as a commandline:
python -m capsul.sphinxext.capsul_pipeline_rst -i morphologist.capsul -o processes_docs --schema
It can be automatically run when building sphinx docs (inside the sphinx-build process) by adding at the end of the conf.py
file in sphinx sources:
# generate pipeline and processes docs
# we must actually write in sources for now.
import subprocess
module_to_document = 'morphologist.capsul' # replace with your modules set
sphinx_dir = os.path.dirname(__file__)
proc_rst_dir = os.path.join(sphinx_dir, 'process_docs')
if not os.path.exists(proc_rst_dir):
os.makedirs(proc_rst_dir)
cmd = [sys.executable, '-m', 'capsul.sphinxext.capsul_pipeline_rst',
'-i', module_to_document, '-o', proc_rst_dir, '--schema']
print('generating CAPSUL processes docs...')
print(cmd)
subprocess.check_output(cmd)
The documentation will include all pipelines and processes in the module to be documented (including Nipype interfaces), and will be built from the processes documentation: docstrings, and parameters descriptions (desc
property of processes traits), as in the processes get_help()
method. An index.rst
file will be created for each sub-module of the main one, and contain links to pipelines and processes docs there.
Then within the sphinx docs sources (index.rst
for instance, or any other sphinx source file), you can include them:
# interestingly, sphinx lexers do not support sphinx language ;)
.. toctree::
process_docs/morphologist/capsul/index.rst
- class capsul.sphinxext.layoutdocgen.LayoutHelperWriter(module_names, root_module_name, rst_extension='.rst')[source]¶
A basic class to create sphinx layout and associated index.
Initialize the LayoutHelperWriter class
- Parameters:
- generate_index_entry(module_name, indent=4)[source]¶
Make autodoc documentation of pilots
- Parameters:
module_name (string) – the name of the module we want to index
ident (int) – the number of blank prefix
- Returns:
ad – the reST formatted index description.
- Return type:
string
- write_index(outdir, froot='index', rst_extension='.rst')[source]¶
Make a reST API index file from python modules
- Parameters:
outdir (string (mandatory)) – Directory to which to write generated index file
froot (string (optional)) – root (filename without extension) of filename to write to Defaults to ‘index’. We add
rst_extension
.rst_extension (string (optional)) – Extension for reST files, default ‘.rst’
- capsul.sphinxext.load_pilots.load_pilots(root, path, root_module_name)[source]¶
Load all the pilot functions.
Path is recursively scanned for
__init__.py
files. Any function declared inside whose name start withpilot_
will be loaded.
- class capsul.sphinxext.usecasesdocgen.UseCasesHelperWriter(pilots, rst_extension='.rst')[source]¶
A basic class to convert the pilot codes to rst use cases
Initialize the UseCasesHelper class
- Parameters:
pilots (list of @function (mandatory)) – list of pilot functions.
rst_extension (string (optional)) – Extension for reST files, default ‘.rst’.
- generate_usecases_doc(src_code, module_name)[source]¶
Make autodoc documentation of pilots
- Parameters:
src_code (string) – pilot source code.
- Returns:
ad – the use case reST formatted documentation.
- Return type:
string
- getsource(function)[source]¶
Method that returns the source code of a function
- Parameters:
function (@function (mandatory)) – a python function.
- Returns:
srccode – the function source code.
- Return type:
- write_index(outdir, froot='index', relative_to=None, rst_extension='.rst')[source]¶
Make a reST API index file from written files
- Parameters:
outdir (string (mandatory)) – Directory to which to write generated index file
froot (string (optional)) – root (filename without extension) of filename to write to Defaults to ‘index’. We add
rst_extension
.relative_to (string) – path to which written filenames are relative. This component of the written file path will be removed from outdir, in the generated index. Default is None, meaning, leave path as it is.
rst_extension (string (optional)) – Extension for reST files, default ‘.rst’
- write_usecases_docs(outdir=None, returnrst=False)[source]¶
Generate Use Cases reST files.
- Parameters:
outdir (string) – Directory name in which to store files. We create automatic filenames for each Use case.
returnrst (bool (optional, default False)) – if True return the rst string documentation, otherwise write it to disk.
Commands¶
capsul_pipeline_rst.py
capsul_pipeline_view.py
capsul_sphinx_layout.py
capsul_usecases_rst.py