Mercurial > hg
diff hgext/highlight/highlight.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | a7abc6081bc5 |
children | 687b865b95ad |
line wrap: on
line diff
--- a/hgext/highlight/highlight.py Sat Oct 05 10:29:34 2019 -0400 +++ b/hgext/highlight/highlight.py Sun Oct 06 09:45:02 2019 -0400 @@ -11,6 +11,7 @@ from __future__ import absolute_import from mercurial import demandimport + demandimport.IGNORES.update(['pkgutil', 'pkg_resources', '__main__']) from mercurial import ( @@ -18,9 +19,7 @@ pycompat, ) -from mercurial.utils import ( - stringutil, -) +from mercurial.utils import stringutil with demandimport.deactivated(): import pygments @@ -39,8 +38,10 @@ TextLexer = pygments.lexers.TextLexer HtmlFormatter = pygments.formatters.HtmlFormatter -SYNTAX_CSS = ('\n<link rel="stylesheet" href="{url}highlightcss" ' - 'type="text/css" />') +SYNTAX_CSS = ( + '\n<link rel="stylesheet" href="{url}highlightcss" ' 'type="text/css" />' +) + def pygmentize(field, fctx, style, tmpl, guessfilenameonly=False): @@ -67,8 +68,7 @@ # To get multi-line strings right, we can't format line-by-line try: path = pycompat.sysstr(fctx.path()) - lexer = guess_lexer_for_filename(path, text[:1024], - stripnl=False) + lexer = guess_lexer_for_filename(path, text[:1024], stripnl=False) except (ClassNotFound, ValueError): # guess_lexer will return a lexer if *any* lexer matches. There is # no way to specify a minimum match score. This can give a high rate of @@ -89,8 +89,10 @@ formatter = HtmlFormatter(nowrap=True, style=pycompat.sysstr(style)) colorized = highlight(text, lexer, formatter) - coloriter = (s.encode(pycompat.sysstr(encoding.encoding), 'replace') - for s in colorized.splitlines()) + coloriter = ( + s.encode(pycompat.sysstr(encoding.encoding), 'replace') + for s in colorized.splitlines() + ) tmpl._filters['colorize'] = lambda x: next(coloriter)