Skip to content

Commit

Permalink
Merge pull request #11502 from pradyunsg/vendoring-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg authored Oct 14, 2022
2 parents 8375281 + 4ab07c7 commit eb90699
Show file tree
Hide file tree
Showing 23 changed files with 343 additions and 214 deletions.
1 change: 1 addition & 0 deletions news/pygments.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrade pygments to 2.13.0
1 change: 1 addition & 0 deletions news/typing_extensions.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrade typing_extensions to 4.4.0
1 change: 1 addition & 0 deletions news/urllib3.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrade urllib3 to 1.26.12
19 changes: 9 additions & 10 deletions src/pip/_vendor/pygments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"""
from io import StringIO, BytesIO

__version__ = '2.12.0'
__version__ = '2.13.0'
__docformat__ = 'restructuredtext'

__all__ = ['lex', 'format', 'highlight']
Expand All @@ -38,10 +38,10 @@ def lex(code, lexer):
"""
try:
return lexer.get_tokens(code)
except TypeError as err:
if (isinstance(err.args[0], str) and
('unbound method get_tokens' in err.args[0] or
'missing 1 required positional argument' in err.args[0])):
except TypeError:
# Heuristic to catch a common mistake.
from pip._vendor.pygments.lexer import RegexLexer
if isinstance(lexer, type) and issubclass(lexer, RegexLexer):
raise TypeError('lex() argument must be a lexer instance, '
'not a class')
raise
Expand All @@ -62,10 +62,10 @@ def format(tokens, formatter, outfile=None): # pylint: disable=redefined-builti
return realoutfile.getvalue()
else:
formatter.format(tokens, outfile)
except TypeError as err:
if (isinstance(err.args[0], str) and
('unbound method format' in err.args[0] or
'missing 1 required positional argument' in err.args[0])):
except TypeError:
# Heuristic to catch a common mistake.
from pip._vendor.pygments.formatter import Formatter
if isinstance(formatter, type) and issubclass(formatter, Formatter):
raise TypeError('format() argument must be a formatter instance, '
'not a class')
raise
Expand All @@ -80,4 +80,3 @@ def highlight(code, lexer, formatter, outfile=None):
it is returned as a string.
"""
return format(lex(code, lexer), formatter, outfile)

9 changes: 7 additions & 2 deletions src/pip/_vendor/pygments/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pip._vendor.pygments.formatters import get_all_formatters, get_formatter_by_name, \
load_formatter_from_file, get_formatter_for_filename, find_formatter_class
from pip._vendor.pygments.formatters.terminal import TerminalFormatter
from pip._vendor.pygments.formatters.terminal256 import Terminal256Formatter
from pip._vendor.pygments.formatters.terminal256 import Terminal256Formatter, TerminalTrueColorFormatter
from pip._vendor.pygments.filters import get_all_filters, find_filter_class
from pip._vendor.pygments.styles import get_all_styles, get_style_by_name

Expand Down Expand Up @@ -445,7 +445,9 @@ def is_only_option(opt):
return 1
else:
if not fmter:
if '256' in os.environ.get('TERM', ''):
if os.environ.get('COLORTERM','') in ('truecolor', '24bit'):
fmter = TerminalTrueColorFormatter(**parsed_opts)
elif '256' in os.environ.get('TERM', ''):
fmter = Terminal256Formatter(**parsed_opts)
else:
fmter = TerminalFormatter(**parsed_opts)
Expand Down Expand Up @@ -636,6 +638,9 @@ def main(args=sys.argv):

try:
return main_inner(parser, argns)
except BrokenPipeError:
# someone closed our stdout, e.g. by quitting a pager.
return 0
except Exception:
if argns.v:
print(file=sys.stderr)
Expand Down
7 changes: 5 additions & 2 deletions src/pip/_vendor/pygments/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ class CodeTagFilter(Filter):
`codetags` : list of strings
A list of strings that are flagged as code tags. The default is to
highlight ``XXX``, ``TODO``, ``BUG`` and ``NOTE``.
highlight ``XXX``, ``TODO``, ``FIXME``, ``BUG`` and ``NOTE``.
.. versionchanged:: 2.13
Now recognizes ``FIXME`` by default.
"""

def __init__(self, **options):
Filter.__init__(self, **options)
tags = get_list_opt(options, 'codetags',
['XXX', 'TODO', 'BUG', 'NOTE'])
['XXX', 'TODO', 'FIXME', 'BUG', 'NOTE'])
self.tag_re = re.compile(r'\b(%s)\b' % '|'.join([
re.escape(tag) for tag in tags if tag
]))
Expand Down
16 changes: 3 additions & 13 deletions src/pip/_vendor/pygments/formatters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import re
import sys
import types
import fnmatch
from fnmatch import fnmatch
from os.path import basename

from pip._vendor.pygments.formatters._mapping import FORMATTERS
Expand All @@ -22,16 +22,6 @@
'get_all_formatters', 'load_formatter_from_file'] + list(FORMATTERS)

_formatter_cache = {} # classes by name
_pattern_cache = {}


def _fn_matches(fn, glob):
"""Return whether the supplied file name fn matches pattern filename."""
if glob not in _pattern_cache:
pattern = _pattern_cache[glob] = re.compile(fnmatch.translate(glob))
return pattern.match(fn)
return _pattern_cache[glob].match(fn)


def _load_formatters(module_name):
"""Load a formatter (and all others in the module too)."""
Expand Down Expand Up @@ -122,13 +112,13 @@ def get_formatter_for_filename(fn, **options):
fn = basename(fn)
for modname, name, _, filenames, _ in FORMATTERS.values():
for filename in filenames:
if _fn_matches(fn, filename):
if fnmatch(fn, filename):
if name not in _formatter_cache:
_load_formatters(modname)
return _formatter_cache[name](**options)
for cls in find_plugin_formatters():
for filename in cls.filenames:
if _fn_matches(fn, filename):
if fnmatch(fn, filename):
return cls(**options)
raise ClassNotFound("no formatter found for file name %r" % fn)

Expand Down
67 changes: 3 additions & 64 deletions src/pip/_vendor/pygments/formatters/_mapping.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
"""
pygments.formatters._mapping
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Formatter mapping definitions. This file is generated by itself. Every time
you change something on a builtin formatter definition, run this script from
the formatters folder to update it.
Do not alter the FORMATTERS dictionary by hand.
:copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
# Automatically generated by scripts/gen_mapfiles.py.
# DO NOT EDIT BY HAND; run `make mapfiles` instead.

FORMATTERS = {
'BBCodeFormatter': ('pygments.formatters.bbcode', 'BBCode', ('bbcode', 'bb'), (), 'Format tokens with BBcodes. These formatting codes are used by many bulletin boards, so you can highlight your sourcecode with pygments before posting it there.'),
Expand All @@ -30,55 +19,5 @@
'Terminal256Formatter': ('pygments.formatters.terminal256', 'Terminal256', ('terminal256', 'console256', '256'), (), 'Format tokens with ANSI color sequences, for output in a 256-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'),
'TerminalFormatter': ('pygments.formatters.terminal', 'Terminal', ('terminal', 'console'), (), 'Format tokens with ANSI color sequences, for output in a text console. Color sequences are terminated at newlines, so that paging the output works correctly.'),
'TerminalTrueColorFormatter': ('pygments.formatters.terminal256', 'TerminalTrueColor', ('terminal16m', 'console16m', '16m'), (), 'Format tokens with ANSI color sequences, for output in a true-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'),
'TestcaseFormatter': ('pygments.formatters.other', 'Testcase', ('testcase',), (), 'Format tokens as appropriate for a new testcase.')
'TestcaseFormatter': ('pygments.formatters.other', 'Testcase', ('testcase',), (), 'Format tokens as appropriate for a new testcase.'),
}

if __name__ == '__main__': # pragma: no cover
import sys
import os

# lookup formatters
found_formatters = []
imports = []
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
from pip._vendor.pygments.util import docstring_headline

for root, dirs, files in os.walk('.'):
for filename in files:
if filename.endswith('.py') and not filename.startswith('_'):
module_name = 'pygments.formatters%s.%s' % (
root[1:].replace('/', '.'), filename[:-3])
print(module_name)
module = __import__(module_name, None, None, [''])
for formatter_name in module.__all__:
formatter = getattr(module, formatter_name)
found_formatters.append(
'%r: %r' % (formatter_name,
(module_name,
formatter.name,
tuple(formatter.aliases),
tuple(formatter.filenames),
docstring_headline(formatter))))
# sort them to make the diff minimal
found_formatters.sort()

# extract useful sourcecode from this file
with open(__file__) as fp:
content = fp.read()
# replace crnl to nl for Windows.
#
# Note that, originally, contributors should keep nl of master
# repository, for example by using some kind of automatic
# management EOL, like `EolExtension
# <https://www.mercurial-scm.org/wiki/EolExtension>`.
content = content.replace("\r\n", "\n")
header = content[:content.find('FORMATTERS = {')]
footer = content[content.find("if __name__ == '__main__':"):]

# write new file
with open(__file__, 'w') as fp:
fp.write(header)
fp.write('FORMATTERS = {\n %s\n}\n\n' % ',\n '.join(found_formatters))
fp.write(footer)

print ('=== %d formatters processed.' % len(found_formatters))
12 changes: 8 additions & 4 deletions src/pip/_vendor/pygments/formatters/img.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,17 @@ def get_char_size(self):
"""
Get the character size.
"""
return self.fonts['NORMAL'].getsize('M')
return self.get_text_size('M')

def get_text_size(self, text):
"""
Get the text size(width, height).
Get the text size (width, height).
"""
return self.fonts['NORMAL'].getsize(text)
font = self.fonts['NORMAL']
if hasattr(font, 'getbbox'): # Pillow >= 9.2.0
return font.getbbox(text)[2:4]
else:
return font.getsize(text)

def get_font(self, bold, oblique):
"""
Expand Down Expand Up @@ -520,7 +524,7 @@ def _create_drawables(self, tokensource):
text_fg = self._get_text_color(style),
text_bg = self._get_text_bg_color(style),
)
temp_width, temp_hight = self.fonts.get_text_size(temp)
temp_width, _ = self.fonts.get_text_size(temp)
linelength += temp_width
maxlinelength = max(maxlinelength, linelength)
charno += len(temp)
Expand Down
20 changes: 5 additions & 15 deletions src/pip/_vendor/pygments/lexers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import re
import sys
import types
import fnmatch
from fnmatch import fnmatch
from os.path import basename

from pip._vendor.pygments.lexers._mapping import LEXERS
Expand All @@ -28,16 +28,6 @@
'guess_lexer', 'load_lexer_from_file'] + list(LEXERS) + list(COMPAT)

_lexer_cache = {}
_pattern_cache = {}


def _fn_matches(fn, glob):
"""Return whether the supplied file name fn matches pattern filename."""
if glob not in _pattern_cache:
pattern = _pattern_cache[glob] = re.compile(fnmatch.translate(glob))
return pattern.match(fn)
return _pattern_cache[glob].match(fn)


def _load_lexers(module_name):
"""Load a lexer (and all others in the module too)."""
Expand Down Expand Up @@ -169,13 +159,13 @@ def find_lexer_class_for_filename(_fn, code=None):
fn = basename(_fn)
for modname, name, _, filenames, _ in LEXERS.values():
for filename in filenames:
if _fn_matches(fn, filename):
if fnmatch(fn, filename):
if name not in _lexer_cache:
_load_lexers(modname)
matches.append((_lexer_cache[name], filename))
for cls in find_plugin_lexers():
for filename in cls.filenames:
if _fn_matches(fn, filename):
if fnmatch(fn, filename):
matches.append((cls, filename))

if isinstance(code, bytes):
Expand Down Expand Up @@ -262,11 +252,11 @@ def guess_lexer_for_filename(_fn, _text, **options):
matching_lexers = set()
for lexer in _iter_lexerclasses():
for filename in lexer.filenames:
if _fn_matches(fn, filename):
if fnmatch(fn, filename):
matching_lexers.add(lexer)
primary[lexer] = True
for filename in lexer.alias_filenames:
if _fn_matches(fn, filename):
if fnmatch(fn, filename):
matching_lexers.add(lexer)
primary[lexer] = False
if not matching_lexers:
Expand Down
Loading

0 comments on commit eb90699

Please sign in to comment.