Skip to content

Commit 3c9c885

Browse files
authored
Merge pull request #142 from adrn/fix-skip-issue
Fix issue with :skip: introduced by :include: feature
2 parents bcc41ff + a9177d4 commit 3c9c885

File tree

5 files changed

+122
-3
lines changed

5 files changed

+122
-3
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Changes in sphinx-automodapi
44
0.15.0 (unreleased)
55
-------------------
66

7+
- Fixed issue with ``:skip:`` introduced by ``:include:`` feature. [#142]
8+
79
0.14.0 (2021-12-22)
810
-------------------
911

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ filterwarnings =
4343
ignore:The `docutils\.parsers\.rst\.directive\.html` module will be removed:DeprecationWarning
4444
ignore:'contextfunction' is renamed to 'pass_context':DeprecationWarning
4545
ignore:'environmentfilter' is renamed to 'pass_environment':DeprecationWarning
46+
ignore:distutils Version classes are deprecated:DeprecationWarning
4647

4748
[flake8]
4849
max-line-length = 125

sphinx_automodapi/automodapi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,12 @@ def _mod_info(modname, toskip=[], include=[], onlylocals=True):
411411

412412
hascls = hasfunc = hasother = False
413413

414-
skips = []
414+
skips = toskip.copy()
415415
for localnm, fqnm, obj in zip(*find_mod_objs(modname, onlylocals=onlylocals)):
416-
if localnm in toskip or (include and localnm not in include):
416+
if include and localnm not in include and localnm not in skips:
417417
skips.append(localnm)
418418

419-
else:
419+
elif localnm not in toskip:
420420
hascls = hascls or inspect.isclass(obj)
421421
hasfunc = hasfunc or inspect.isroutine(obj)
422422
hasother = hasother or (not inspect.isclass(obj) and
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
A module that imports objects from the standard library.
3+
"""
4+
from pathlib import Path
5+
from datetime import time
6+
7+
8+
__all__ = ['Path', 'time', 'add']
9+
10+
11+
def add(a, b):
12+
"""
13+
Add two numbers
14+
"""
15+
return a + b

sphinx_automodapi/tests/test_automodapi.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,107 @@ def test_am_replacer_skip(tmpdir):
327327
assert result == am_replacer_skip_expected
328328

329329

330+
am_replacer_skip_stdlib_str = """
331+
This comes before
332+
333+
.. automodapi:: sphinx_automodapi.tests.example_module.stdlib
334+
:skip: time
335+
:skip: Path
336+
337+
This comes after
338+
"""
339+
340+
341+
am_replacer_skip_stdlib_expected = """
342+
This comes before
343+
344+
345+
sphinx_automodapi.tests.example_module.stdlib Module
346+
----------------------------------------------------
347+
348+
.. automodule:: sphinx_automodapi.tests.example_module.stdlib
349+
350+
Functions
351+
^^^^^^^^^
352+
353+
.. automodsumm:: sphinx_automodapi.tests.example_module.stdlib
354+
:functions-only:
355+
:toctree: api
356+
:skip: time,Path
357+
358+
359+
This comes after
360+
""".format(empty='')
361+
362+
363+
def test_am_replacer_skip_stdlib(tmpdir):
364+
"""
365+
Tests using the ":skip:" option in an ".. automodapi::"
366+
that skips objects imported from the standard library.
367+
This is a regression test for #141
368+
"""
369+
370+
with open(tmpdir.join('index.rst').strpath, 'w') as f:
371+
f.write(am_replacer_skip_stdlib_str.format(options=''))
372+
373+
run_sphinx_in_tmpdir(tmpdir)
374+
375+
with open(tmpdir.join('index.rst.automodapi').strpath) as f:
376+
result = f.read()
377+
378+
assert result == am_replacer_skip_stdlib_expected
379+
380+
381+
am_replacer_include_stdlib_str = """
382+
This comes before
383+
384+
.. automodapi:: sphinx_automodapi.tests.example_module.stdlib
385+
:include: add
386+
:allowed-package-names: pathlib, datetime, sphinx_automodapi
387+
388+
This comes after
389+
"""
390+
391+
am_replacer_include_stdlib_expected = """
392+
This comes before
393+
394+
395+
sphinx_automodapi.tests.example_module.stdlib Module
396+
----------------------------------------------------
397+
398+
.. automodule:: sphinx_automodapi.tests.example_module.stdlib
399+
400+
Functions
401+
^^^^^^^^^
402+
403+
.. automodsumm:: sphinx_automodapi.tests.example_module.stdlib
404+
:functions-only:
405+
:toctree: api
406+
:skip: Path,time
407+
:allowed-package-names: pathlib,datetime,sphinx_automodapi
408+
409+
410+
This comes after
411+
""".format(empty='')
412+
413+
414+
def test_am_replacer_include_stdlib(tmpdir):
415+
"""
416+
Tests using the ":include: option in an ".. automodapi::"
417+
in the presence of objects imported from the standard library.
418+
"""
419+
420+
with open(tmpdir.join('index.rst').strpath, 'w') as f:
421+
f.write(am_replacer_include_stdlib_str.format(options=''))
422+
423+
run_sphinx_in_tmpdir(tmpdir)
424+
425+
with open(tmpdir.join('index.rst.automodapi').strpath) as f:
426+
result = f.read()
427+
428+
assert result == am_replacer_include_stdlib_expected
429+
430+
330431
am_replacer_include_str = """
331432
This comes before
332433

0 commit comments

Comments
 (0)