Skip to content

Commit 2e1f9e0

Browse files
authored
Merge pull request #190 from astrofrog/import-private-into-public
Added test case for importing a class from a private submodule into a public one
2 parents 7e5e6fa + 7673171 commit 2e1f9e0

11 files changed

+62
-3
lines changed

CHANGES.rst

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Changes in sphinx-automodapi
44
0.18.0 (unreleased)
55
-------------------
66

7+
- Fixed an issue where items defined in ``__all__`` but originally imported
8+
from elsewhere, e.g. a private module, were not documented. [#190]
9+
710
0.17.0 (2024-02-22)
811
-------------------
912

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Importing a class from a private submodule to a public submodule
2+
at the same level of hierarchy in the module.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. automodapi:: sphinx_automodapi.tests.example_module.public
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Camelot
2+
=======
3+
4+
.. currentmodule:: sphinx_automodapi.tests.example_module.public
5+
6+
.. autoclass:: Camelot
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Spam
2+
====
3+
4+
.. currentmodule:: sphinx_automodapi.tests.example_module.public
5+
6+
.. autoclass:: Spam
7+
:show-inheritance:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
sphinx_automodapi.tests.example_module.public Module
3+
----------------------------------------------------
4+
5+
.. automodule:: sphinx_automodapi.tests.example_module.public
6+
7+
Classes
8+
^^^^^^^
9+
10+
.. automodsumm:: sphinx_automodapi.tests.example_module.public
11+
:classes-only:
12+
:toctree: api
13+
14+
Class Inheritance Diagram
15+
^^^^^^^^^^^^^^^^^^^^^^^^^
16+
17+
.. automod-diagram:: sphinx_automodapi.tests.example_module.public
18+
:private-bases:
19+
:parts: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.. currentmodule:: sphinx_automodapi.tests.example_module.public
2+
3+
.. autosummary::
4+
:toctree: api
5+
6+
Camelot
7+
Spam
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Camelot:
2+
"""
3+
It's a silly place anyway
4+
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from ._private import Camelot
2+
from .classes import Spam
3+
4+
__all__ = [
5+
'Camelot',
6+
'Spam'
7+
]

sphinx_automodapi/utils.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ def find_mod_objs(modname, onlylocals=False, sort=False):
5050
modname : str
5151
The name of the module to search.
5252
onlylocals : bool or list
53-
If True, only attributes that are either members of `modname` OR one of
53+
If `True`, only attributes that are either members of `modname` OR one of
5454
its modules or subpackages will be included. If a list, only members
5555
of packages in the list are included. If `False`, selection is done.
56+
This option is ignored if a module defines __all__ - in that case, __all__
57+
is used to determine whether objects are public.
5658
5759
Returns
5860
-------
@@ -81,7 +83,7 @@ def find_mod_objs(modname, onlylocals=False, sort=False):
8183
# Optionally sort the items alphabetically
8284
if sort:
8385
pkgitems.sort()
84-
86+
onlylocals = False
8587
else:
8688
pkgitems = [(k, getattr(mod, k)) for k in dir(mod) if k[0] != "_"]
8789

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extras =
1919
test: test
2020
commands =
2121
pip freeze
22-
!cov: pytest --pyargs sphinx_automodapi
22+
!cov: pytest --pyargs sphinx_automodapi {posargs}
2323
cov: pytest --pyargs sphinx_automodapi --cov sphinx_automodapi --cov-config={toxinidir}/setup.cfg {posargs}
2424
cov: coverage xml -o {toxinidir}/coverage.xml
2525
passenv = HOME, WINDIR, LC_ALL, LC_CTYPE, LANG, CC, CI

0 commit comments

Comments
 (0)