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

Fix issue with :skip: introduced by :include: feature #142

Merged
merged 7 commits into from Dec 29, 2021

Conversation

adrn
Copy link
Member

@adrn adrn commented Dec 28, 2021

This is a fix for the bug identified in #141. The fix is implemented in the first commit from me, which simplifies some of the logic and reverts back to looking more like it did before #127 but keeps the new :include: functionality.

Note: this includes the commits from #140 which added a useful regression test.

cc @eslavich

EDIT:

@adrn
Copy link
Member Author

adrn commented Dec 28, 2021

Uhh, what's up with the failing tests?? Any ideas @pllim?

@pllim
Copy link
Member

pllim commented Dec 29, 2021

Looks like Sphinx is using distutils but it is deprecated now. I guess we can ignore it...

../../.tox/py38-test-sphinx35/lib/python3.8/site-packages/sphinx/util/smartypants.py:33: in <module>
    from sphinx.util.docutils import __version_info__ as docutils_version
../../.tox/py38-test-sphinx35/lib/python3.8/site-packages/sphinx/util/docutils.py:45: in <module>
    __version_info__ = tuple(LooseVersion(docutils.__version__).version)
../../.tox/py38-test-sphinx35/lib/python3.8/site-packages/setuptools/_distutils/version.py:53: in __init__
    warnings.warn(
E   DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.

@pllim pllim added the bug label Dec 29, 2021
@pllim pllim added this to the 0.15.0 milestone Dec 29, 2021
@codecov
Copy link

codecov bot commented Dec 29, 2021

Codecov Report

Merging #142 (a9177d4) into main (ef2e5dd) will increase coverage by 0.14%.
The diff coverage is 96.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #142      +/-   ##
==========================================
+ Coverage   89.00%   89.14%   +0.14%     
==========================================
  Files          22       23       +1     
  Lines        1091     1115      +24     
==========================================
+ Hits          971      994      +23     
- Misses        120      121       +1     
Impacted Files Coverage Δ
sphinx_automodapi/tests/example_module/stdlib.py 80.00% <80.00%> (ø)
sphinx_automodapi/automodapi.py 93.29% <100.00%> (+0.04%) ⬆️
sphinx_automodapi/tests/test_automodapi.py 99.16% <100.00%> (+0.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bcc41ff...a9177d4. Read the comment docs.

@pllim
Copy link
Member

pllim commented Dec 29, 2021

I don't grok what is going on here, so I'll wait for @eslavich to review. Thanks for the quick fix!

Copy link

@eslavich eslavich left a comment

Choose a reason for hiding this comment

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

One possible issue, thanks for the fast turnaround on this @adrn!

@@ -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)):

Choose a reason for hiding this comment

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

I think the new :include: feature has a similar problem as was introduced for :skip:. Here's a test that fails on this branch:

am_replacer_include_stdlib_str = """
This comes before

.. automodapi:: sphinx_automodapi.tests.example_module.stdlib
    :include: add

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


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
    ```

Copy link
Member Author

@adrn adrn Dec 29, 2021

Choose a reason for hiding this comment

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

I don't think this is an issue -- the function names would only need to be skipped if you added the stdlib module names to :allowed-package-names:. For example,

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='')

Then the test passes. Otherwise, find_mod_objs() has onlylocals=True and ignores the imported names.

Choose a reason for hiding this comment

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

Ah, okay! That makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

Do you at least want to put this test in CI before merge?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure

Choose a reason for hiding this comment

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

I'm not sure it's a worthy test, given what @adrn told me -- it makes sense that :skip: doesn't appear, but I'm not sure that we need to assert that it is not present.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added one more check that doing what I said in the comment above makes your test pass -- I think that is still worth including!

Copy link

@eslavich eslavich left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@pllim pllim left a comment

Choose a reason for hiding this comment

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

Thanks, all!

@pllim pllim merged commit 3c9c885 into astropy:main Dec 29, 2021
@pllim
Copy link
Member

pllim commented Dec 29, 2021

Since I also fixed jwst docs to not require this patch, I don't think an immediate release is needed. But please let me know if you disagree. Thanks!

@mwcraig
Copy link
Member

mwcraig commented Jan 12, 2022

@pllim -- if you have a chance a new release would be helpful because ccdproc tests are failing because of this (we have defined __all__ so that fix won't work here).

Failing test: https://github.com/astropy/ccdproc/runs/4757634889?check_suite_focus=true#step:7:79

Pinned the version for now, so no an emergency

@pllim pllim modified the milestones: 0.15.0, 0.14.1 Jan 12, 2022
@pllim
Copy link
Member

pllim commented Jan 12, 2022

Done. v0.14.1 is on PyPI. Hope this helps!

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.

:skip: no longer works with standard library objects
4 participants