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

Can't get local templates to work #198

Closed
JamesALeedham opened this issue Apr 21, 2020 · 7 comments
Closed

Can't get local templates to work #198

JamesALeedham opened this issue Apr 21, 2020 · 7 comments

Comments

@JamesALeedham
Copy link

I want to customize the way classes are templated.

So I copied https://raw.githubusercontent.com/readthedocs/sphinx-autoapi/master/autoapi/templates/python/class.rst to a source/_autoapi_templates folder, saving it as class.rst. Then in source/conf.py I set autoapi_template_dir = '_autoapi_templates'.

When I run make html, however, my template changes aren't reflected in class output. What's going wrong?

@AWhetter
Copy link
Collaborator

Do you have an example project where this isn't working?

@JamesALeedham
Copy link
Author

Thanks very much for getting back to me. Just to say that sphinx-autoapi looks really good so far, so much easier to understand than either sphinx-apidoc or sphinx.ext.autosummary. I look forward to getting it in production on Readthedocs asap.

Please find attached a tar.gz with a sample project. I'm running Ubuntu 18.04 and a Python 3.7.5 virtual env. Running pip freeze reports:

alabaster==0.7.12
astroid==2.3.3
Babel==2.8.0
certifi==2020.4.5.1
chardet==3.0.4
docutils==0.16
idna==2.9
imagesize==1.2.0
Jinja2==2.11.2
lazy-object-proxy==1.4.3
MarkupSafe==1.1.1
packaging==20.3
pkg-resources==0.0.0
Pygments==2.6.1
pyparsing==2.4.7
pytz==2019.3
PyYAML==5.3.1
requests==2.23.0
six==1.14.0
snowballstemmer==2.0.0
Sphinx==3.0.2
sphinx-autoapi==1.3.0
sphinx-rtd-theme==0.4.3
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==1.0.3
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.4
typed-ast==1.4.1
Unidecode==1.1.1
urllib3==1.25.9
wrapt==1.11.2

To set up the project, I ran:

  1. pip install sphinx sphinx-autoapi sphinx_rtd_theme
  2. make html

In source/_autoapi_templates/class.rst I made some (nonsense) local edits to the class template. This is referenced in source/conf.py using autoapi_template_dir = '_autoapi_templates'.

My expectation was that the presence of the local class.rst file would override site-packages/autoapi/templates/python/class.rst. However, this doesn't seem to be the case - the nonsense edits don't show up in the built html.

TEST.tar.gz

@Markus-Goetz
Copy link

I can confirm the behaviour @JamesALeedham experiences. Together with a colleague, we closely followed the guide on your tutorial web pages. We were unable to use a custom template as described. However, changes to the template in the site-packages folder affected the building.

Per environment: we have tested it for sphinx-autoapi version 1.2.0 as well as 1.3.0 in a virtual environment created using python -m venv ...

@mesca
Copy link

mesca commented Apr 28, 2020

In conf.py:

templates_path = ['_templates']
autoapi_template_dir = '_templates/autoapi'

And move your template to: _templates/autoapi/python/class.rst

@JamesALeedham
Copy link
Author

Brilliant! Thanks @mesca ! That works...

So it seems the (mandatory) bit I was missing was a /python/ directory in the local template path. Perhaps this doc could be made a bit more explicit...

@Markus-Goetz
Copy link

Same here. Thanks for the quick response. Definitely upvoting the doc change.

@AWhetter
Copy link
Collaborator

Thanks for the suggestions. I've included an explained example in the documentation to make this more clear.

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants