sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.59k stars 2.12k forks source link

.rst_t apidoc template files are not found #12916

Closed Sbte closed 1 month ago

Sbte commented 1 month ago

Describe the bug

Most likely since #11165 (at least since 7.4.0, not before that) my apidoc template files are not found anymore. They are called module.rst_t and package.rst_t. Renaming them to module.rst.jinja and package.rst.jinja fixes the issue, but this breaks compatibility with earlier sphinx versions. Moreover, .rst_t files will only be marked as deprecated starting 31 December 2024.

How to Reproduce

conf.py:

extensions = [
    'sphinxcontrib.apidoc',
]

templates_path = ['templates']
exclude_patterns = ['_build']

apidoc_module_dir = 'mod'
apidoc_output_dir = 'reference'

apidoc_separate_modules = True

templates/module.rst_t:

{%- if show_headings %}
{{- basename | e | heading }}

The template was found!
-----------------------

{% endif -%}
.. automodule:: {{ qualname }}
{%- for option in automodule_options %}
   :{{ option }}:
{%- endfor %}

index.rst

Hello World
===========

.. toctree::
   :maxdepth: 2
   :caption: API documentation

   reference/mod

mod/mod.py:

class Test:
    '''This is a test class'''
    pass

Using this configuration, you don't see the line "The template was found!" on the index page or anywhere else. Renaming templates/module.rst_t to templates/module.rst.jinja fixes the issue, but breaks compatibility with other sphinx versions.

Environment Information

Platform:              linux; (Linux-6.8.0-40-generic-x86_64-with-glibc2.35)
Python version:        3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0])
Python implementation: CPython
Sphinx version:        8.0.2
Docutils version:      0.20.1
Jinja2 version:        3.1.4
Pygments version:      2.18.0

Sphinx extensions

`['sphinxcontrib.apidoc']`

Additional context

No response

AA-Turner commented 1 month ago

cc @jayaddison

jayaddison commented 1 month ago

This seems to be a problem, yep. Thank you for the bugreport @Sbte. Although #11165 is where these changes were first prepared, I believe the first release to include them was v7.4.0 after they were (re)introduced by #12364.

This also seems to be a regression since it breaks existing functionality, so I'll add the appropriate bugtracker label. I should be able to start on a fix within the next day or two.

jayaddison commented 1 month ago

@Sbte I believe that pull request #12929 should resolve this - it includes some test coverage intended to demonstrate that it does, but if you have any time available to confirm that it fixes the problem that'd be much apprecated!

hennjanssen commented 1 month ago

I encountered exactly the same problem and tested different versions of Sphinx on my project (which is using *.rst_t files as templates):

Sphinx version Success?
7.3.7 🆗
7.4.0 👎
8.0.2 👎
8.1.0 from #12929 🆗

I was always using Python 3.12.5 on Ubuntu 22.04 with WSL. I hope that my contribution is helpful.

Sbte commented 1 month ago

@Sbte I believe that pull request #12929 should resolve this - it includes some test coverage intended to demonstrate that it does, but if you have any time available to confirm that it fixes the problem that'd be much apprecated!

Yes, that seems to have fixed it, thanks!