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

Ensure submodules are unique in sphinx.ext.apidoc #10406

Merged
merged 2 commits into from May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -72,6 +72,8 @@ Features added
Bugs fixed
----------

* #10200: apidoc: Duplicated submodules are shown for modules having both .pyx
and .so files
* #10279: autodoc: Default values for keyword only arguments in overloaded
functions are rendered as a string literal
* #10280: autodoc: :confval:`autodoc_docstring_signature` unexpectedly generates
Expand Down
1 change: 1 addition & 0 deletions sphinx/ext/apidoc.py
Expand Up @@ -117,6 +117,7 @@ def create_package_file(root: str, master_package: str, subroot: str, py_files:
submodules = [sub.split('.')[0] for sub in py_files
if not is_skipped_module(path.join(root, sub), opts, excludes) and
not is_initpy(sub)]
submodules = sorted(set(submodules))
submodules = [module_join(master_package, subroot, modname)
for modname in submodules]
options = copy(OPTIONS)
Expand Down
Empty file.
29 changes: 29 additions & 0 deletions tests/test_ext_apidoc.py
Expand Up @@ -4,6 +4,7 @@

import pytest

import sphinx.ext.apidoc
from sphinx.ext.apidoc import main as apidoc_main
from sphinx.testing.path import path

Expand Down Expand Up @@ -639,3 +640,31 @@ def test_namespace_package_file(tempdir):
" :members:\n"
" :undoc-members:\n"
" :show-inheritance:\n")


def test_no_duplicates(rootdir, tempdir):
"""Make sure that a ".pyx" and ".so" don't cause duplicate listings.

We can't use pytest.mark.apidoc here as we use a different set of arguments
to apidoc_main
"""

original_suffixes = sphinx.ext.apidoc.PY_SUFFIXES
try:
# Ensure test works on Windows
sphinx.ext.apidoc.PY_SUFFIXES += ('.so',)

package = rootdir / 'test-apidoc-duplicates' / 'fish_licence'
outdir = tempdir / 'out'
apidoc_main(['-o', outdir, "-T", package, "--implicit-namespaces"])

# Ensure the module has been documented
assert (outdir / 'fish_licence.rst').isfile()

# Ensure the submodule only appears once
text = (outdir / 'fish_licence.rst').read_text(encoding="utf-8")
count_submodules = text.count(r'fish\_licence.halibut module')
assert count_submodules == 1

finally:
sphinx.ext.apidoc.PY_SUFFIXES = original_suffixes