Skip to content

Commit

Permalink
Accept a version tuple in app.require_sphinx()
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed May 11, 2023
1 parent ae20669 commit c73628d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -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
----------
Expand Down
16 changes: 12 additions & 4 deletions sphinx/application.py
Expand Up @@ -401,18 +401,26 @@ def setup_extension(self, extname: str) -> None:
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:
Expand Down

0 comments on commit c73628d

Please sign in to comment.