Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
rossbar wants to merge14 commits intonumpy:main
base:main
Choose a base branch
Loading
fromrossbar:soft-sphinx

Conversation

@rossbar
Copy link
Contributor

@rossbarrossbar commentedOct 15, 2025
edited
Loading

See#648 for motivation.

This is an attempt at refactoring numpydoc so that the bits that don't depend on sphinx, primarilyNumpyDocString, can be used by downstream librarieswithout pulling in a transitive sphinx dependency.

Fortunately numpydoc was already organized in such a way that this was fairly straightforward:docscrape.py is the important module (whereNumpyDocString is 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:

  • 8a51c0a : moves sphinx from a hard dependency to a separate dependency group that I arbitrarily calleddefault (matching the pattern used by NetworkX). Happy to reorganize this according to whomever's preference!
  • fb070f9 : Only attempt to construct thesetup function (used in registering the extension with the sphinx-build pipeline) on import if sphinx is installed.
  • 03c7593 throughe61875f : Split uptest_docscrape.py into two test files in a way that preserve the commit history perthis recipe.
  • 3c4ffaf : Modifytest_docscrape.py andtest_docscrape_sphinx.py so that the former primarily captures tests of theNumpyDocString class, whereas the latter coversSphinxDocString and anything else that depends on sphinx. The diff is nasty, butno tests were added/removed - this commit only changes where tests live (and addspytest.importorskip("sphinx") to the latter).
  • 4e38009 : some minor cleanup related toeffcf01 - import text for test cases rather than re-defining strings
  • cef7fd9 : All tests intest_full.py require sphinx, sopytest.importorskip that test module
  • f8f2310 : AFAICT there was onlyone private function_clean_text_signature defined innumpydoc.py which 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.py without losing any coverage.
  • c3f1676 : The numpydoc test suite runs doctests by default, which causes problems at test collection time when some modules which depend on sphinx are imported. This commit adds a dynamic config for pytest that skips doctest collection for these modules when sphinx is not present. Again, pattern borrowed from NetworkX.
  • da65208 : One idea for breaking the single dependence on sphinx that I noticed for the cli/hooks workflows. If we instead useNumpyDocString inrender_object instead 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:

  • Try building scipy with numpydoc's NumpyDocString instead ofscipy's vendored version to ensure everything works and scipy's build recipe remains unaffected
  • Try with napari: seeNumpydoc dependency napari/napari#8322 for details
  • Verifyscikit-learn 's test suite works as expected with this PR
  • Add another CI workflow to run the tests in an environment where sphinx is not installed
  • Build the docs of major scientific Python libraries that depend on numpydoc (numpy, scipy, matplotlib, the scikits, networkx) to verify that all doc build recipes are unaffected by this change.

@larsoner
Copy link
Collaborator

Thanks for tackling this! Just one quick idea comes to mind for:

effcf01 : Split the docscrape tests into two test modules...

Have you consideredsplitting while keeping blame? I did this recently inmne-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.

@rossbar
Copy link
ContributorAuthor

Have you considered splitting while keeping blame?

Thanks for the pointer@larsoner , this is definitely worthwhile ! I will give it a shot

@rossbar
Copy link
ContributorAuthor

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?

Copy link
Contributor

@stefmolinstefmolin left a comment
edited
Loading

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 soft is definitely a good idea.

@rossbar
Copy link
ContributorAuthor

(or a dependency change in the action runner).

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.

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

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:

  1. How did these changes affect these test results (having re-looked at everything there doesn't seem to be any direct connection to the changes and thehooks/test_ tests).
  2. How did these tests ever pass on windows in the first place? The problems that were tripping it up do indeed seem to be entirely related to windows path rendering... why wasn't this a problem before? FWIW7708ca0 "fixes" the issue by robust-ifying the tests themselves to different platforms. That doesn't answer either of these two questions though.

Normally I'd address these questions bybisect-ing to ID which specific commit caused the issue, but I don't have ready access to a windows machine.

@stefmolin
Copy link
Contributor

stefmolin commentedOct 18, 2025
edited
Loading

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.

@rossbar
Copy link
ContributorAuthor

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.

I believe I've figured it out: the issue is thetest/hooks test werenever being run in CI. See#653 , specificallye728f61 and the associated action logs, for proof. Basically the tests are run with the--pyargs flag which runs tests from the installed package, but thetests/hooks tests were not included in the package, so they were never run.

I suspect the reason they started being run with this PR was the introduction ofconftest.py, which IIRC can subtly influence test collection1.

Anyways - I will port the test fixes in7708ca0 over to#653 to fix all of that separately so we can remain focused on the sphinx-dep changes in this PR.

Footnotes

  1. I'm not 100% sure here, but that's where I'd start investigating if I really wanted to chase down exactly what's happening.

mattgebert reacted with thumbs up emojimattgebert reacted with eyes emoji

@@ -1,8 +1,11 @@
importpytest

pytest.importorskip("sphinx")
Copy link
Contributor

Choose a reason for hiding this comment

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

What about including thereason for all of these calls?

@mattgebert
Copy link
Contributor

@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 thefile changes.

  • I had to add an explicit call in the CI for thenumpydoc/tests/hooks directory to ensure it runs.
  • The other thing in the hook tests is the use of delimeters that don't match the Windows filepath. Added aos.replace("/", os.sep)

#622 is also now ready to integrate btw since we move to Python 3.10+.

All other functions defined in numpydoc.py module depend on sphinxand therefore can be skipped for testing purposes when sphinx isnot 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 anddocscrape_sphinx.py modules during test collection as theydepend on sphinx.
The only thing here that depends on sphinx is thefn which uses docscrape_sphinx's version of get_doc_object.If we switch to docscrape's version of get_doc_object, then theresulting rendering is derived from NumpyDocString instead ofSphinxDocString.Alternatively - this could be left as-is and the test_render testsin  could be importorskipped.
@rossbar
Copy link
ContributorAuthor

Now that#653 is in and testing gremlins are all chased down I intend to keep pushing this!

The first order of business was taking up@larsoner 's excellent suggestion about preserving history in the newtest_docscrape_sphinx.py file. Ifollowed the linked procedure and indeed was able to verify withgit blame that the history is preserved as expected.

Unfortunately the "split the files" commit(s) are relatively early in the stack by necessity, so the only way I could get these changes up was with a rebase+force-push, which screws up the linked commit summary in the original post. I'll go ahead and update that to reflect the new hashes.

The next order of business is to work throughthe checklist... I will share results for each task once I've had a chance to work through it.

larsoner reacted with thumbs up emojistefanv reacted with hooray emoji

@stefanv
Copy link
Contributor

This is awesome,@rossbar! I useNumpyDocString for the early prototype myst API generator, and it would be great not to have to bring in Sphinx. Same in CI etc.

rossbar reacted with hooray emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stefmolinstefmolinstefmolin left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@rossbar@larsoner@stefmolin@mattgebert@stefanv

[8]ページ先頭

©2009-2025 Movatter.jp