customising pdoc automatically generated documentation for python - python

I used pdoc3 to automatically generate documentation from the docstrings at the beginning of each python class/function by executing the following
pdoc3 --html ambit_stochastics
The resulting documentation can be found at https://danleonte.github.io/Ambit_Stochastics/index.html
Can I remove the ambit_stochastics from ambit_stochastics.helpers on the index page and, subsequently, on all of the subpages? It seems unnecessary and wordy.
Can I edit the index page ( the one that pops up when accessing the link) to add some introductory text? how about other templates?

Not sure about your #1 point without editing the template, but you can tackle #2 by including a module docstring in your ambit_stochastics/__init__.py like pdoc does. This ten renders on the main module page, along with its TOC for titles:
https://pdoc3.github.io/pdoc/doc/pdoc/

Related

using :ref: in Python docstrings using Sphinx

I'm using Sphinx to document a python project, and I'm trying to create a reusable tip to be used in several locations.
Typically, I'll use the following syntax in a python file:
"""
.. tip::
I want this tip to be used in several locations. Why?
- Save time
- Work less
"""
Now this works whether I put it at the beginning of the file, right under class definition or right under function definition.
I found Sphinx's manual for :ref:, which suggests to use a label:
.. _my_reusable_tip:
.. tip::
...
And then call this tip with :ref:`my_reusable_tip` anywhere I want.
The manual states that 'it works across files, when section headings are changed, and for all builders that support cross-references'
The thing is, it doesn't matter in which .py file in the project I write the label and tip definition, the :ref:`my_reusable_tip` just displays 'my_reusable_tip', and not the tip itself.
What I'm using to build the documentation is
sphinx-apidoc -f -F -o
make html
I'm pretty sure my logic is flawed in some way, but I can't figure out why.
I know that Sphinx searches the project for reStructuredText and renders it if it can, but I think I'm missing something here.
I tried to add this label in a seperate .py file enclosed in """, and in a separate .txt file without enclosed """.
I tried creating an .rst file with the label definition and rebuild the html documentation.
What am I missing here?
Python 3.4.3 BTW.
In sphinx, a :ref: is simply a more robust way of linking (or referencing) another part of the document. Thus, your use of :ref: will simply provide a hyperlink to the label.
It is not a way of substituting or expanding a block.
Inline substitutions are available using using |...|, however an inline substitution cannot be used to substitute a block as you seem to require.
RestructuredText is not a template language, and thus doesn't provide macro like facilities. In the event you need it, an alternative solution is to use a template library such as mako or jinja to deal with this kind of issue.
Just using reStructuredText directive
.. include:: ./my_reusable_tip.txt
in your rst files?

Documenting parameters with long descriptions in Sphinx

I'm documenting my Python classes using Sphinx, and sometimes I want to give my parameters quite long descriptions to explain something in details. Unfortunately, Sphinx generates ugly output for me which wastes a lot of space and breaks the whole page appearance:
It can be seen that Sphinx creates a table, then puts "Parameters" header to the left cell, and the actual list of parameters to the right cell. But there should be way to avoid creating this table completely. After playing with the page DOM tree I finally can show that I want to achieve:
Is there a built-in way to do this or I'd have to create a PR to Sphinx theme or Sphinx itself?
After posting an issue to Sphinx bug-tracker and having no response, I've decided to roll-out my own solution (better say, hack). To achieve the look I want, I have written a simple Sphinx extension which post-processes generated HTML code. It can be found on PyPI:
https://pypi.python.org/pypi/sphinxcontrib.divparams
https://pythonhosted.org/sphinxcontrib.divparams/
This doesn't seem to be the best way to solve the issue, but the behaviour I wanted to change is deeply hard-coded in docutils, not Sphinx.

Make viewcode show module sources

I am trying to make a cookbook out of some Python snippets using Sphinx. Each snippet is a self-contained Python script and has a tutorial-type doctsring.
I want to have a source link in the generated documentation to display the script contents. But viewcode does not seem to create this link for the module, but only for a function or a class with a docstring. Is there a way to coax sphinx.ext.viewcode to display the script code without having any class/function in it?
I hope you haven't sat for two years waiting for an answer, but try using the literal include tag. You can play around with what gets displayed.
See the sphinx docs for more details.

PyCharm3 Live template not working at all

I just switched from Eclipse/PyDev to PyCharm 3 CE. I can't get the live templates working any ways. Followed every documentation I can find online like this:
http://www.jetbrains.com/pycharm/webhelp/live-templates.html
And the builtin python template super(Generates a 'super' call) does not work either.
By "not working", I meant that when editing a python file in PyCharm and typing the abbreviation, the popup snippets list does not include the live templates, even though they are under the Python template group.
Am I missing something?
I am using PyCharm 3.1 Professional (evaluation version) and am having the same issue.
However, using Ctrl+J will bring up templates as will Code -> Insert Live Template. It is also possible to start typing a code snippet and then press Ctrl+J to see a filtered list of templates.
Don't forget to also select the "context"...

have sphinx report broken links

When building html documentation, how do you force sphinx to report, or create an error, on links that don't exist?
Specifically, I have properties and methods within my Python project that have been removed or renamed, and it is hard to find all the dead links with the sphinx generated html output.
I feel like I'm staring at the answer here:
http://sphinx-doc.org/glossary.html, as descriped in the opening paragraph.
I'm obviously not understanding something.
Set the nitpicky configuration variable to True (you can also use the -n option when running sphinx-build).
In nitpicky mode, a cross-reference to a function (such as :func:`myfunc`), class, or other object that cannot be found will generate a warning message.
I think CheckExternalLinksBuilder is what you're looking for.
It's basically used by calling 'sphinx-build' with -b linkcheck option. Please see sphinx-build for more info. Also, take a look at the list of sphinx-extensions here and here.

Categories

Resources