diff options
author | Adam Turner <9087854+aa-turner@users.noreply.github.com> | 2023-05-11 13:34:09 +0100 |
---|---|---|
committer | Adam Turner <9087854+aa-turner@users.noreply.github.com> | 2023-05-11 13:50:45 +0100 |
commit | c73628dfcac844f89198ccd805e8e35609b37636 (patch) | |
tree | 37662b0d765682efc5862d09151c1612f818b17e | |
parent | ae206694e68bea074aca633ea0d32e9ed882a95f (diff) | |
download | sphinx-git-c73628dfcac844f89198ccd805e8e35609b37636.tar.gz |
Accept a version tuple in ``app.require_sphinx()``
-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: |