Skip to content

Commit 42a2aea

Browse files
authored
Merge pull request #28093 from rjmccall/monkeyless-sphinx
Tell Sphinx about the Swift lexers without monkey-patching it
2 parents 10d62a1 + 17cc65c commit 42a2aea

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

docs/conf.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import sys
1515
from datetime import date
16+
from sphinx.highlighting import lexers
1617

1718
# If extensions (or modules to document with autodoc) are in another directory,
1819
# add these directories to sys.path here. If the directory is relative to the
@@ -263,9 +264,7 @@
263264
# Enable this if you want TODOs to show up in the generated documentation.
264265
todo_include_todos = True
265266

266-
#
267-
# Monkeypatch pygments so it will know about the Swift lexers
268-
#
267+
# -- Patch pygments so it will know about the Swift lexers ---------------
269268

270269
# Pull in the Swift lexers
271270
from os.path import abspath, dirname, join as join_paths # noqa (E402)
@@ -277,22 +276,6 @@
277276

278277
sys.path.pop(0)
279278

280-
# Monkeypatch pygments.lexers.get_lexer_by_name to return our lexers. The
281-
# ordering required to allow for monkeypatching causes the warning
282-
# "I100 Import statements are in the wrong order." when linting using
283-
# flake8-import-order. "noqa" is used to suppress this warning.
284-
from pygments.lexers import get_lexer_by_name as original_get_lexer_by_name # noqa (E402)
285-
286-
287-
def swift_get_lexer_by_name(_alias, *args, **kw):
288-
if _alias == 'swift':
289-
return swift_pygments_lexers.SwiftLexer()
290-
elif _alias == 'sil':
291-
return swift_pygments_lexers.SILLexer()
292-
elif _alias == 'swift-console':
293-
return swift_pygments_lexers.SwiftConsoleLexer()
294-
else:
295-
return original_get_lexer_by_name(_alias, *args, **kw)
296-
297-
import pygments.lexers # noqa (I100 Import statements are in the wrong order.)
298-
pygments.lexers.get_lexer_by_name = swift_get_lexer_by_name
279+
lexers['swift'] = swift_pygments_lexers.SwiftLexer()
280+
lexers['sil'] = swift_pygments_lexers.SILLexer()
281+
lexers['swift-console'] = swift_pygments_lexers.SwiftConsoleLexer()

0 commit comments

Comments
 (0)