Skip to content

Commit

Permalink
Fix sphinx-doc#9708: needs_extension failed to check double-digit ver…
Browse files Browse the repository at this point in the history
…sion correctly
  • Loading branch information
tk0miya committed Oct 6, 2021
1 parent 9922923 commit 332ae3b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -42,6 +42,7 @@ Bugs fixed
* #9649: HTML search: when objects have the same name but in different domains,
return all of them as result instead of just one.
* #9678: linkcheck: file extension was shown twice in warnings
* #9708: needs_extension failed to check double-digit version correctly

Testing
--------
Expand Down
15 changes: 14 additions & 1 deletion sphinx/extension.py
Expand Up @@ -10,6 +10,8 @@

from typing import TYPE_CHECKING, Any, Dict

from packaging.version import InvalidVersion, Version

from sphinx.config import Config
from sphinx.errors import VersionRequirementError
from sphinx.locale import __
Expand Down Expand Up @@ -51,7 +53,18 @@ def verify_needs_extensions(app: "Sphinx", config: Config) -> None:
'but it is not loaded.'), extname)
continue

if extension.version == 'unknown version' or reqversion > extension.version:
fulfilled = True
if extension.version == 'unknown version':
fulfilled = False
else:
try:
if Version(reqversion) > Version(extension.version):
fulfilled = False
except InvalidVersion:
if reqversion > extension.version:
fulfilled = False

if not fulfilled:
raise VersionRequirementError(__('This project needs the extension %s at least in '
'version %s and therefore cannot be built with '
'the loaded version (%s).') %
Expand Down

0 comments on commit 332ae3b

Please sign in to comment.