Fix needs_extensions version comparison to use packaging.Version#14376
Closed
piyushhhxyz wants to merge 2 commits intosphinx-doc:masterfrom
Closed
Fix needs_extensions version comparison to use packaging.Version#14376piyushhhxyz wants to merge 2 commits intosphinx-doc:masterfrom
piyushhhxyz wants to merge 2 commits intosphinx-doc:masterfrom
Conversation
The needs_extensions check was comparing version strings lexicographically, which caused incorrect results for versions with components >= 10. For example, '0.6.0' > '0.10.0' as strings, but 0.6.0 < 0.10.0 as versions. This fix uses packaging.version.Version for proper semantic version comparison, which is already a dependency of Sphinx.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix the
needs_extensionscheck to compare versions usingpackaging.version.Versioninstead of string comparison.Problem
The
needs_extensionscheck compared version strings lexicographically, which produced incorrect results for versions with components >= 10. For example:'0.6.0' > '0.10.0'evaluates toTrue(wrong)Version('0.6.0') > Version('0.10.0')evaluates toFalse(correct)This caused extensions like sphinx-gallery 0.10.0 to be rejected when 0.6.0 was the minimum required version.
Fix
Replace the string comparison
reqversion > extension.versionwithVersion(reqversion) > Version(extension.version)usingpackaging.version.Version, which is already a dependency of Sphinx.Files Changed
sphinx/extension.py-- Usepackaging.version.Versionfor proper semantic version comparisontests/test_extension.py-- New test file with regression tests for the version comparison fixTesting
Unit tests (new)
Manual verification
Existing tests
Ran
tests/test_config.py-- all pre-existing failures are unrelated (sphinxcontrib.applehelp version mismatch with this old Sphinx version). Verified by running the same tests on the base commit without changes.