From 7bc673b8f212f78768b1f153cb0ec5a3e9a80e4a Mon Sep 17 00:00:00 2001 From: patrick96 Date: Thu, 20 Apr 2023 01:19:22 +0200 Subject: [PATCH] fix(doc): %s in extlinks caption before sphinx 4.0 There is no way to support extlinks with a custom caption in both sphinx < 4 and >= 4 at the same time without implementing different behavior per version. --- doc/conf.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 255061a9..c1f369c1 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -36,6 +36,9 @@ def get_version(root_path): raise RuntimeError("No version found in {}".format(path)) + +sphinx_version = packaging.version.parse(sphinx.__version__) + # -- Project information ----------------------------------------------------- @@ -117,10 +120,18 @@ highlight_language = 'none' smartquotes = False # Quickly link to issues or PRs using :issue:`...` or :pull:`...` -extlinks = { - "issue": ("https://github.com/polybar/polybar/issues/%s", "#"), - "pull": ("https://github.com/polybar/polybar/pull/%s", "PR #"), -} +if sphinx_version >= packaging.version.parse("4.0.0"): + extlinks = { + "issue": ("https://github.com/polybar/polybar/issues/%s", "#%s"), + "pull": ("https://github.com/polybar/polybar/pull/%s", "PR #%s"), + } +else: + # Versions before 4.0 (e.g. on readthedocs) do not support %s in the + # caption and simply append the value + extlinks = { + "issue": ("https://github.com/polybar/polybar/issues/%s", "#"), + "pull": ("https://github.com/polybar/polybar/pull/%s", "PR #"), + } extlinks_detect_hardcoded_links = True @@ -302,7 +313,7 @@ def setup(app): # built from master, documentation built for proper releases should not even # mention unreleased changes. Because of that it's not that important that this # is added to local builds. -if packaging.version.parse(sphinx.__version__) >= packaging.version.parse("1.8.5"): +if sphinx_version >= packaging.version.parse("1.8.5"): from typing import List from docutils.nodes import Node