Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with private inheritance in generated rst #195

Closed
jsturdy opened this issue Apr 9, 2020 · 1 comment
Closed

Issue with private inheritance in generated rst #195

jsturdy opened this issue Apr 9, 2020 · 1 comment

Comments

@jsturdy
Copy link

jsturdy commented Apr 9, 2020

Hi, I've been trying out this tool on a couple of projects where I'm trying to simplify and consolidate the documentation procedure and it's been working quite well.

However, I've run into a small issue with a part of the code involving generation of inheritance diagrams where it appears that the jinja templating is expanding into invalid rst, resulting in the following warning:

WARNING: Explicit markup ends without a blank line; unexpected unindent.

Here is the configuration I'm using:

 autoapi_type = "python"
 autoapi_python_use_implicit_namespaces = True
 autoapi_dirs = [
     "{}".format(os.getenv("PYTHONSOURCE")),
 ]
 autoapi_add_toctree_entry = False
 autoapi_keep_files = True
 autoapi_options = [
     "members",
     "undoc-members",
     "private-members",
     "show-inheritance",
     "special-members",
     "show-inheritance-diagram",
     "show-module-summary",
 ]
 autoapi_ignore = ["*migrations*", "*conf.py", "*setup.py"]
 autoapi_template_dir = "_templates/autoapi"

And here is an example of the generated rst:

 .. py:class:: Prompt(completekey='tab', stdin=None, stdout=None)                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                                                                             
    Bases: :class:`cmd.Cmd`                                                                                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                                                                             
    .. autoapi-inheritance-diagram:: common.prompt.Prompt                                                                                                                                                                                                                                                                                         
       :parts: 1                                                                                                                                                                                                                                                                                                                                                             
 :private-bases:                                                                                                                                                                                                                                                                                                                                                             
    Class defining command line interface prompt.                                                                                                                                                                                                                                                                                                                            

    .. note ::                                                                                                                                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                                                                                                                             
       This is a base class and it can (should) be extended                                                                                                                                                                                                                                                                                                                  

which results in the following docs (using sphinx-rtd-theme)
autoapi-default

and here is what I would expect it to look like:

.. py:class:: Prompt(completekey='tab', stdin=None, stdout=None)                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                             
   Bases: :class:`cmd.Cmd`                                                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                                                                             
   .. autoapi-inheritance-diagram:: common.prompt.Prompt                                                                                                                                                                                                                                                                                          
      :parts: 1                                                                                                                                                                                                                                                                                                                                                              
      :private-bases:                                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                             
   Class defining command line interface prompt.                                                                                                                                                                                                                                                                                                                             

   .. note ::                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                                                                             
      This is a base class and it can (should) be extended                                                                                                                                                                                                                                                                                                                   

If I modify the autoapi/templates/python/classes.rst template I can get the expected behaviour (but I'm not an expert in jinja template syntax, so I don't know if it is the "correct" way to fix the root issue)

14c14,16
<       {% if "private-members" in autoapi_options %}:private-bases:{% endif %}
---
>       {% if "private-members" in autoapi_options %}
>       :private-bases:
>       {% endif %}

which results in:
autoapi-myfix

I am working with an older code base, so using python 2.7, but I did a minimal change to fix print statements and was able to obtain the same result with python 3.8 (both in a conda environment).

For the python 2.7 env, the package versions are (removed other matches, but can add them if you think it's relevant):

Jinja2==2.10.1
Sphinx==1.8.5
sphinx-autoapi==1.3.0
sphinx-rtd-theme==0.4.3

and for the python 3.8 env, the package versions are:

pip freeze|egrep -i (sphinx|autoapi|jinja)
Jinja2==2.10.3
Sphinx==2.4.3
sphinx-autoapi==1.3.0
sphinx-rtd-theme==0.4.3

Please let me know if any additional information would be helpful.

@AWhetter
Copy link
Collaborator

Thanks for the detailed report! The fix for this will go out in the next release.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Aug 24, 2020
v1.4.0 (2020-06-07)
-------------------

Features
^^^^^^^^
* `#197 <https://github.com/readthedocs/sphinx-autoapi/issues/197>`: Added
  ``autoapi.__version__`` and ``autoapi.__version_info__`` attributes
  for accessing version information.
* `#201 <https://github.com/readthedocs/sphinx-autoapi/issues/201>`: (Python)
  Added the ``autoapi_member_order`` option to allow the order that members
  are documentated to be configurable.
* `#203 <https://github.com/readthedocs/sphinx-autoapi/issues/203>`: (Python)
  A class without a docstring inherits one from its parent.
  A methods without a docstring inherits one from the method that it overrides.
* `#204 <https://github.com/readthedocs/sphinx-autoapi/issues/204>`: (Python)
  Added the ``imported-members`` AutoAPI option to be able to enable or disable
  documenting objects imported from the same top-level package or module
  without needing to override templates.

Bug Fixes
^^^^^^^^^
* `#198 <https://github.com/readthedocs/sphinx-autoapi/issues/198>`:
  Documentation describes the required layout for template override directories.
* `#195 <https://github.com/readthedocs/sphinx-autoapi/issues/195>`: (Python)
  Fixed incorrect formatting when ``show-inheritance-diagram``
  and ``private-members`` are turned on.
* `#193 <https://github.com/readthedocs/sphinx-autoapi/issues/193>` and
* `#208 <https://github.com/readthedocs/sphinx-autoapi/issues/208>`: (Python)
  Inheritance diagrams can follow imports to find classes to document.
* `#213 <https://github.com/readthedocs/sphinx-autoapi/issues/213>`: (Python)
  Fixed module summary never showing.

Trivial/Internal Changes
^^^^^^^^^^^^^^^^^^^^^^^^
* black shows diffs by default
* `#207 <https://github.com/readthedocs/sphinx-autoapi/issues/207>`:
  Fixed a typo in the code of the golang tutorial.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants