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

Conversation

astrofrog
Copy link
Member

Investigating the issue from astropy/astropy#16974

@astrofrog
Copy link
Member Author

For now this just adds the regression test. One way to solve that specific use case is to do:

.. automodapi:: sphinx_automodapi.tests.example_module.public
    :allowed-package-names: sphinx_automodapi.tests.example_module._private

however this could get tedious if we ever did use this pattern of private submodules extensively in a package. I wonder if actually what we want to do is to have an option to respect __all__ if it is present, as the authoritative version of what should be documented in a module.

@astrofrog
Copy link
Member Author

astrofrog commented Sep 11, 2024

I think I found the solution - the issue is that currently we were not trusting __all__ and still excluding items from all that were imported from another location unless :allowed-package-names: was present. I think this doesn't make sense - I'm pretty sure that most people documenting a module that contains __all__ will be expecting all items in __all__ to be included in the API docs, so I've made it so that the onlylocals option is ignored if __all__ is present.

Copy link

codecov bot commented Sep 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.29%. Comparing base (d671dd5) to head (7673171).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #190      +/-   ##
==========================================
+ Coverage   90.25%   90.29%   +0.04%     
==========================================
  Files          28       30       +2     
  Lines        1201     1206       +5     
==========================================
+ Hits         1084     1089       +5     
  Misses        117      117              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@astrofrog astrofrog marked this pull request as ready for review September 11, 2024 12:02
@@ -0,0 +1,5 @@
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

@nstarman
Copy link
Member

I'm not familiar with the internals of this package. I know it uses autosummary and has templates.
From that info, I would expect autosummary to generate the stub files via autodoc

A autosummary directive also generates short “stub” files for the entries listed in its content. These files by default contain only the corresponding sphinx.ext.autodoc directive, but can be customized with templates. (link)

The relevant autodoc directive would then have the :members: option which naturally uses __all__.

Is that what's happening here?

Comment on lines +1 to +7
Camelot
=======

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

.. autoclass:: Camelot
:show-inheritance:
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 :)

@astrofrog
Copy link
Member Author

In future we might want to re examine using Sphinx directly to generate all the API docs (this package predates the ability of Sphinx to generate stub files)

@bsipocz
Copy link
Member

bsipocz commented Sep 11, 2024

In future we might want to re examine using Sphinx directly to generate all the API docs (this package predates the ability of Sphinx to generate stub files)

I really wondered about this, too as a lot has happened in the past 10 years on sphinx land...

@astrofrog
Copy link
Member Author

@bsipocz - I adjusted the test as you requested to include a class imported from a public submodule

@pllim pllim added the bug label Sep 12, 2024
@pllim
Copy link
Member

pllim commented Sep 12, 2024

Re: Using Sphinx directly -- We have issue at #147

Copy link
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

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

Looks good now, thanks @astrofrog!

@bsipocz
Copy link
Member

bsipocz commented Sep 12, 2024

Re: Using Sphinx directly -- We have issue at #147

Yes, I think we're circling back to that question but I can't recall if someone looked into it carefully and made a full assessment. Btw, things like these can be funded short projects; as it's absolutely in the remit of long-term sustainability and maintenance (and IMO has a better impact on the project than bombarding the codebase with automated ruff and such refactorings forcing a lot of rebase and conflicts on PRs and such)

@pllim
Copy link
Member

pllim commented Sep 12, 2024

funded short projects

Would be nice! Cycle 4 already ongoing... I wonder if someone wants to take this on for Cycle 5 or some other alternate funding.

@astrofrog astrofrog merged commit 2e1f9e0 into astropy:main Sep 13, 2024
19 checks passed
@pllim
Copy link
Member

pllim commented Sep 13, 2024

Thanks, all! @astrofrog , do you plan to do a release here or you need help?

@astrofrog
Copy link
Member Author

Already done! (v0.18)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants