Skip to content

DOC/ENH: distinguish missing packages from installed ones with incompatible versions in docs/conf.py - #20414

Merged
neutrinoceros merged 1 commit into
astropy:mainfrom
neutrinoceros:enh/improve-configuration-errors
Sep 17, 2026
Merged

neutrinoceros merged 1 commit into
astropy:mainfrom
neutrinoceros:enh/improve-configuration-errors

Conversation

@neutrinoceros

Copy link
Copy Markdown
Contributor

Description

Triggered by this discussion, I asked myself how to better leverage packaging APIs in this for loop, and went down a rabbit hole. I didn't intended to open a PR at first, as I was doing it for fun/training (I won't bill the time I spent there), but I ended up with one real (albeit minor) improvement: now, packages that are found but incompatible with requirements are explicitly reported as such, instead of being reported as plainly missing.
This also includes the small change that triggered the discussion about canonicalizing package names.

AI Disclosure

None

  • I certify that I am human and that I take full responsibility for this pull request including all interactions with reviewers.

Merge method

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

Comment thread docs/conf.py
required=req.specifier,
)
)
continue

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is an actual bugfix I found while self-reviewing the PR: not having a continue in the original code could lead to a NameError if the first package tried wasn't found (version would be unbound), and to duplicate lines if a package wasn't found and its version requirement was not satisfied by the version of the latest found package...

@neutrinoceros
neutrinoceros marked this pull request as ready for review September 16, 2026 08:06
@nstarman

Copy link
Copy Markdown
Member

It looks good. But is there any way to test this? Testing conf.py files within the test env they set up is kinda hard...

@neutrinoceros
neutrinoceros force-pushed the enh/improve-configuration-errors branch from 3e061f6 to 50054d9 Compare September 16, 2026 13:03
@neutrinoceros

Copy link
Copy Markdown
Contributor Author

It's actually pretty trivial to test locally, just install sphinx via pip within a fresh env then run docs/conf.py as if a script.
This is what I get

The following packages could not be found and are required to build the documentation:
    * sphinx <9,>=8.2.0 (found incompatible version 9.1.0)
    * dask >=2024.8.0
    * sphinx-design >=0.6.1
    * pytest >=8.0.0
    * sphinx-astropy >=1.11
    * fsspec >=2023.4.0
    * sphinxcontrib-globalsubs >=0.1.1
    * matplotlib !=3.9.0
    * sphinx-changelog >=1.4.0
Please install the "docs" optional dependencies.

@neutrinoceros
neutrinoceros force-pushed the enh/improve-configuration-errors branch from 50054d9 to 5681655 Compare September 16, 2026 13:37
@astrofrog

Copy link
Copy Markdown
Member

This is getting a bit complex and would also be useful to have for coordinated packages - I'm curious if you have any thoughts about how we could potentially factor this out? For instance, we could always have a helper function in sphinx_astropy then have:

try:
    from sphinx_astropy import assert_dependencies
except ImportError:
    <error about requiring recent sphinx_astropy>

assert_dependencies('astropy', extras='docs')

Yes it's still not a single line, but it would save quite a bit of code over a number of repos.

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

I don't know if it'd fit sphinx-astropy's scope, but I'd be happy to move the correct version of it there if you think it makes sense.

@nstarman nstarman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.
I'd also be happy generalizing this tool out of Astropy.
.... I'd love to do that for more of Astropy's non-core functionality!

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

@astrofrog to be clear, should be proceed with this PR as is and then upstream the function ?

@astrofrog

Copy link
Copy Markdown
Member

Yes let's not hold this up

@neutrinoceros
neutrinoceros merged commit d4a3a7f into astropy:main Sep 17, 2026
37 of 38 checks passed
@neutrinoceros
neutrinoceros deleted the enh/improve-configuration-errors branch September 17, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants