Skip to content

Commit

Permalink
extlinks: Emit a warning if extlnks config does not contain '%s'
Browse files Browse the repository at this point in the history
To let users know the deprecation surely, use logger.warning instead
of RemovedInSphinxXXWarning since 5.0. It will cause a crash if users
use `-W` option on their CI.
  • Loading branch information
tk0miya committed May 3, 2021
1 parent 3027a2f commit 7682353
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@
autosummary_generate = False
todo_include_todos = True
extlinks = {'duref': ('http://docutils.sourceforge.net/docs/ref/rst/'
'restructuredtext.html#%s', ''),
'restructuredtext.html#%s', '%s'),
'durole': ('http://docutils.sourceforge.net/docs/ref/rst/'
'roles.html#%s', ''),
'roles.html#%s', '%s'),
'dudir': ('http://docutils.sourceforge.net/docs/ref/rst/'
'directives.html#%s', '')}
'directives.html#%s', '%s')}

man_pages = [
('contents', 'sphinx-all', 'Sphinx documentation generator system manual',
Expand Down
18 changes: 10 additions & 8 deletions sphinx/ext/extlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
:license: BSD, see LICENSE for details.
"""

import warnings
from typing import Any, Dict, List, Tuple

from docutils import nodes, utils
Expand All @@ -34,10 +33,13 @@

import sphinx
from sphinx.application import Sphinx
from sphinx.deprecation import RemovedInSphinx60Warning
from sphinx.locale import __
from sphinx.util import logging
from sphinx.util.nodes import split_explicit_title
from sphinx.util.typing import RoleFunction

logger = logging.getLogger(__name__)


def make_link_role(name: str, base_url: str, caption: str) -> RoleFunction:
# Check whether we have base_url and caption strings have an '%s' for
Expand All @@ -48,17 +50,17 @@ def make_link_role(name: str, base_url: str, caption: str) -> RoleFunction:
try:
base_url % 'dummy'
except (TypeError, ValueError):
warnings.warn('extlinks: Sphinx-6.0 will require base URL to '
'contain exactly one \'%s\' and all other \'%\' need '
'to be escaped as \'%%\'.', RemovedInSphinx60Warning)
logger.warn(__('extlinks: Sphinx-6.0 will require base URL to '
'contain exactly one \'%s\' and all other \'%\' need '
'to be escaped as \'%%\'.')) # RemovedInSphinx60Warning
base_url = base_url.replace('%', '%%') + '%s'
if caption is not None:
try:
caption % 'dummy'
except (TypeError, ValueError):
warnings.warn('extlinks: Sphinx-6.0 will require a caption string to '
'contain exactly one \'%s\' and all other \'%\' need '
'to be escaped as \'%%\'.', RemovedInSphinx60Warning)
logger.warning(__('extlinks: Sphinx-6.0 will require a caption string to '
'contain exactly one \'%s\' and all other \'%\' need '
'to be escaped as \'%%\'.')) # RemovedInSphinx60Warning
caption = caption.replace('%', '%%') + '%s'

def role(typ: str, rawtext: str, text: str, lineno: int,
Expand Down

0 comments on commit 7682353

Please sign in to comment.