Merge branch '4.x' into class-option-for-code-directive

This commit is contained in:
Takeshi KOMIYA
2021-10-09 16:10:04 +09:00
committed by GitHub
3 changed files with 46 additions and 1 deletions

View File

@@ -63,6 +63,7 @@ Bugs fixed
* #9678: linkcheck: file extension was shown twice in warnings
* #9697: py domain: An index entry with parens was registered for ``py:method``
directive with ``:property:`` option
* #9708: needs_extension failed to check double-digit version correctly
* Fix bug ``.. code::`` recognising ``:classes:`` option instead of ``:class:``
option. The new behaviour is to only accept the ``:class:`` option.

View File

@@ -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 __
@@ -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).') %

31
tests/test_extension.py Normal file
View File

@@ -0,0 +1,31 @@
"""
test_extension
~~~~~~~~~~~~~~
Test sphinx.extesion module.
:copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import pytest
from sphinx.errors import VersionRequirementError
from sphinx.extension import Extension, verify_needs_extensions
def test_needs_extensions(app):
# empty needs_extensions
assert app.config.needs_extensions == {}
verify_needs_extensions(app, app.config)
# needs_extensions fulfilled
app.config.needs_extensions = {'test.extension': '3.9'}
app.extensions['test.extension'] = Extension('test.extension', 'test.extension', version='3.10')
verify_needs_extensions(app, app.config)
# needs_extensions not fulfilled
app.config.needs_extensions = {'test.extension': '3.11'}
app.extensions['test.extension'] = Extension('test.extension', 'test.extension', version='3.10')
with pytest.raises(VersionRequirementError):
verify_needs_extensions(app, app.config)