Skip to content

Commit 448af4d

Browse files
committed
Upgrade pygments to 2.17.2
1 parent f2c07ee commit 448af4d

File tree

16 files changed

+203
-84
lines changed

16 files changed

+203
-84
lines changed

news/pygments.vendor.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade pygments to 2.17.2

src/pip/_vendor/pygments/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"""
2727
from io import StringIO, BytesIO
2828

29-
__version__ = '2.15.1'
29+
__version__ = '2.17.2'
3030
__docformat__ = 'restructuredtext'
3131

3232
__all__ = ['lex', 'format', 'highlight']

src/pip/_vendor/pygments/formatters/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def get_formatter_for_filename(fn, **options):
131131
if name not in _formatter_cache:
132132
_load_formatters(modname)
133133
return _formatter_cache[name](**options)
134-
for cls in find_plugin_formatters():
134+
for _name, cls in find_plugin_formatters():
135135
for filename in cls.filenames:
136136
if _fn_matches(fn, filename):
137137
return cls(**options)

src/pip/_vendor/pygments/formatters/_mapping.py

100644100755
File mode changed.

src/pip/_vendor/pygments/formatters/html.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ class ``"special"`` (default: ``0``).
323323
If set to the path of a ctags file, wrap names in anchor tags that
324324
link to their definitions. `lineanchors` should be used, and the
325325
tags file should specify line numbers (see the `-n` option to ctags).
326+
The tags file is assumed to be encoded in UTF-8.
326327
327328
.. versionadded:: 1.6
328329
@@ -908,7 +909,7 @@ def _format_lines(self, tokensource):
908909
def _lookup_ctag(self, token):
909910
entry = ctags.TagEntry()
910911
if self._ctags.find(entry, token.encode(), 0):
911-
return entry['file'], entry['lineNumber']
912+
return entry['file'].decode(), entry['lineNumber']
912913
else:
913914
return None, None
914915

src/pip/_vendor/pygments/formatters/img.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
88
:license: BSD, see LICENSE for details.
99
"""
10-
1110
import os
1211
import sys
1312

@@ -68,6 +67,15 @@ def __init__(self, font_name, font_size=14):
6867
self.font_size = font_size
6968
self.fonts = {}
7069
self.encoding = None
70+
self.variable = False
71+
if hasattr(font_name, 'read') or os.path.isfile(font_name):
72+
font = ImageFont.truetype(font_name, self.font_size)
73+
self.variable = True
74+
for style in STYLES:
75+
self.fonts[style] = font
76+
77+
return
78+
7179
if sys.platform.startswith('win'):
7280
if not font_name:
7381
self.font_name = DEFAULT_FONT_NAME_WIN
@@ -223,14 +231,43 @@ def get_font(self, bold, oblique):
223231
Get the font based on bold and italic flags.
224232
"""
225233
if bold and oblique:
234+
if self.variable:
235+
return self.get_style('BOLDITALIC')
236+
226237
return self.fonts['BOLDITALIC']
227238
elif bold:
239+
if self.variable:
240+
return self.get_style('BOLD')
241+
228242
return self.fonts['BOLD']
229243
elif oblique:
244+
if self.variable:
245+
return self.get_style('ITALIC')
246+
230247
return self.fonts['ITALIC']
231248
else:
249+
if self.variable:
250+
return self.get_style('NORMAL')
251+
232252
return self.fonts['NORMAL']
233253

254+
def get_style(self, style):
255+
"""
256+
Get the specified style of the font if it is a variable font.
257+
If not found, return the normal font.
258+
"""
259+
font = self.fonts[style]
260+
for style_name in STYLES[style]:
261+
try:
262+
font.set_variation_by_name(style_name)
263+
return font
264+
except ValueError:
265+
pass
266+
except OSError:
267+
return font
268+
269+
return font
270+
234271

235272
class ImageFormatter(Formatter):
236273
"""
@@ -258,6 +295,8 @@ class ImageFormatter(Formatter):
258295
The font name to be used as the base font from which others, such as
259296
bold and italic fonts will be generated. This really should be a
260297
monospace font to look sane.
298+
If a filename or a file-like object is specified, the user must
299+
provide different styles of the font.
261300
262301
Default: "Courier New" on Windows, "Menlo" on Mac OS, and
263302
"DejaVu Sans Mono" on \\*nix

src/pip/_vendor/pygments/lexer.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ class Lexer(metaclass=LexerMeta):
7272
.. autoattribute:: url
7373
:no-value:
7474
75+
Lexers included in Pygments may have additional attributes:
76+
77+
.. autoattribute:: _example
78+
:no-value:
79+
7580
You can pass options to the constructor. The basic options recognized
7681
by all lexers and processed by the base `Lexer` class are:
7782
@@ -128,6 +133,10 @@ class Lexer(metaclass=LexerMeta):
128133
#: documentation.
129134
url = None
130135

136+
#: Example file name. Relative to the ``tests/examplefiles`` directory.
137+
#: This is used by the documentation generator to show an example.
138+
_example = None
139+
131140
def __init__(self, **options):
132141
"""
133142
This constructor takes arbitrary options as keyword arguments.
@@ -190,20 +199,9 @@ def analyse_text(text):
190199
it's the same as if the return values was ``0.0``.
191200
"""
192201

193-
def get_tokens(self, text, unfiltered=False):
194-
"""
195-
This method is the basic interface of a lexer. It is called by
196-
the `highlight()` function. It must process the text and return an
197-
iterable of ``(tokentype, value)`` pairs from `text`.
202+
def _preprocess_lexer_input(self, text):
203+
"""Apply preprocessing such as decoding the input, removing BOM and normalizing newlines."""
198204

199-
Normally, you don't need to override this method. The default
200-
implementation processes the options recognized by all lexers
201-
(`stripnl`, `stripall` and so on), and then yields all tokens
202-
from `get_tokens_unprocessed()`, with the ``index`` dropped.
203-
204-
If `unfiltered` is set to `True`, the filtering mechanism is
205-
bypassed even if filters are defined.
206-
"""
207205
if not isinstance(text, str):
208206
if self.encoding == 'guess':
209207
text, _ = guess_decode(text)
@@ -246,6 +244,24 @@ def get_tokens(self, text, unfiltered=False):
246244
if self.ensurenl and not text.endswith('\n'):
247245
text += '\n'
248246

247+
return text
248+
249+
def get_tokens(self, text, unfiltered=False):
250+
"""
251+
This method is the basic interface of a lexer. It is called by
252+
the `highlight()` function. It must process the text and return an
253+
iterable of ``(tokentype, value)`` pairs from `text`.
254+
255+
Normally, you don't need to override this method. The default
256+
implementation processes the options recognized by all lexers
257+
(`stripnl`, `stripall` and so on), and then yields all tokens
258+
from `get_tokens_unprocessed()`, with the ``index`` dropped.
259+
260+
If `unfiltered` is set to `True`, the filtering mechanism is
261+
bypassed even if filters are defined.
262+
"""
263+
text = self._preprocess_lexer_input(text)
264+
249265
def streamer():
250266
for _, t, v in self.get_tokens_unprocessed(text):
251267
yield t, v

src/pip/_vendor/pygments/lexers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
COMPAT = {
2323
'Python3Lexer': 'PythonLexer',
2424
'Python3TracebackLexer': 'PythonTracebackLexer',
25+
'LeanLexer': 'Lean3Lexer',
2526
}
2627

2728
__all__ = ['get_lexer_by_name', 'get_lexer_for_filename', 'find_lexer_class',

0 commit comments

Comments
 (0)