-
-
Couldn't load subscription status.
- Fork 169
Refactor to make sphinx a soft dependency #651
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
base: main
Are you sure you want to change the base?
Conversation
All other functions defined in numpydoc.py module depend on sphinx and therefore can be skipped for testing purposes when sphinx is not installed. importorskips the numpydoc tests but maintains the testing of _clean_text_signature in new test_utils.py module.
When sphinx is not installed, ignore the numpydoc.py and docscrape_sphinx.py modules during test collection as they depend on sphinx.
The only thing here that depends on sphinx is the fn which uses docscrape_sphinx's version of get_doc_object. If we switch to docscrape's version of get_doc_object, then the resulting rendering is derived from NumpyDocString instead of SphinxDocString. Alternatively - this could be left as-is and the test_render tests in could be importorskipped.
|
Thanks for tackling this! Just one quick idea comes to mind for:
Have you considered splitting while keeping blame? I did this recently in mne-tools/mne-qt-browser#350 (comment) for example and it seems to have worked for preserving blame. But I understand if this doesn't seem worth it here! Your TODO list looks good to me as well. |
Thanks for the pointer @larsoner , this is definitely worthwhile ! I will give it a shot |
|
AFAICT the test failures are not obviously related: the failures seem to be related to path formatting on windows for the validator. @stefmolin @mattgebert any idea what might be going on here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT the test failures are not obviously related: the failures seem to be related to path formatting on windows for the validator. @stefmolin @mattgebert any idea what might be going on here?
This is definitely related to Windows paths, but it is failing here and not in main, which makes it seem like it is related to these changes (or a dependency change in the action runner).
As far as whether this will affect the AST logic and the hook, I haven't tested, but I don't think it will have any effect and making the sphinx dependency is definitely a good idea.
| @@ -0,0 +1,15 @@ | |||
| # Configure test collection to skip doctests for modules that depend on sphinx | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is necessary. What about including numpydoc[default] in our test dependencies and then we can test everything?
Alternatively, what about marking the tests that require sphinx as expected fails when sphinx isn't available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about including numpydoc[default] in our test dependencies and then we can test everything?
This would work for CI but wouldn't work out-of-the-box for a development environment. I personally think there's value in being able to run only the tests (including doctests) for the non-sphinxy bits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth using nox if we want that because now we are talking about needing to use two different virtual environments to run the tests like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm -1 on more tooling for testing/environment management. All this change does is introduce importorskip-like behavior for doctests as well to ensure that the "full" test suite (i.e. including doctests) runs the correct tests whether or not sphinx is installed.
Co-authored-by: Stefanie Molin <24376333+stefmolin@users.noreply.github.com>
* replace path separators on windows * Add drive to path for windows
Good observation - I opened #804 to test whether it was something in the runner environment - everything there runs as expected so it's likely not that.
Indeed that seems to be the case, but I still can't tell how. After looking at this a bit, there are two things I'm confused by:
Normally I'd address these questions by |
|
I'm also at a loss for why these changes would cause the tests to suddenly fail on Windows. The only thing I can think of is that the proposed changes don't touch our GitHub Actions, meaning that we are no longer testing any of the sphinx behavior – it's not installed. Maybe sphinx comes with something that changes how the paths behave on Windows? I don't have access to a Windows machine either. |
Co-authored-by: Stefanie Molin <24376333+stefmolin@users.noreply.github.com>
I believe I've figured it out: the issue is the I suspect the reason they started being run with this PR was the introduction of Anyways - I will port the test fixes in 7708ca0 over to #653 to fix all of that separately so we can remain focused on the sphinx-dep changes in this PR. Footnotes
|
| @@ -1,8 +1,11 @@ | |||
| import pytest | |||
|
|
|||
| pytest.importorskip("sphinx") | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about including the reason for all of these calls?
|
@rossbar Sorry I haven't had time recently to get on top of this, and am just having a quick look at this now! I noticed the hook tests never being called (see #622 (comment) ) a while ago when I was writing #622 I did a few things to rectify this, not sure if this is the same as what you've now done in #653. You can check the file changes.
#622 is also now ready to integrate btw since we move to Python 3.10+. |
See #648 for motivation.
This is an attempt at refactoring numpydoc so that the bits that don't depend on sphinx, primarily
NumpyDocString, can be used by downstream libraries without pulling in a transitive sphinx dependency.Fortunately numpydoc was already organized in such a way that this was fairly straightforward:
docscrape.pyis the important module (whereNumpyDocStringis defined) and already doesn't depend on sphinx. Therefore I went about trying to remove any remaining transitive dependencies and reorganizing the test suite.A quick commit-by-commit summary:
default(matching the pattern used by NetworkX). Happy to reorganize this according to whomever's preference!setupfunction (used in registering the extension with the sphinx-build pipeline) on import if sphinx is installed.test_docscrape.pyandtest_docscrape_sphinx.py. The former primarily captures tests of theNumpyDocStringclass, whereas the latter coversSphinxDocStringand anything else that depends on sphinx. The diff is nasty, but no tests were added/removed - this commit only changes where tests live (and addspytest.importorskip("sphinx")to the latter).test_full.pyrequire sphinx, sopytest.importorskipthat test module_clean_text_signaturedefined innumpydoc.pywhich didn't depend on sphinx. All other functionality in that module is related to the sphinx extension (docstring mangling, etc.). Therefore, I chose to split this one function out into it's own private module with separate testing. That way I could safelypytest.importorskiptest_numpydoc.pywithout losing any coverage.NumpyDocStringinrender_objectinstead ofSphinxDocString, then the cli is (I think) completely sphinx-free. I'm not sure what implications this has for the cli-based validation workflows - I'm hoping @stefmolin or someone more familiar with this piece can weigh in!I'm opening as a draft PR to get initial feedback on the idea and review from the cli/hooks folks. I have the following list of todo's before I move from draft->reviwable status:
scikit-learn's test suite works as expected with this PR