Skip to content

Commit c73628d

Browse files
committed
Accept a version tuple in app.require_sphinx()
1 parent ae20669 commit c73628d

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Features added
2424

2525
* #11415: Add a checksum to JavaScript and CSS asset URIs included within
2626
generated HTML, using the CRC32 algorithm.
27+
* :meth:`~sphinx.application.Sphinx.require_sphinx` now allows the version
28+
requirement to be specified as ``(major, minor)``.
2729

2830
Bugs fixed
2931
----------

sphinx/application.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,18 +401,26 @@ def setup_extension(self, extname: str) -> None:
401401
logger.debug('[app] setting up extension: %r', extname)
402402
self.registry.load_extension(self, extname)
403403

404-
def require_sphinx(self, version: str) -> None:
404+
@staticmethod
405+
def require_sphinx(version: tuple[int, int] | str) -> None:
405406
"""Check the Sphinx version if requested.
406407
407408
Compare *version* with the version of the running Sphinx, and abort the
408409
build when it is too old.
409410
410-
:param version: The required version in the form of ``major.minor``.
411+
:param version: The required version in the form of ``major.minor`` or
412+
``(major, minor)``.
411413
412414
.. versionadded:: 1.0
415+
.. versionchanged:: 7.1
416+
Type of *version* now allows ``(major, minor)`` form.
413417
"""
414-
if version > sphinx.__display_version__[:3]:
415-
raise VersionRequirementError(version)
418+
if isinstance(version, tuple):
419+
major, minor = version
420+
else:
421+
major, minor = map(int, version.split('.')[:2])
422+
if (major, minor) > sphinx.version_info[:2]:
423+
raise VersionRequirementError(f'{major}.{minor}')
416424

417425
# event interface
418426
def connect(self, event: str, callback: Callable, priority: int = 500) -> int:

0 commit comments

Comments
 (0)