From 6050062efa9751ee65eea96d43705e3a601f36c1 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 1 May 2022 00:45:39 +0900 Subject: [PATCH 1/2] Fix #10200: apidoc: Duplicated submodules are shown for modules --- CHANGES | 2 ++ sphinx/ext/apidoc.py | 1 + 2 files changed, 3 insertions(+) diff --git a/CHANGES b/CHANGES index cac188e60a7..481916830a3 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/sphinx/ext/apidoc.py b/sphinx/ext/apidoc.py index 68afc83b8d1..ebea66a6c81 100644 --- a/sphinx/ext/apidoc.py +++ b/sphinx/ext/apidoc.py @@ -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) From bde47ce67957638712b23b5d249c085376dbf453 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 1 May 2022 06:12:25 +0100 Subject: [PATCH 2/2] Add test for duplicated submodules in `sphinx.ext.apidoc` --- .../halibut.cpython-38-x86_64-linux-gnu.so | 0 .../fish_licence/halibut.pyx | 0 tests/test_ext_apidoc.py | 29 +++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 tests/roots/test-apidoc-duplicates/fish_licence/halibut.cpython-38-x86_64-linux-gnu.so create mode 100644 tests/roots/test-apidoc-duplicates/fish_licence/halibut.pyx diff --git a/tests/roots/test-apidoc-duplicates/fish_licence/halibut.cpython-38-x86_64-linux-gnu.so b/tests/roots/test-apidoc-duplicates/fish_licence/halibut.cpython-38-x86_64-linux-gnu.so new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/roots/test-apidoc-duplicates/fish_licence/halibut.pyx b/tests/roots/test-apidoc-duplicates/fish_licence/halibut.pyx new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/test_ext_apidoc.py b/tests/test_ext_apidoc.py index 7aba847a397..8a3c499f3c1 100644 --- a/tests/test_ext_apidoc.py +++ b/tests/test_ext_apidoc.py @@ -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 @@ -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