mirror of
https://github.com/kennethreitz/crayons.git
synced 2026-06-05 23:10:18 +00:00
add flake8 linting for crayons
This commit is contained in:
+3
-1
@@ -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
|
||||
|
||||
+11
-12
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user