Skip to content

Commit

Permalink
Merge pull request #142 from adrn/fix-skip-issue
Browse files Browse the repository at this point in the history
Fix issue with :skip: introduced by :include: feature
  • Loading branch information
pllim committed Dec 29, 2021
2 parents bcc41ff + a9177d4 commit 3c9c885
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -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)
-------------------

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions sphinx_automodapi/automodapi.py
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions sphinx_automodapi/tests/example_module/stdlib.py
@@ -0,0 +1,15 @@
"""
A module that imports objects from the standard library.
"""
from pathlib import Path
from datetime import time


__all__ = ['Path', 'time', 'add']


def add(a, b):
"""
Add two numbers
"""
return a + b
101 changes: 101 additions & 0 deletions sphinx_automodapi/tests/test_automodapi.py
Expand Up @@ -327,6 +327,107 @@ 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.
This is a regression test for #141
"""

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_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
Expand Down

0 comments on commit 3c9c885

Please sign in to comment.