Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-ansicolor for openSUSE:Factory checked in at 2022-01-15 20:05:24 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-ansicolor (Old) and /work/SRC/openSUSE:Factory/.python-ansicolor.new.1892 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-ansicolor" Sat Jan 15 20:05:24 2022 rev:5 rq:946667 version:0.3.2 Changes: -------- --- /work/SRC/openSUSE:Factory/python-ansicolor/python-ansicolor.changes 2019-11-27 13:52:29.812412189 +0100 +++ /work/SRC/openSUSE:Factory/.python-ansicolor.new.1892/python-ansicolor.changes 2022-01-15 20:05:45.561785176 +0100 @@ -1,0 +2,7 @@ +Sat Jan 15 16:33:17 UTC 2022 - Dirk M??ller <dmuel...@suse.com> + +- update to 0.3.2: + * flake8 fixes + * python 3.8+ fixed + +------------------------------------------------------------------- Old: ---- ansicolor-0.2.6.tar.gz New: ---- ansicolor-0.3.2.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-ansicolor.spec ++++++ --- /var/tmp/diff_new_pack.Fyhpsu/_old 2022-01-15 20:05:45.925785459 +0100 +++ /var/tmp/diff_new_pack.Fyhpsu/_new 2022-01-15 20:05:45.929785462 +0100 @@ -1,7 +1,7 @@ # # spec file for package python-ansicolor # -# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2022 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -20,7 +20,7 @@ # For license file %define tag a5a5c31dc6de5c864a0c5684ae326972573a712b Name: python-ansicolor -Version: 0.2.6 +Version: 0.3.2 Release: 0 Summary: Python module for ANSI color output and colored highlighting and diffing License: Apache-2.0 ++++++ ansicolor-0.2.6.tar.gz -> ansicolor-0.3.2.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansicolor-0.2.6/PKG-INFO new/ansicolor-0.3.2/PKG-INFO --- old/ansicolor-0.2.6/PKG-INFO 2018-01-22 11:29:46.000000000 +0100 +++ new/ansicolor-0.3.2/PKG-INFO 2021-05-05 09:04:01.884181300 +0200 @@ -1,20 +1,16 @@ Metadata-Version: 1.1 Name: ansicolor -Version: 0.2.6 +Version: 0.3.2 Summary: A library to produce ansi color output and colored highlighting and diffing Home-page: https://github.com/numerodix/ansicolor Author: Martin Matusiak Author-email: numero...@gmail.com License: UNKNOWN -Description-Content-Type: UNKNOWN Description: UNKNOWN Platform: UNKNOWN Classifier: License :: OSI Approved :: Apache Software License -Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.2 -Classifier: Programming Language :: Python :: 3.3 -Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.8 +Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: Implementation :: CPython -Classifier: Programming Language :: Python :: Implementation :: PyPy diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansicolor-0.2.6/README.rst new/ansicolor-0.3.2/README.rst --- old/ansicolor-0.2.6/README.rst 2016-12-01 18:22:56.000000000 +0100 +++ new/ansicolor-0.3.2/README.rst 2021-05-05 08:56:26.000000000 +0200 @@ -4,16 +4,13 @@ .. image:: https://badge.fury.io/py/ansicolor.png :target: https://badge.fury.io/py/ansicolor -.. image:: https://travis-ci.org/numerodix/ansicolor.png?branch=master - :target: https://travis-ci.org/numerodix/ansicolor - -.. image:: https://pypip.in/wheel/ansicolor/badge.png +.. image:: https://img.shields.io/pypi/wheel/ansicolor.svg :target: https://pypi.python.org/pypi/ansicolor/ -.. image:: https://pypip.in/license/ansicolor/badge.png +.. image:: https://img.shields.io/pypi/l/ansicolor.svg :target: https://pypi.python.org/pypi/ansicolor/ -Python version support: CPython 2.6, 2.7, 3.2, 3.3, 3.4 and PyPy. +Python version support: CPython 2.7, 3.2+. Introduction @@ -30,6 +27,8 @@ $ pip install ansicolor +You can also download `tarballs from Github`_. + Documentation ------------- @@ -49,4 +48,117 @@ $ python -m ansicolor.demos --diff + +Maintenance tasks +----------------- + + +Setting up a development environment (Ubuntu) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. code:: bash + + # if you don't have `mkvirtualenv` & `workon` functions in your shell + $ sudo apt install virtualenvwrapper + + # creating the virtual env the first time + $ mkvirtualenv ansicolor + (ansicolor) $ pip install -r dev-requirements.txt + + # re-activating the virtual env next time + $ workon ansicolor + +All the steps below assume you have an activated virtual env (even though the +``(ansicolor)`` prompt is not shown). + + +Running unit tests +^^^^^^^^^^^^^^^^^^ + +.. code:: bash + + $ py.test + + +Measuring code coverage +^^^^^^^^^^^^^^^^^^^^^^^ + +.. code:: bash + + $ py.test --cov=ansicolor.ansicolor + $ coverage html + # open htmlcov/index.html in the browser + + +Running all possible tests under tox +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +We use ``tox`` to run both the unit tests and the demos under several different +Python interpreter versions. Depending on which interpreters you have installed +(this is managed system-wide and not covered in this README) ``tox`` will most +likely give you a partial success. + +.. code:: bash + + # to run against all interpreters + $ tox + + # to run only against selected interpreters + $ tox -e py27,py38 + + +Checking code style +^^^^^^^^^^^^^^^^^^^ + +.. code:: bash + + $ flake8 ansicolor + + +Re-formatting code +^^^^^^^^^^^^^^^^^^ + +.. code:: bash + + $ black ansicolor tests + + +Release a new version +^^^^^^^^^^^^^^^^^^^^^ + +1. Before starting work on a change/fix/whatever, make sure there is no + unfinished work on ``develop`` and merge ``master`` into ``develop``. +2. Make all the changes on ``develop``. + +Quality assurance (see steps above for how to): + +1. Make sure all tests are passing. +2. Make sure test coverage has not declined. +3. Make sure ``tox`` run succeeds on all (installed) interpreters. +4. Make sure ``flake8`` checker passes. +5. Make sure ``black`` formatter has no changes to make. + +Doc updates: + +1. Update ``docs/src/changes.rst``. + +Doing a release: + +1. Bump version in ``ansicolor/__init__.py``. +2. Git tag the new version and push the tag. This allows users/packagers to + download an auto-generated zip/tarball of the tagged release from Github. +3. ``python setup.py sdist`` +4. ``python setup.py bdist_wheel`` +5. ``twine upload dist/*`` + +Finally: + +1. Merge ``develop`` into ``master``. + +Post-release verification: + +1. ``pip install -U ansicolor`` from PyPI and use a tool that uses it. + + .. _`documentation`: https://ansicolor.readthedocs.org/ +.. _`tarballs from Github`: https://github.com/numerodix/ansicolor/tags diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansicolor-0.2.6/ansicolor/__init__.py new/ansicolor-0.3.2/ansicolor/__init__.py --- old/ansicolor-0.2.6/ansicolor/__init__.py 2018-01-22 11:29:38.000000000 +0100 +++ new/ansicolor-0.3.2/ansicolor/__init__.py 2021-05-05 09:03:29.000000000 +0200 @@ -1,36 +1,59 @@ from __future__ import absolute_import -from ansicolor.ansicolor import * # noqa +from ansicolor.ansicolor import black +from ansicolor.ansicolor import blue +from ansicolor.ansicolor import cyan +from ansicolor.ansicolor import green +from ansicolor.ansicolor import magenta +from ansicolor.ansicolor import red +from ansicolor.ansicolor import white +from ansicolor.ansicolor import yellow + +from ansicolor.ansicolor import colorize +from ansicolor.ansicolor import colorize_v2 +from ansicolor.ansicolor import get_code +from ansicolor.ansicolor import get_code_v2 +from ansicolor.ansicolor import wrap_string + +from ansicolor.ansicolor import highlight_string +from ansicolor.ansicolor import get_highlighter + +from ansicolor.ansicolor import strip_escapes +from ansicolor.ansicolor import justify_formatted + +from ansicolor.ansicolor import colordiff +from ansicolor.ansicolor import set_term_title +from ansicolor.ansicolor import write_out +from ansicolor.ansicolor import write_err +from ansicolor.ansicolor import Colors -__all__ = [ - 'black', - 'blue', - 'cyan', - 'green', - 'magenta', - 'red', - 'white', - 'yellow', - - 'colorize', - 'wrap_string', - 'get_code', - - 'highlight_string', - 'get_highlighter', - - 'strip_escapes', - 'justify_formatted', - - 'colordiff', - 'set_term_title', - 'write_out', - 'write_err', - 'Colors', +__all__ = [ + "black", + "blue", + "cyan", + "green", + "magenta", + "red", + "white", + "yellow", + "colorize", + "colorize_v2", + "get_code", + "get_code_v2", + "wrap_string", + "highlight_string", + "get_highlighter", + "strip_escapes", + "justify_formatted", + "colordiff", + "set_term_title", + "write_out", + "write_err", + "Colors", ] -__major_version__ = "0.2" -__release__ = "6" +__major_version__ = "0.3" +__release__ = "2" __version__ = "%s.%s" % (__major_version__, __release__) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansicolor-0.2.6/ansicolor/ansicolor.py new/ansicolor-0.3.2/ansicolor/ansicolor.py --- old/ansicolor-0.2.6/ansicolor/ansicolor.py 2018-01-22 11:29:29.000000000 +0100 +++ new/ansicolor-0.3.2/ansicolor/ansicolor.py 2021-05-05 09:01:20.000000000 +0200 @@ -8,33 +8,28 @@ __all__ = [ # noqa - 'black', - 'blue', - 'cyan', - 'green', - 'magenta', - 'red', - 'white', - 'yellow', - - 'colorize', - 'colorize_v2', - 'wrap_string', - 'get_code', - 'get_code_v2', - - 'highlight_string', - 'get_highlighter', - - 'strip_escapes', - 'justify_formatted', - - 'colordiff', - 'set_term_title', - 'write_out', - 'write_err', - - 'Colors', + "black", + "blue", + "cyan", + "green", + "magenta", + "red", + "white", + "yellow", + "colorize", + "colorize_v2", + "wrap_string", + "get_code", + "get_code_v2", + "highlight_string", + "get_highlighter", + "strip_escapes", + "justify_formatted", + "colordiff", + "set_term_title", + "write_out", + "write_err", + "Colors", ] @@ -43,7 +38,8 @@ class Colors(object): - '''Container class for colors''' + """Container class for colors""" + @classmethod def new(cls, colorname): try: @@ -62,7 +58,8 @@ for color in cls._colorlist: yield color -## Define Colors members + +# Define Colors members Colors.new("Black") Colors.new("Red") Colors.new("Green") @@ -73,32 +70,37 @@ Colors.new("White") -## Define coloring shorthands +# Define coloring shorthands def make_func(color): def f(s, bold=False, reverse=False): return colorize(s, color, bold=bold, reverse=reverse) - f.__doc__ = """ + + f.__doc__ = ( + """ Colorize string in %s :param string s: The string to colorize. :param bool bold: Whether to mark up in bold. :param bool reverse: Whether to mark up in reverse video. :rtype: string - """ % color.__name__.lower() + """ + % color.__name__.lower() + ) return f + for color in Colors.iter(): globals()[color.__name__.lower()] = make_func(color) -## Define highlighting colors +# Define highlighting colors highlights = [ Colors.Green, Colors.Yellow, Colors.Cyan, Colors.Blue, Colors.Magenta, - Colors.Red + Colors.Red, ] highlight_map = {} @@ -106,7 +108,7 @@ highlight_map[n] = [color for color in Colors.iter() if h == color].pop() -## Coloring functions +# Coloring functions def get_highlighter(colorid): """ Map a color index to a highlighting color. @@ -117,6 +119,7 @@ return highlight_map[colorid % len(highlights)] + def get_code(color, bold=False, reverse=False): """ Returns the escape code for styling with the given color, @@ -132,21 +135,23 @@ if _disabled: return "" - fmt = '0;0' + fmt = "0;0" if bold and reverse: - fmt = '1;7' + fmt = "1;7" elif reverse: - fmt = '0;7' + fmt = "0;7" elif bold: - fmt = '0;1' - color = (color is not None) and ';3%s' % color.id or '' + fmt = "0;1" + color = (color is not None) and ";3%s" % color.id or "" + + return "\033[" + fmt + color + "m" - return '\033[' + fmt + color + 'm' def get_code_v2(color, bold=False, reverse=False, underline=False, blink=False): """ Returns the escape code for styling with the given color, in bold and/or reverse. + :param color: The color to use. :type color: :class:`Colors` class :param bool bold: Whether to mark up in bold. @@ -159,18 +164,23 @@ if _disabled: return "" - fmt = '0' - l = [] - if bold: l.append('1') - if underline: l.append('4') - if blink: l.append('5') - if reverse: l.append('7') - if len(l) != 0: - fmt = ';'.join(l) + fmt = "0" + items = [] + if bold: + items.append("1") + if underline: + items.append("4") + if blink: + items.append("5") + if reverse: + items.append("7") + if len(items) != 0: + fmt = ";".join(items) - color = (color is not None) and ';3%s' % color.id or '' + color = (color is not None) and ";3%s" % color.id or "" + + return "\033[" + fmt + color + "m" - return '\033[' + fmt + color + 'm' def colorize(s, color, bold=False, reverse=False, start=None, end=None): """ @@ -193,16 +203,28 @@ between = s[start:end] after = s[end:] - return ("%s%s%s%s%s" % (before, - get_code(color, bold=bold, reverse=reverse), - between, - get_code(None), - after)) - -def colorize_v2(s, color, bold=False, reverse=False, underline=False, blink=False, - start=None, end=None): + return "%s%s%s%s%s" % ( + before, + get_code(color, bold=bold, reverse=reverse), + between, + get_code(None), + after, + ) + + +def colorize_v2( + s, + color, + bold=False, + reverse=False, + underline=False, + blink=False, + start=None, + end=None, +): """ Colorize a string with the color given. + :param string s: The string to colorize. :param color: The color to use. :type color: :class:`Colors` class @@ -222,14 +244,15 @@ between = s[start:end] after = s[end:] - return ("%s%s%s%s%s" % (before, - get_code_v2(color, bold=bold, - underline=underline, - blink=blink, - reverse=reverse), - between, - get_code_v2(None), - after)) + return "%s%s%s%s%s" % ( + before, + get_code_v2( + color, bold=bold, underline=underline, blink=blink, reverse=reverse + ), + between, + get_code_v2(None), + after, + ) def wrap_string(s, pos, color, bold=False, reverse=False): @@ -253,12 +276,14 @@ if _disabled: if pos == 0: pos = 1 - return s[:pos - 1] + "|" + s[pos:] + return s[: pos - 1] + "|" + s[pos:] - return "%s%s%s%s" % (get_code(color, bold=bold, reverse=reverse), - s[:pos], - get_code(None), - s[pos:]) + return "%s%s%s%s" % ( + get_code(color, bold=bold, reverse=reverse), + s[:pos], + get_code(None), + s[pos:], + ) def highlight_string(s, *spanlists, **kw): @@ -276,7 +301,7 @@ The `color` parameter has been deprecated in favor of `colors`. """ - colors = kw.get('colors', []) + colors = kw.get("colors", []) # pair span with color and id of the list -> (span, color, list_id) tuples = [] @@ -335,13 +360,13 @@ # allow bold/reverse/nocolor styling as parameters if color: - if kw.get('color'): - color = kw.get('color') + if kw.get("color"): + color = kw.get("color") warnings.warn("color is deprecated", DeprecationWarning, 2) - elif kw.get('nocolor'): + elif kw.get("nocolor"): color = None - bold = kw.get('bold') or bold - reverse = kw.get('reverse') or reverse + bold = kw.get("bold") or bold + reverse = kw.get("reverse") or reverse if layer == 2: bold = True @@ -357,7 +382,7 @@ cursor = pos segments.append(s[cursor:]) - return ''.join(segments) + return "".join(segments) def colordiff(x, y, color_x=Colors.Cyan, color_y=Colors.Green, debug=False): @@ -382,23 +407,25 @@ rather than the longest common subsequence, but this just causes the diff to show more changed characters, the result is still correct""" sm = difflib.SequenceMatcher(None, x, y) - seq = '' + seq = "" for match in sm.get_matching_blocks(): - seq += x[match.a:match.a + match.size] + seq += x[match.a : match.a + match.size] return seq def make_generator(it): g = ((i, e) for (i, e) in enumerate(it)) + def f(): try: return next(g) except StopIteration: return (-1, None) + return f def log(s): if debug: - print(s) + print(s) # pragma: no cover seq = compute_seq(x, y) log(">>> %s , %s -> %s" % (x, y, seq)) @@ -421,31 +448,31 @@ # character the same in all sets # -> unchanged if s == a == b: - log(' %s' % s) + log(" %s" % s) (sid, s) = it_seq() (aid, a) = it_x() (bid, b) = it_y() # character the same in orig and common # -> added in new elif s == a: - log('+%s' % b) + log("+%s" % b) y_spans.append((bid, bid + 1)) (bid, b) = it_y() # character the same in new and common # -> removed in orig elif s == b: - log('-%s' % a) + log("-%s" % a) x_spans.append((aid, aid + 1)) (aid, a) = it_x() # character not the same (eg. case change) # -> removed in orig and added in new elif a != b: if a: - log('-%s' % a) + log("-%s" % a) x_spans.append((aid, aid + 1)) (aid, a) = it_x() if b: - log('+%s' % b) + log("+%s" % b) y_spans.append((bid, bid + 1)) (bid, b) = it_y() @@ -477,10 +504,10 @@ :rtype: string """ - return re.sub('\033[[](?:(?:[0-9]*;)*)(?:[0-9]*m)', '', s) + return re.sub("\033\[(?:(?:[0-9]*;)*)(?:[0-9]*m)", "", s) -## Output functions +# Output functions def set_term_title(s): """ Set the title of a terminal window. @@ -491,6 +518,7 @@ if not _disabled: sys.stdout.write("\033]2;%s\007" % s) + def write_to(target, s): # assuming we have escapes in the string if not _disabled: @@ -499,6 +527,7 @@ target.write(s) target.flush() + def write_out(s): """ Write a string to ``sys.stdout``, strip escapes if output is a pipe. @@ -508,6 +537,7 @@ write_to(sys.stdout, s) + def write_err(s): """ Write a string to ``sys.stderr``, strip escapes if output is a pipe. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansicolor-0.2.6/ansicolor/demos.py new/ansicolor-0.3.2/ansicolor/demos.py --- old/ansicolor-0.2.6/ansicolor/demos.py 2018-01-22 11:29:29.000000000 +0100 +++ new/ansicolor-0.3.2/ansicolor/demos.py 2021-05-05 08:41:09.000000000 +0200 @@ -17,92 +17,129 @@ lst = [] - lst.extend([[], ['>>> Without colors'], []]) + lst.extend([[], [">>> Without colors"], []]) line = [] line.append(colorize("Standard".ljust(width), None)) line.append(colorize("Bold".ljust(width), None, bold=True)) line.append(colorize("Reverse".ljust(width), None, reverse=True)) - line.append(colorize("Bold & Rev".ljust(width), None, bold=True, reverse=True)) # noqa + line.append( + colorize("Bold & Rev".ljust(width), None, bold=True, reverse=True) + ) # noqa lst.append(line) - lst.extend([[], ['>>> Using colors'], []]) + lst.extend([[], [">>> Using colors"], []]) for color in Colors.iter(): line = [] line.append(colorize(color.__name__.ljust(width), color)) line.append(colorize(color.__name__.ljust(width), color, bold=True)) # noqa line.append(colorize(color.__name__.ljust(width), color, reverse=True)) # noqa - line.append(colorize(color.__name__.ljust(width), color, bold=True, reverse=True)) # noqa + line.append( + colorize(color.__name__.ljust(width), color, bold=True, reverse=True) + ) # noqa lst.append(line) - lst.extend([[], ['>>> Using highlighting colors'], []]) + lst.extend([[], [">>> Using highlighting colors"], []]) for color in Colors.iter(): color = get_highlighter(color.id) line = [] line.append(colorize(color.__name__.ljust(width), color)) line.append(colorize(color.__name__.ljust(width), color, bold=True)) # noqa line.append(colorize(color.__name__.ljust(width), color, reverse=True)) # noqa - line.append(colorize(color.__name__.ljust(width), color, bold=True, reverse=True)) # noqa + line.append( + colorize(color.__name__.ljust(width), color, bold=True, reverse=True) + ) # noqa lst.append(line) for line in lst: for item in line: - write_out('%s ' % item) + write_out("%s " % item) write_out("\n") + def demo_color_v2(): width = 10 lst = [] - lst.extend([[], ['>>> Without colors'], []]) + lst.extend([[], [">>> Without colors"], []]) line = [] line.append(colorize_v2("Standard".ljust(width), None)) line.append(colorize_v2("Bold".ljust(width), None, bold=True)) line.append(colorize_v2("Underline".ljust(width), None, underline=True)) line.append(colorize_v2("Blink".ljust(width), None, blink=True)) line.append(colorize_v2("Reverse".ljust(width), None, reverse=True)) - line.append(colorize_v2("Bold & Rev".ljust(width), None, bold=True, underline=True, reverse=True)) # noqa + line.append( + colorize_v2( + "Bold & Rev".ljust(width), None, bold=True, underline=True, reverse=True + ) + ) # noqa lst.append(line) - lst.extend([[], ['>>> Using colors_v2'], []]) + lst.extend([[], [">>> Using colors_v2"], []]) for color in Colors.iter(): line = [] line.append(colorize_v2(color.__name__.ljust(width), color)) line.append(colorize_v2(color.__name__.ljust(width), color, bold=True)) # noqa - line.append(colorize_v2(color.__name__.ljust(width), color, underline=True)) # noqa + line.append( + colorize_v2(color.__name__.ljust(width), color, underline=True) + ) # noqa line.append(colorize_v2(color.__name__.ljust(width), color, blink=True)) # noqa - line.append(colorize_v2(color.__name__.ljust(width), color, reverse=True)) # noqa - line.append(colorize_v2(color.__name__.ljust(width), color, bold=True, underline=True, reverse=True)) # noqa + line.append( + colorize_v2(color.__name__.ljust(width), color, reverse=True) + ) # noqa + line.append( + colorize_v2( + color.__name__.ljust(width), + color, + bold=True, + underline=True, + reverse=True, + ) + ) # noqa lst.append(line) - lst.extend([[], ['>>> Using highlighting colors_v2'], []]) + lst.extend([[], [">>> Using highlighting colors_v2"], []]) for color in Colors.iter(): color = get_highlighter(color.id) line = [] line.append(colorize_v2(color.__name__.ljust(width), color)) line.append(colorize_v2(color.__name__.ljust(width), color, bold=True)) # noqa - line.append(colorize_v2(color.__name__.ljust(width), color, underline=True)) # noqa + line.append( + colorize_v2(color.__name__.ljust(width), color, underline=True) + ) # noqa line.append(colorize_v2(color.__name__.ljust(width), color, blink=True)) # noqa - line.append(colorize_v2(color.__name__.ljust(width), color, reverse=True)) # noqa - line.append(colorize_v2(color.__name__.ljust(width), color, bold=True, underline=True, reverse=True)) # noqa + line.append( + colorize_v2(color.__name__.ljust(width), color, reverse=True) + ) # noqa + line.append( + colorize_v2( + color.__name__.ljust(width), + color, + bold=True, + underline=True, + reverse=True, + ) + ) # noqa lst.append(line) for line in lst: for item in line: - write_out('%s ' % item) + write_out("%s " % item) write_out("\n") + def _demo_highlight(reverse=False): rxs = [ - '(b+).*\\1', - '(c+).*\\1', - '(d+).*\\1', - '(e+).*\\1', + "(b+).*\\1", + "(c+).*\\1", + "(d+).*\\1", + "(e+).*\\1", ] s = """\ aaabbbcccdddeeefffeeedddcccbbbaaa fffeeedddcccbbbaaabbbcccdddeeefff """ + def display(rxs, s): spanlists = [] colors = [] @@ -122,17 +159,19 @@ for (i, rx) in enumerate(rxs): color = get_highlighter(i) color = colorize(color.__name__.ljust(10), color) - write_out('Regex %s: %s %s\n' % (i, color, rx)) + write_out("Regex %s: %s %s\n" % (i, color, rx)) write_out(s) for i in range(0, len(rxs) + 1): - write_out('\n') + write_out("\n") display(rxs[:i], s) + def demo_highlight(): _demo_highlight() + def demo_highlight_reverse(): _demo_highlight(reverse=True) @@ -140,31 +179,30 @@ def demo_diff(): def display_diff(s, t): (s_fmt, t_fmt) = colordiff(s, t) - write_out('>>> %s\n' % s_fmt) - write_out(' %s\n\n' % t_fmt) - - display_diff('first last', 'First Last') - display_diff('the the boss', 'the boss') - display_diff('the coder', 'the first coder') - display_diff('agcat', 'gac') - display_diff('XMJYAUZ', 'MZJAWXU') - display_diff('abcdfghjqz', 'abcdefgijkrxyz') + write_out(">>> %s\n" % s_fmt) + write_out(" %s\n\n" % t_fmt) + display_diff("first last", "First Last") + display_diff("the the boss", "the boss") + display_diff("the coder", "the first coder") + display_diff("agcat", "gac") + display_diff("XMJYAUZ", "MZJAWXU") + display_diff("abcdfghjqz", "abcdefgijkrxyz") -if __name__ == '__main__': +if __name__ == "__main__": try: action = sys.argv[1] except IndexError: print("Usage: %s [ --color | --highlight | --diff ]" % sys.argv[0]) sys.exit(1) - if action == '--color': + if action == "--color": demo_color() demo_color_v2() - elif action == '--highlight': + elif action == "--highlight": demo_highlight() - elif action == '--highlight-reverse': + elif action == "--highlight-reverse": demo_highlight_reverse() - elif action == '--diff': + elif action == "--diff": demo_diff() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansicolor-0.2.6/ansicolor.egg-info/PKG-INFO new/ansicolor-0.3.2/ansicolor.egg-info/PKG-INFO --- old/ansicolor-0.2.6/ansicolor.egg-info/PKG-INFO 2018-01-22 11:29:46.000000000 +0100 +++ new/ansicolor-0.3.2/ansicolor.egg-info/PKG-INFO 2021-05-05 09:04:01.000000000 +0200 @@ -1,20 +1,16 @@ Metadata-Version: 1.1 Name: ansicolor -Version: 0.2.6 +Version: 0.3.2 Summary: A library to produce ansi color output and colored highlighting and diffing Home-page: https://github.com/numerodix/ansicolor Author: Martin Matusiak Author-email: numero...@gmail.com License: UNKNOWN -Description-Content-Type: UNKNOWN Description: UNKNOWN Platform: UNKNOWN Classifier: License :: OSI Approved :: Apache Software License -Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.2 -Classifier: Programming Language :: Python :: 3.3 -Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.8 +Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: Implementation :: CPython -Classifier: Programming Language :: Python :: Implementation :: PyPy diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansicolor-0.2.6/ansicolor.egg-info/SOURCES.txt new/ansicolor-0.3.2/ansicolor.egg-info/SOURCES.txt --- old/ansicolor-0.2.6/ansicolor.egg-info/SOURCES.txt 2018-01-22 11:29:46.000000000 +0100 +++ new/ansicolor-0.3.2/ansicolor.egg-info/SOURCES.txt 2021-05-05 09:04:01.000000000 +0200 @@ -8,4 +8,7 @@ ansicolor.egg-info/SOURCES.txt ansicolor.egg-info/dependency_links.txt ansicolor.egg-info/not-zip-safe -ansicolor.egg-info/top_level.txt \ No newline at end of file +ansicolor.egg-info/top_level.txt +tests/__init__.py +tests/test_colors.py +tests/test_imports.py \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansicolor-0.2.6/setup.cfg new/ansicolor-0.3.2/setup.cfg --- old/ansicolor-0.2.6/setup.cfg 2018-01-22 11:29:46.000000000 +0100 +++ new/ansicolor-0.3.2/setup.cfg 2021-05-05 09:04:01.888181400 +0200 @@ -1,6 +1,7 @@ [flake8] exclude = .tox/,build/,docs/ -ignore = E301,E302,E303 +ignore = E203,E301,E302,E303,W503,W605 +max_line_length = 88 [wheel] universal = 1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansicolor-0.2.6/setup.py new/ansicolor-0.3.2/setup.py --- old/ansicolor-0.2.6/setup.py 2016-12-01 18:22:56.000000000 +0100 +++ new/ansicolor-0.3.2/setup.py 2021-05-05 08:41:09.000000000 +0200 @@ -4,29 +4,24 @@ setup( - name='ansicolor', + name="ansicolor", version=ansicolor.__version__, description=( - 'A library to produce ansi color output ' - 'and colored highlighting and diffing' + "A library to produce ansi color output and colored highlighting and diffing" ), - author='Martin Matusiak', - author_email='numero...@gmail.com', - url='https://github.com/numerodix/ansicolor', - + author="Martin Matusiak", + author_email="numero...@gmail.com", + url="https://github.com/numerodix/ansicolor", packages=[ - 'ansicolor', + "ansicolor", ], classifiers=[ - 'License :: OSI Approved :: Apache Software License', - 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.2', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy', + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: Implementation :: CPython", ], # don't install as zipped egg zip_safe=False, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansicolor-0.2.6/tests/test_colors.py new/ansicolor-0.3.2/tests/test_colors.py --- old/ansicolor-0.2.6/tests/test_colors.py 1970-01-01 01:00:00.000000000 +0100 +++ new/ansicolor-0.3.2/tests/test_colors.py 2021-05-05 08:41:09.000000000 +0200 @@ -0,0 +1,325 @@ +import contextlib + +from ansicolor import Colors +from ansicolor import blue +from ansicolor import colordiff +from ansicolor import colorize +from ansicolor import colorize_v2 +from ansicolor import get_code +from ansicolor import get_code_v2 +from ansicolor import get_highlighter +from ansicolor import highlight_string +from ansicolor import justify_formatted +from ansicolor import red +from ansicolor import set_term_title +from ansicolor import strip_escapes +from ansicolor import wrap_string +from ansicolor import write_err +from ansicolor import write_out +import ansicolor + + +@contextlib.contextmanager +def disabled_state(): + ansicolor.ansicolor._disabled = True + + try: + # run the test with colors disabled + yield + + finally: + ansicolor.ansicolor._disabled = False + + +def test_codes(): + # reset code + assert "\033[0;0m" == get_code(None) + + # plain color codes + assert "\033[0;0;30m" == get_code(Colors.Black) + assert "\033[0;0;31m" == get_code(Colors.Red) + assert "\033[0;0;32m" == get_code(Colors.Green) + assert "\033[0;0;33m" == get_code(Colors.Yellow) + assert "\033[0;0;34m" == get_code(Colors.Blue) + assert "\033[0;0;35m" == get_code(Colors.Magenta) + assert "\033[0;0;36m" == get_code(Colors.Cyan) + assert "\033[0;0;37m" == get_code(Colors.White) + + # bold color + assert "\033[0;1;31m" == get_code(Colors.Red, bold=True) + + # reverse color + assert "\033[0;7;31m" == get_code(Colors.Red, reverse=True) + + # bold + reverse color + assert "\033[1;7;31m" == get_code(Colors.Red, bold=True, reverse=True) + + +def test_codes_disabled(): + with disabled_state(): + assert "" == get_code(Colors.Black) + + +def test_codes_v2(): + # reset code + assert "\033[0m" == get_code_v2(None) + + # plain color codes + assert "\033[0;30m" == get_code_v2(Colors.Black) + assert "\033[0;31m" == get_code_v2(Colors.Red) + assert "\033[0;32m" == get_code_v2(Colors.Green) + assert "\033[0;33m" == get_code_v2(Colors.Yellow) + assert "\033[0;34m" == get_code_v2(Colors.Blue) + assert "\033[0;35m" == get_code_v2(Colors.Magenta) + assert "\033[0;36m" == get_code_v2(Colors.Cyan) + assert "\033[0;37m" == get_code_v2(Colors.White) + + # bold, underline, blink, reverse color + assert "\033[1;31m" == get_code_v2(Colors.Red, bold=True) + assert "\033[4;31m" == get_code_v2(Colors.Red, underline=True) + assert "\033[5;31m" == get_code_v2(Colors.Red, blink=True) + assert "\033[7;31m" == get_code_v2(Colors.Red, reverse=True) + + # mixed color + assert "\033[1;4;31m" == get_code_v2(Colors.Red, bold=True, underline=True) + assert "\033[1;5;31m" == get_code_v2(Colors.Red, bold=True, blink=True) + assert "\033[1;7;31m" == get_code_v2(Colors.Red, bold=True, reverse=True) + + assert "\033[4;5;31m" == get_code_v2(Colors.Red, underline=True, blink=True) + assert "\033[4;7;31m" == get_code_v2(Colors.Red, underline=True, reverse=True) + + assert "\033[5;7;31m" == get_code_v2(Colors.Red, blink=True, reverse=True) + + assert "\033[1;4;5;31m" == get_code_v2( + Colors.Red, bold=True, underline=True, blink=True + ) + assert "\033[1;4;7;31m" == get_code_v2( + Colors.Red, bold=True, underline=True, reverse=True + ) + assert "\033[1;5;7;31m" == get_code_v2( + Colors.Red, bold=True, blink=True, reverse=True + ) + assert "\033[1;4;5;7;31m" == get_code_v2( + Colors.Red, bold=True, underline=True, blink=True, reverse=True + ) + + +def test_codes_v2_disabled(): + with disabled_state(): + assert "" == get_code_v2(Colors.Black) + + +def test_coloring(): + assert "\033[0;0;31m" + "hi" + "\033[0;0m" == red("hi") + + +def test_get_hightlighter(): + # can I get a highlighter? + assert Colors.Green == get_highlighter(0) + assert Colors.Yellow == get_highlighter(1) + + +def test_highlight_string_one_layer(): + text = "aaabbbaaa" + spanlists = [ + [(3, 6)], + ] + + assert ( + "aaa" + get_code(Colors.Green) + "bbb" + get_code(None) + "aaa" + ) == highlight_string(text, *spanlists) + + +def test_highlight_string_one_color_chosen(): + text = "aaabbbaaa" + spanlists = [ + [(3, 6)], + ] + + assert ( + "aaa" + get_code(Colors.Cyan) + "bbb" + get_code(None) + "aaa" + ) == highlight_string(text, *spanlists, color=Colors.Cyan) + + +def test_highlight_string_nocolor(): + text = "aaabbbaaa" + spanlists = [ + [(3, 6)], + ] + + assert ( + "aaa" + get_code(None) + "bbb" + get_code(None) + "aaa" + ) == highlight_string(text, *spanlists, nocolor=True) + + +def test_highlight_string_four_layers_inside_out(): + text = "aaabbbcccdddeeefffeeedddcccbbbaaa" + spanlists = [ + [(3, 30)], + [(6, 27)], + [(9, 24)], + [(12, 21)], + ] + colors = [ + Colors.Green, + Colors.Yellow, + Colors.Cyan, + Colors.Blue, + ] + + assert ( + "aaa" + + get_code(Colors.Green) + + "bbb" + + get_code(Colors.Yellow, bold=True) + + "ccc" + + get_code(Colors.Cyan, reverse=True) + + "ddd" + + get_code(Colors.Blue, bold=True, reverse=True) + + "eeefffeee" + + get_code(Colors.Cyan, reverse=True) + + "ddd" + + get_code(Colors.Yellow, bold=True) + + "ccc" + + get_code(Colors.Green) + + "bbb" + + get_code(None) + + "aaa" + ) == highlight_string(text, *spanlists, colors=colors) + + +def test_highlight_string_four_layers_outside_in(): + text = "fffeeedddcccbbbaaabbbcccdddeeefff" + spanlists = [[(12, 21)], [(9, 24)], [(6, 27)], [(3, 30)]] + colors = [ + Colors.Green, + Colors.Yellow, + Colors.Cyan, + Colors.Blue, + ] + + assert ( + "fff" + + get_code(Colors.Blue) + + "eee" + + get_code(Colors.Blue, bold=True) + + "ddd" + + get_code(Colors.Blue, reverse=True) + + "ccc" + + get_code(Colors.Blue, bold=True, reverse=True) + + "bbbaaabbb" + + get_code(Colors.Blue, reverse=True) + + "ccc" + + get_code(Colors.Blue, bold=True) + + "ddd" + + get_code(Colors.Blue) + + "eee" + + get_code(None) + + "fff" + ) == highlight_string(text, *spanlists, colors=colors) + + +def test_colorize(): + assert (get_code(Colors.Red) + "Hi there" + get_code(None)) == colorize( + "Hi there", Colors.Red + ) + + +def test_colorize_with_start_end(): + assert ("H" + get_code(Colors.Red) + "i ther" + get_code(None) + "e") == colorize( + "Hi there", Colors.Red, start=1, end=7 + ) + + +def test_colorize_v2(): + assert (get_code_v2(Colors.Red) + "Hi there" + get_code_v2(None)) == colorize_v2( + "Hi there", Colors.Red + ) + + assert ( + "H" + get_code_v2(Colors.Red) + "i ther" + get_code_v2(None) + "e" + ) == colorize_v2("Hi there", Colors.Red, start=1, end=7) + + +def test_wrap_string(): + assert (get_code(Colors.Red) + "Hi " + get_code(None) + "there") == wrap_string( + "Hi there", 3, Colors.Red + ) + + +def test_wrap_string_disabled(): + with disabled_state(): + assert "Hi|there" == wrap_string("Hi there", 3, Colors.Red) + assert "|i there" == wrap_string("Hi there", 0, Colors.Red) + + +def test_strip_escapes(): + assert "Hi there" == strip_escapes(colorize("Hi there", Colors.Red, start=3)) + + assert ( + strip_escapes( + colorize("Hi", None, bold=True) + + " there, " + + colorize("stranger", Colors.Green, bold=True) + ) + == "Hi there, stranger" + ) + + +def test_colordiff_different(): + x, y = colordiff("hi bob", "hi there", color_x=Colors.Red, color_y=Colors.Blue) + + def fx(s): + return red(s, reverse=True) + + def fy(s): + return blue(s, reverse=True) + + assert x == "hi " + fx("b") + fx("o") + fx("b") + assert y == "hi " + fy("t") + fy("h") + fy("e") + fy("r") + fy("e") + + +def test_colordiff_edited(): + x, y = colordiff("hi bobby", "hi bob", color_x=Colors.Red, color_y=Colors.Blue) + + def fx(s): + return red(s, reverse=True) + + assert x == "hi bob" + fx("b") + fx("y") + assert y == "hi bob" + + +def test_justify_formatted(): + def rjust(s, width): + return s.rjust(width) + + assert justify_formatted(red("hi"), rjust, 10) == " " + red("hi") + + +def test_set_term_title(capsys): + set_term_title("ansicolor demo") + + captured = capsys.readouterr() + assert "\033]2;ansicolor demo\007" == captured.out + + +def test_write_out(capfd): + text = colorize("Hi there", Colors.Red, start=3, end=6) + + # escapes will be stripped since we rely on capfd and os.isatty detects a + # tty device on the other end + write_out(text) + + captured = capfd.readouterr() + assert "Hi there" == captured.out + + +def test_write_err(capfd): + text = colorize("Hi there", Colors.Red, start=3, end=6) + + # escapes will be stripped since we rely on capfd and os.isatty detects a + # tty device on the other end + write_err(text) + + captured = capfd.readouterr() + assert "Hi there" == captured.err diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ansicolor-0.2.6/tests/test_imports.py new/ansicolor-0.3.2/tests/test_imports.py --- old/ansicolor-0.2.6/tests/test_imports.py 1970-01-01 01:00:00.000000000 +0100 +++ new/ansicolor-0.3.2/tests/test_imports.py 2021-05-05 08:41:09.000000000 +0200 @@ -0,0 +1,34 @@ +def test_importability(): + from ansicolor import black # noqa + from ansicolor import blue # noqa + from ansicolor import cyan # noqa + from ansicolor import green # noqa + from ansicolor import magenta # noqa + from ansicolor import red # noqa + from ansicolor import white # noqa + from ansicolor import yellow # noqa + + from ansicolor import Colors # noqa + + Colors.Black + Colors.Blue + Colors.Cyan + Colors.Green + Colors.Magenta + Colors.Red + Colors.White + Colors.Yellow + + from ansicolor import get_highlighter # noqa + from ansicolor import get_code # noqa + + from ansicolor import colorize # noqa + from ansicolor import wrap_string # noqa + from ansicolor import highlight_string # noqa + from ansicolor import colordiff # noqa + from ansicolor import justify_formatted # noqa + from ansicolor import strip_escapes # noqa + from ansicolor import set_term_title # noqa + + from ansicolor import write_err # noqa + from ansicolor import write_out # noqa