Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test case for importing a class from a private submodule into a public one #190

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changes in sphinx-automodapi
0.18.0 (unreleased)
-------------------

- Fixed an issue where items defined in ``__all__`` but originally imported
from elsewhere, e.g. a private module, were not documented. [#190]

0.17.0 (2024-02-22)
-------------------

Expand Down
2 changes: 2 additions & 0 deletions sphinx_automodapi/tests/cases/public_from_private/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Importing a class from a private submodule to a public submodule
at the same level of hierarchy in the module.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. automodapi:: sphinx_automodapi.tests.example_module.public
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Camelot
=======

.. currentmodule:: sphinx_automodapi.tests.example_module.public

.. autoclass:: Camelot
:show-inheritance:
Comment on lines +1 to +7
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nstarman we actually generate the stub files ourselves and they contain individual eg autoclass calls so the fix has to be and is in our code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then all LGTM. The results files seem reasonable :)

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Spam
====

.. currentmodule:: sphinx_automodapi.tests.example_module.public

.. autoclass:: Spam
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

sphinx_automodapi.tests.example_module.public Module
----------------------------------------------------

.. automodule:: sphinx_automodapi.tests.example_module.public

Classes
^^^^^^^

.. automodsumm:: sphinx_automodapi.tests.example_module.public
:classes-only:
:toctree: api

Class Inheritance Diagram
^^^^^^^^^^^^^^^^^^^^^^^^^

.. automod-diagram:: sphinx_automodapi.tests.example_module.public
:private-bases:
:parts: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. currentmodule:: sphinx_automodapi.tests.example_module.public

.. autosummary::
:toctree: api

Camelot
Spam
4 changes: 4 additions & 0 deletions sphinx_automodapi/tests/example_module/_private.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Camelot:
"""
It's a silly place anyway
"""
7 changes: 7 additions & 0 deletions sphinx_automodapi/tests/example_module/public.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from ._private import Camelot
Copy link
Member

@bsipocz bsipocz Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a test where we import from a non-private module? I mean those cases worked (before this PR), so I just want to make sure that keeps being the case.
(although I see cases where they listed in multiple __all__s, probably those should be cleaned up, and (which is beyond scope here) preferably errored out by sphinx-automodapi?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, will adjust the test

from .classes import Spam

__all__ = [
'Camelot',
'Spam'
]
6 changes: 4 additions & 2 deletions sphinx_automodapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ def find_mod_objs(modname, onlylocals=False, sort=False):
modname : str
The name of the module to search.
onlylocals : bool or list
If True, only attributes that are either members of `modname` OR one of
If `True`, only attributes that are either members of `modname` OR one of
its modules or subpackages will be included. If a list, only members
of packages in the list are included. If `False`, selection is done.
This option is ignored if a module defines __all__ - in that case, __all__
is used to determine whether objects are public.

Returns
-------
Expand Down Expand Up @@ -81,7 +83,7 @@ def find_mod_objs(modname, onlylocals=False, sort=False):
# Optionally sort the items alphabetically
if sort:
pkgitems.sort()

onlylocals = False
else:
pkgitems = [(k, getattr(mod, k)) for k in dir(mod) if k[0] != "_"]

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extras =
test: test
commands =
pip freeze
!cov: pytest --pyargs sphinx_automodapi
!cov: pytest --pyargs sphinx_automodapi {posargs}
cov: pytest --pyargs sphinx_automodapi --cov sphinx_automodapi --cov-config={toxinidir}/setup.cfg {posargs}
cov: coverage xml -o {toxinidir}/coverage.xml
passenv = HOME, WINDIR, LC_ALL, LC_CTYPE, LANG, CC, CI
Expand Down
Loading