diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..684cac0 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +ignore = F822 \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index dc697a1..c3de7fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,9 @@ python: - '3.8-dev' install: - - pip install colorama + - pip install colorama flake8 flake8-bugbear script: + - flake8 - python test_crayons.py + - python setup.py install diff --git a/crayons.py b/crayons.py index d64f662..2cd82f9 100644 --- a/crayons.py +++ b/crayons.py @@ -1,12 +1,5 @@ # -*- coding: utf-8 -*- - -""" -clint.colored -~~~~~~~~~~~~~ - -This module provides a simple and elegant wrapper for colorama. - -""" +"""A simple and elegant wrapper for colorama.""" import os import re @@ -16,6 +9,7 @@ import colorama PY3 = sys.version_info[0] >= 3 + __all__ = ( 'red', 'green', 'yellow', 'blue', 'black', 'magenta', 'cyan', 'white', @@ -38,11 +32,13 @@ else: if os.getenv("TERM") == "dumb": DISABLE_COLOR = True + class ColoredString(object): """Enhanced string for __len__ operations on Colored output.""" + def __init__(self, color, s, always_color=False, bold=False): super(ColoredString, self).__init__() - if not PY3 and isinstance(s, unicode): + if not PY3 and isinstance(s, unicode): # noqa: F821 self.s = s.encode('utf-8') else: self.s = s @@ -74,7 +70,7 @@ class ColoredString(object): getattr(colorama.Style, style), self.s, colorama.Fore.RESET, - getattr(colorama.Style, 'NORMAL')) + colorama.Style.NORMAL) if self.always_color: return c @@ -118,7 +114,7 @@ class ColoredString(object): def clean(s): - strip = re.compile(r"([^-_a-zA-Z0-9!@#%&=,/'\";:~`\$\^\*\(\)\+\[\]\.\{\}\|\?\<\>\\]+|[^\s]+)") + strip = re.compile(r"([^-_a-zA-Z0-9!@#%&=,/'\";:~`\$\^\*\(\)\+\[\]\.\{\}\|\?\<\>\\]+|[^\s]+)") # noqa: E501 txt = strip.sub('', str(s)) strip = re.compile(r'\[\d+m') @@ -126,22 +122,25 @@ def clean(s): return txt + _colors = {x: x.upper() for x in __all__[:-3]} _colors['normal'] = 'RESET' for key, val in _colors.items(): function = eval( - 'lambda s, always=False, bold=False: ColoredString("{}", s, always_color=always, bold=bold)'.format(val)) + 'lambda s, always=False, bold=False: ColoredString("{}", s, always_color=always, bold=bold)'.format(val)) # noqa: E501 locals()[key] = function del key, val, _colors, function + def disable(): """Disables colors.""" global DISABLE_COLOR DISABLE_COLOR = True + def enable(): """Enables colors.""" global DISABLE_COLOR diff --git a/setup.py b/setup.py index 8307b33..0257637 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +"""setup script for module installation.""" import os import sys