Skip to content

Comments

swev-id: sphinx-doc__sphinx-9711 fix needs_extensions version check#94

Open
casey-brooks wants to merge 1 commit intosphinx-doc__sphinx-9711from
noa/issue-91
Open

swev-id: sphinx-doc__sphinx-9711 fix needs_extensions version check#94
casey-brooks wants to merge 1 commit intosphinx-doc__sphinx-9711from
noa/issue-91

Conversation

@casey-brooks
Copy link

Summary

Testing

  • pytest tests/test_extension_needs.py -q
  • flake8 sphinx/extension.py tests/test_extension_needs.py
  • PYTHONPATH=/workspace/sphinx/stubs:/workspace/sphinx sphinx-build -b html -T -v . _build/html

Reproduction

  1. Create a minimal project with conf.py:
    extensions = ['sphinx_gallery.gen_gallery']
    needs_extensions = {'sphinx_gallery.gen_gallery': '0.6.0'}
    master_doc = 'index'
    project = 'Needs Extension Repro'
    and an index.rst stub.
  2. python3 -m venv .venv && . .venv/bin/activate
  3. pip install -e . sphinx-gallery==0.10.0
  4. Add a sitecustomize.py (and put its directory on PYTHONPATH) containing:
    import sphinx
    sphinx.__display_version__ = '5.0.0'
    This satisfies the pip-installed sphinxcontrib.* packages that guard on require_sphinx('5.0') while the branch still reports 4.3.0.
  5. Place a placeholder examples/README.txt so sphinx-gallery gets past its README check.
  6. Run PYTHONPATH=/path/to/sitecustomize:/workspace/sphinx sphinx-build -b html -T -v . _build/html.

Observed failure (before fix)

Running Sphinx v5.0.0

Traceback (most recent call last):
  File "/workspace/sphinx/sphinx/cmd/build.py", line 276, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/sphinx/sphinx/application.py", line 261, in __init__
    self.events.emit('config-inited', self.config)
  File "/workspace/sphinx/sphinx/events.py", line 101, in emit
    results.append(listener.handler(self.app, *args))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/sphinx/sphinx/extension.py", line 55, in verify_needs_extensions
    raise VersionRequirementError(__('This project needs the extension %s at least in '
sphinx.errors.VersionRequirementError: This project needs the extension sphinx_gallery.gen_gallery at least in version 0.6.0 and therefore cannot be built with the loaded version (0.10.0).

Sphinx version error:
This project needs the extension sphinx_gallery.gen_gallery at least in version 0.6.0 and therefore cannot be built with the loaded version (0.10.0).

After fix

  • PYTHONPATH=/path/to/sitecustomize:/workspace/sphinx sphinx-build -b html -T -v . _build/html
    build succeeded.

@casey-brooks casey-brooks requested a review from a team December 26, 2025 21:11
@casey-brooks
Copy link
Author

Test & Lint

  • pytest tests/test_extension_needs.py -q (5 passed)
  • flake8 sphinx/extension.py tests/test_extension_needs.py (no issues)

Copy link

@noa-lucent noa-lucent 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 to me. Thanks for adding robust version comparisons and thorough tests covering the new behavior.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants