Skip to content

toctree is wrong for python modules named "md" #10914

@bernstei

Description

@bernstei

Describe the bug

When constructing the toctree suffixes are stripped in

# remove suffixes (backwards compatibility)

However, if the toctree is for a python package that includes a subpackage which is named md, in our production case wfl.generate.md, the final package name is stripped off, because it happens to match a valid suffix (.md for markdown), and the toctree is broken. Instead of wfl.generate toc including the items from wfl.generate.md, it tries to include itself (because the .md was removed while adding nodes for sub-packages), and so there is no link to the wfl.generate.md docs, and there are lots of warnings about circular references.

How to Reproduce

tar xzf sphinx_suffix_bug.tar.gz
cd sphinx_suffix_bug
source README

sphinx_suffix_bug.tar.gz

Expected behavior

Both "working" and "broken" versions of the package should get documentation generated identically and correctly, except for the subpackage name of md vs. mda.

Instead, I get the output in sphinx_suffix_bug.output.txt
and the resulting docs are different - the working one shows mda as a subpackage of pkg, while the other puts another copy of the contents of pkg inside pkg, and nothing from md (see screenshots below).

Your project

The real thing is at https://libatoms.github.io/workflow/modules.html, but a small example has been attached to the "how to reproduce" section

Screenshots

sphinx broken html screenshot

sphinx working html screenshot

images of top level index.html, showing subpackage mda ("working"), but nothing for subpackage md ("broken")

OS

Rocky Linux 8

Python version

3.9.7

Sphinx version

4.5.0

Sphinx extensions

many, most relevantly autodoc and napoleon

Extra tools

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions