2

All I want is to generate API docs from function docstrings in my source code, presumably through sphinx's autodoc extension, to comprise my lean API documentation. My code follows the functional programming paradigm, not OOP, as demonstrated below.

I'd probably, as a second step, add one or more documentation pages for the project, hosting things like introductory comments, code examples (leveraging doctest I guess) and of course linking to the API documentation itself.

What might be a straightforward flow to accomplish documentation from docstrings here? Sphinx is a great popular tool, yet I find its getting started pages a bit dense.

What I've tried, from within my source directory:

$ mkdir documentation
$ sphinx-apidoc -f --ext-autodoc -o documentation .

No error messages, yet this doesn't find (or handle) the docstrings in my source files; it just creates an rst file per source, with contents like follows:

tokenizer module
================

.. automodule:: tokenizer
    :members:
    :undoc-members:
    :show-inheritance:

Basically, my source files look like follows, without much module ceremony or object oriented contents in them (I like functional programming, even though it's python this time around). I've truncated the sample source file below of course, it contains more functions not shown below.

tokenizer.py

from hltk.util import clean, safe_get, safe_same_char

"""
    Basic tokenization for text

    not supported:

    + forms of pseuod elipsis (...)
   
    support for the above should be added only as part of an automata rewrite
"""

always_swallow_separators = u" \t\n\v\f\r\u200e"
always_separators = ",!?()[]{}:;"

def is_one_of(char, chars):
    '''
    Returns whether the input `char` is any of the characters of the string `chars`
    '''
    return chars.count(char)

Or would you recommend a different tool and flow for this use case?

Many thanks!

Community
  • 1
  • 1
matanster
  • 15,072
  • 19
  • 88
  • 167
  • Possible duplicate of https://stackoverflow.com/q/25549321/407651 – mzjn Jun 28 '18 at 13:41
  • I believe they are related, but not duplicate – matanster Jun 28 '18 at 14:38
  • Please ask a practical, answerable question based on an actual problem that you face (see https://stackoverflow.com/help/dont-ask). So far you have basically just said that the Sphinx documentation is "a bit dense". That is not a problem statement. – mzjn Jun 28 '18 at 16:15
  • Okay I added more to the question, and went down to the bottom of the ocean in the chat section of the linked answer adding `-F` to my command, but the results are still the same: not getting the docstrings included in the `rst` files. I hope the overall flow isn't _as cumbersome_ as @Dror suspected there. – matanster Jun 30 '18 at 08:24
  • 1
    Yes, **sphinx-apidoc** generates RST source files containing `automodule` directives. After you have run that tool, you need to run **sphinx-build** in order to generate HTML output. – mzjn Jun 30 '18 at 10:02
  • Can I alternatively generate output that is viewable within a python notebook environment, rather than from a public or dedicated web server? Thanks a lot for your prior patience. – matanster Jun 30 '18 at 11:37
  • I'm not sure what you mean by "viewable within a python notebook environment". I haven't really used (Jupyter) notebooks. – mzjn Jul 01 '18 at 05:29

1 Answers1

0

If you find Sphinx too cumbersome and particular to use for simple projects, try pdoc:

$ pdoc --html tokenizer.py
K3---rnc
  • 6,717
  • 3
  • 31
  • 46