Skip to content

Build API documentation with Sphinx via TravisCI/Tox [WIP] - #1388

Closed
peterjc wants to merge 27 commits into
biopython:masterfrom
peterjc:travis_sphinx
Closed

peterjc wants to merge 27 commits into
biopython:masterfrom
peterjc:travis_sphinx

Conversation

@peterjc

@peterjc peterjc commented Sep 12, 2017 •

Copy link
Copy Markdown
Member

This pull request would in part address issue #906, the goal of replacing epydoc for our API documentation.

Note in addition to Sphinx specific changes, there are some code changes in Bio.Restriction and Bio.Graphics.GenomeDiagram in order to avoid an exception and include the classes in the public documentation.

Still needs work, e.g. dealing with special methods like __init__ which we probably want to be included by default.

@codecov

codecov Bot commented Sep 12, 2017 •

Copy link
Copy Markdown

Codecov Report

❗ No coverage uploaded for pull request base (master@72b3a77). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1388   +/-   ##
=========================================
  Coverage          ?   85.11%           
=========================================
  Files             ?      327           
  Lines             ?    49531           
  Branches          ?        0           
=========================================
  Hits              ?    42156           
  Misses            ?     7375           
  Partials          ?        0

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 72b3a77...37f8931. Read the comment docs.

@peterjc

peterjc commented Sep 15, 2017 •

Copy link
Copy Markdown
Member Author

These options seem to improve the output, and in particular document __init__ explicitly:

.. automodule:: Bio.SeqRecord
    :members:
    :undoc-members:
    :show-inheritance:
    :special-members:
    :exclude-members: __dict__,__weakref__,__module__
    :member-order: bysource

Including :inherited-members: sadly appears to include everything from the base Python object class which introduces a lot of noise.

Update: https://stackoverflow.com/questions/3757500/connect-sphinx-autodoc-skip-member-to-my-function#3757526 suggests a way to do this via the conf.py file.

@peterjc

peterjc commented Oct 10, 2017

Copy link
Copy Markdown
Member Author

I hinted at this in a comment in the last commit referencing my Sphinx pull request sphinx-doc/sphinx#4076 which adds a new Sphinx conf.py setting autodoc_exclude_members which will hopefully be accepted.

Running this with my branch of Sphinx, we can manage the special settings for automodule without processing the RST files produced by sphinx-apidoc to include the special methods while excluding a few boring cases like __dict__, __weakref__ and __module__.

@peterjc

peterjc commented Oct 10, 2017

Copy link
Copy Markdown
Member Author

TODO: Resolve all the scary Sphinx warnings Unexpected section title.

@peterjc

peterjc commented Oct 20, 2017

Copy link
Copy Markdown
Member Author

Cross reference sphinx-doc/sphinx#4170 for the __all__ and __version__ bug.

@peterjc

peterjc commented Oct 26, 2017

Copy link
Copy Markdown
Member Author

Note to self: Sphinx, apidoc, and readthedocs

I think we need to run sphinx-apidoc as part of building our API documentation, regenerating the module-specific *.rst files fresh (i.e. not storing them in our source code repository).

However, out of the box, readthedocs seems to focus on the running sphinx with the conf.py file, and assumes all the *.rst files already exist. There is an open issue on this:

readthedocs/readthedocs.org#1139

That issue includes a workaround where they modify conf.py to invoke building the API *.rst files, also documented at http://ggeditor.readthedocs.io/en/latest/ApiDoc.html using:

import sys, os

# append the next line to conf.py, should change "backend" to your module name
sys.path.insert(0, os.path.join(os.path.dirname(__file__),'..','backend'))

# ensure the autodoc and napoleon are in the extensions
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.napoleon']

def run_apidoc(_):
    from sphinx.apidoc import main
    parentFolder = os.path.join(os.path.dirname(__file__), '..')
    cur_dir = os.path.abspath(os.path.dirname(__file__))
    sys.path.append(parentFolder)
    # change "backend" to your module name
    module = os.path.join(parentFolder,'backend')
    output_path = os.path.join(cur_dir, 'api')
    main(['-e','-f','-o', output_path, module])

def setup(app):
    # overrides for wide tables in RTD theme
    app.add_stylesheet('theme_overrides.css')
    # trigger the run_apidoc
    app.connect('builder-inited', run_apidoc)

@peterjc

peterjc commented Mar 12, 2018

Copy link
Copy Markdown
Member Author

I'm going to remove the Bio.Restriction changes (since something equivalent has been merged), and rebase this...

@peterjc

peterjc commented Apr 2, 2018

Copy link
Copy Markdown
Member Author

Running locally without -W now getting five TOC warnings:

/Users/xxx/repositories/biopython/Doc/api/Bio.Align.Applications.rst: WARNING: document isn't included in any toctree
/Users/xxx/repositories/biopython/Doc/api/Bio.Graphics.GenomeDiagram.rst: WARNING: document isn't included in any toctree
/Users/xx/repositories/biopython/Doc/api/Bio.Phylo.Applications.rst: WARNING: document isn't included in any toctree
/Users/xx/repositories/biopython/Doc/api/Bio.Sequencing.Applications.rst: WARNING: document isn't included in any toctree
/Users/xx/repositories/biopython/Doc/api/Bio.motifs.applications.rst: WARNING: document isn't included in any toctree

This makes sense for use in continuous integration.
Don't know or currently care how these would work for
Bio and BioSQL top level modules together.
In theory this would allow readthedocs to be
used and generate the API documentation *.rst
files on demand.

See readthedocs/readthedocs.org#1139
Calling sphinx-apidoc via conf.py broke on Sphinx 1.7.1,

$ make SPHINXBUILD=python -msphinx -W -C Doc/api/ html
make: Entering directory `/home/travis/build/biopython/biopython/Doc/api'
python -msphinx -W -b html -d _build/doctrees   . _build/html
Running Sphinx v1.7.1
loading translations [en]... done
making output directory...
loading pickled environment... not yet created
usage: usage: __main__.py [OPTIONS] -o <OUTPUT_PATH> <MODULE_PATH> [EXCLUDE_PATTERN, ...]
__main__.py: error: argument -d/--maxdepth: invalid int value: '_build/doctrees'
make: *** [html] Error 2
make: Leaving directory `/home/travis/build/biopython/biopython/Doc/api'
ERROR: InvocationError: '/usr/bin/make SPHINXBUILD=python -msphinx -W -C Doc/api/ html'
Under Sphinx 1.7 the Makefile calls sphinx-build with
the -M argument which must be the first argument.
This reverts commit 95bae71.

Currently strict mode fails due to TOC problems:

.../Doc/api/Bio.Align.Applications.rst: WARNING: document isn't included in any toctree
.../Doc/api/Bio.Graphics.GenomeDiagram.rst: WARNING: document isn't included in any toctree
.../Doc/api/Bio.Phylo.Applications.rst: WARNING: document isn't included in any toctree
.../Doc/api/Bio.Sequencing.Applications.rst: WARNING: document isn't included in any toctree
.../Doc/api/Bio.motifs.applications.rst: WARNING: document isn't included in any toctree
@peterjc

peterjc commented Sep 21, 2018

Copy link
Copy Markdown
Member Author

Given sphinx-doc/sphinx#5215 was merged and is part of Sphinx 1.8.0, updating the branch (and rebasing)...

@peterjc
peterjc force-pushed the travis_sphinx branch 2 times, most recently from 98569cb to 37f8931 Compare September 21, 2018 16:48
This replaced my proposed autodoc_exclude_members setting
which was put forward on another Sphinx pull request.
@peterjc
peterjc removed the request for review from JoaoRodrigues September 21, 2018 16:53
@peterjc

peterjc commented Sep 24, 2018

Copy link
Copy Markdown
Member Author

Closing in favour of #1803 (which clears up the history) now that this seems to be working.

@peterjc peterjc closed this Sep 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant