diff options
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | sphinx/application.py | 16 |
2 files changed, 14 insertions, 4 deletions
@@ -24,6 +24,8 @@ Features added * #11415: Add a checksum to JavaScript and CSS asset URIs included within generated HTML, using the CRC32 algorithm. +* :meth:`~sphinx.application.Sphinx.require_sphinx` now allows the version + requirement to be specified as ``(major, minor)``. Bugs fixed ---------- diff --git a/sphinx/application.py b/sphinx/application.py index 67b322693..495e90570 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -401,18 +401,26 @@ class Sphinx: logger.debug('[app] setting up extension: %r', extname) self.registry.load_extension(self, extname) - def require_sphinx(self, version: str) -> None: + @staticmethod + def require_sphinx(version: tuple[int, int] | str) -> None: """Check the Sphinx version if requested. Compare *version* with the version of the running Sphinx, and abort the build when it is too old. - :param version: The required version in the form of ``major.minor``. + :param version: The required version in the form of ``major.minor`` or + ``(major, minor)``. .. versionadded:: 1.0 + .. versionchanged:: 7.1 + Type of *version* now allows ``(major, minor)`` form. """ - if version > sphinx.__display_version__[:3]: - raise VersionRequirementError(version) + if isinstance(version, tuple): + major, minor = version + else: + major, minor = map(int, version.split('.')[:2]) + if (major, minor) > sphinx.version_info[:2]: + raise VersionRequirementError(f'{major}.{minor}') # event interface def connect(self, event: str, callback: Callable, priority: int = 500) -> int: |
