From baa95e98ac266eca63fe115ddb3a6ea08c493408 Mon Sep 17 00:00:00 2001 From: Ed Slavich Date: Mon, 27 Dec 2021 14:10:22 -0500 Subject: [PATCH 1/7] Add test of :skip: with stdlib objects --- .../tests/example_module/stdlib.py | 12 +++++ sphinx_automodapi/tests/test_automodapi.py | 50 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 sphinx_automodapi/tests/example_module/stdlib.py diff --git a/sphinx_automodapi/tests/example_module/stdlib.py b/sphinx_automodapi/tests/example_module/stdlib.py new file mode 100644 index 0000000..3ce715d --- /dev/null +++ b/sphinx_automodapi/tests/example_module/stdlib.py @@ -0,0 +1,12 @@ +""" +A module that imports objects from the standard library. +""" +from pathlib import Path +from datetime import time + + +def add(a, b): + """ + Add two numbers + """ + return a + b diff --git a/sphinx_automodapi/tests/test_automodapi.py b/sphinx_automodapi/tests/test_automodapi.py index cd0550e..21f6e1d 100644 --- a/sphinx_automodapi/tests/test_automodapi.py +++ b/sphinx_automodapi/tests/test_automodapi.py @@ -327,6 +327,56 @@ def test_am_replacer_skip(tmpdir): assert result == am_replacer_skip_expected +am_replacer_skip_stdlib_str = """ +This comes before + +.. automodapi:: sphinx_automodapi.tests.example_module.stdlib + :skip: time + :skip: Path + +This comes after +""" + + +am_replacer_skip_stdlib_expected = """ +This comes before + + +sphinx_automodapi.tests.example_module.stdlib Module +---------------------------------------------------- + +.. automodule:: sphinx_automodapi.tests.example_module.stdlib + +Functions +^^^^^^^^^ + +.. automodsumm:: sphinx_automodapi.tests.example_module.stdlib + :functions-only: + :toctree: api + :skip: time,Path + + +This comes after +""".format(empty='') + + +def test_am_replacer_skip_stdlib(tmpdir): + """ + Tests using the ":skip:" option in an ".. automodapi::" + that skips objects imported from the standard library. + """ + + with open(tmpdir.join('index.rst').strpath, 'w') as f: + f.write(am_replacer_skip_stdlib_str.format(options='')) + + run_sphinx_in_tmpdir(tmpdir) + + with open(tmpdir.join('index.rst.automodapi').strpath) as f: + result = f.read() + + assert result == am_replacer_skip_stdlib_expected + + am_replacer_include_str = """ This comes before From 8be51e311d8748594e3537ed22471b6d114e3799 Mon Sep 17 00:00:00 2001 From: Ed Slavich Date: Mon, 27 Dec 2021 14:19:12 -0500 Subject: [PATCH 2/7] Fix style issue --- sphinx_automodapi/tests/example_module/stdlib.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sphinx_automodapi/tests/example_module/stdlib.py b/sphinx_automodapi/tests/example_module/stdlib.py index 3ce715d..626dc69 100644 --- a/sphinx_automodapi/tests/example_module/stdlib.py +++ b/sphinx_automodapi/tests/example_module/stdlib.py @@ -5,6 +5,9 @@ from datetime import time +__all__ = ['Path', 'time', 'add'] + + def add(a, b): """ Add two numbers From 610bb350c336fb48b2011e9ea2a974a1e89f9416 Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Tue, 28 Dec 2021 18:10:57 -0500 Subject: [PATCH 3/7] fix for skip bug --- sphinx_automodapi/automodapi.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sphinx_automodapi/automodapi.py b/sphinx_automodapi/automodapi.py index 1957194..28cff8a 100644 --- a/sphinx_automodapi/automodapi.py +++ b/sphinx_automodapi/automodapi.py @@ -411,12 +411,12 @@ def _mod_info(modname, toskip=[], include=[], onlylocals=True): hascls = hasfunc = hasother = False - skips = [] + skips = toskip.copy() for localnm, fqnm, obj in zip(*find_mod_objs(modname, onlylocals=onlylocals)): - if localnm in toskip or (include and localnm not in include): + if include and localnm not in include and localnm not in skips: skips.append(localnm) - else: + elif localnm not in toskip: hascls = hascls or inspect.isclass(obj) hasfunc = hasfunc or inspect.isroutine(obj) hasother = hasother or (not inspect.isclass(obj) and From 57a83608a60228688c7813ab43223fd03e59c519 Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Tue, 28 Dec 2021 18:11:19 -0500 Subject: [PATCH 4/7] add note about regression test --- sphinx_automodapi/tests/test_automodapi.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sphinx_automodapi/tests/test_automodapi.py b/sphinx_automodapi/tests/test_automodapi.py index 21f6e1d..4aa40a0 100644 --- a/sphinx_automodapi/tests/test_automodapi.py +++ b/sphinx_automodapi/tests/test_automodapi.py @@ -364,6 +364,7 @@ def test_am_replacer_skip_stdlib(tmpdir): """ Tests using the ":skip:" option in an ".. automodapi::" that skips objects imported from the standard library. + This is a regression test for #141 """ with open(tmpdir.join('index.rst').strpath, 'w') as f: From 4ae1ae4357d6ba04f53dd2360449c8e1f6afc26a Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Wed, 29 Dec 2021 09:25:17 -0500 Subject: [PATCH 5/7] Ignore distutils DeprecationWarning from Sphinx --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index fdd19cc..0dfbcc6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -43,6 +43,7 @@ filterwarnings = ignore:The `docutils\.parsers\.rst\.directive\.html` module will be removed:DeprecationWarning ignore:'contextfunction' is renamed to 'pass_context':DeprecationWarning ignore:'environmentfilter' is renamed to 'pass_environment':DeprecationWarning + ignore:distutils Version classes are deprecated:DeprecationWarning [flake8] max-line-length = 125 From b355d3075f782214fca91bab21bc13c25772039e Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Wed, 29 Dec 2021 09:30:14 -0500 Subject: [PATCH 6/7] Update CHANGES.rst --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 62b20ed..53fa563 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,8 @@ Changes in sphinx-automodapi 0.15.0 (unreleased) ------------------- +- Fixed issue with ``:skip:`` introduced by ``:include:`` feature. [#142] + 0.14.0 (2021-12-22) ------------------- From a9177d460c8c1130ee630a6d3c541324b43f213b Mon Sep 17 00:00:00 2001 From: Adrian Price-Whelan Date: Wed, 29 Dec 2021 12:56:36 -0500 Subject: [PATCH 7/7] add one more validation that non-local names get skipped --- sphinx_automodapi/tests/test_automodapi.py | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/sphinx_automodapi/tests/test_automodapi.py b/sphinx_automodapi/tests/test_automodapi.py index 4aa40a0..72e52fd 100644 --- a/sphinx_automodapi/tests/test_automodapi.py +++ b/sphinx_automodapi/tests/test_automodapi.py @@ -378,6 +378,56 @@ def test_am_replacer_skip_stdlib(tmpdir): assert result == am_replacer_skip_stdlib_expected +am_replacer_include_stdlib_str = """ +This comes before + +.. automodapi:: sphinx_automodapi.tests.example_module.stdlib + :include: add + :allowed-package-names: pathlib, datetime, sphinx_automodapi + +This comes after +""" + +am_replacer_include_stdlib_expected = """ +This comes before + + +sphinx_automodapi.tests.example_module.stdlib Module +---------------------------------------------------- + +.. automodule:: sphinx_automodapi.tests.example_module.stdlib + +Functions +^^^^^^^^^ + +.. automodsumm:: sphinx_automodapi.tests.example_module.stdlib + :functions-only: + :toctree: api + :skip: Path,time + :allowed-package-names: pathlib,datetime,sphinx_automodapi + + +This comes after +""".format(empty='') + + +def test_am_replacer_include_stdlib(tmpdir): + """ + Tests using the ":include: option in an ".. automodapi::" + in the presence of objects imported from the standard library. + """ + + with open(tmpdir.join('index.rst').strpath, 'w') as f: + f.write(am_replacer_include_stdlib_str.format(options='')) + + run_sphinx_in_tmpdir(tmpdir) + + with open(tmpdir.join('index.rst.automodapi').strpath) as f: + result = f.read() + + assert result == am_replacer_include_stdlib_expected + + am_replacer_include_str = """ This comes before