ariatosca-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emblempar...@apache.org
Subject incubator-ariatosca git commit: ARIA-103 Remove dependency on Clint
Date Mon, 10 Jul 2017 13:09:50 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/master b30a7edd8 -> f903006b0


ARIA-103 Remove dependency on Clint

We no longer require this third-party library, instead the utils/console
module uses the existing cli/color module.

This commit also fixes the cli/color module to properly support Unicode,
and also properly deinitialize Colorama in Windows.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/f903006b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/f903006b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/f903006b

Branch: refs/heads/master
Commit: f903006b013fdc9c77b7be42a915dfb72fb16b96
Parents: b30a7ed
Author: Tal Liron <tal.liron@gmail.com>
Authored: Mon Jul 10 12:28:23 2017 +0300
Committer: Tal Liron <tal.liron@gmail.com>
Committed: Mon Jul 10 15:56:01 2017 +0300

----------------------------------------------------------------------
 aria/cli/color.py     | 21 ++++++++++++------
 aria/utils/console.py | 53 +++++++++++++++++++++++++++++++---------------
 requirements.in       |  1 -
 requirements.txt      |  4 +---
 4 files changed, 52 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f903006b/aria/cli/color.py
----------------------------------------------------------------------
diff --git a/aria/cli/color.py b/aria/cli/color.py
index 03381ba..d6a4cd6 100644
--- a/aria/cli/color.py
+++ b/aria/cli/color.py
@@ -18,11 +18,20 @@ Terminal colorization utilities.
 """
 
 from StringIO import StringIO
+import atexit
 import re
 
 import colorama
 
+from ..utils.formatting import safe_str
+
+
+def _restore_terminal():
+    colorama.deinit()
+
+
 colorama.init()
+atexit.register(_restore_terminal)
 
 
 class StringStylizer(object):
@@ -33,20 +42,20 @@ class StringStylizer(object):
     def __repr__(self):
         if self._color_spec:
             return '{schema}{str}{reset}'.format(
-                schema=self._color_spec, str=str(self._str), reset=Colors.Style.RESET_ALL)
+                schema=self._color_spec, str=safe_str(self._str), reset=Colors.Style.RESET_ALL)
         return self._str
 
     def __add__(self, other):
-        return str(self) + other
+        return safe_str(self) + other
 
     def __radd__(self, other):
-        return other + str(self)
+        return other + safe_str(self)
 
     def color(self, color_spec):
         self._color_spec = color_spec
 
     def replace(self, old, new, **kwargs):
-        self._str = self._str.replace(str(old), str(new), **kwargs)
+        self._str = self._str.replace(safe_str(old), safe_str(new), **kwargs)
 
     def format(self, *args, **kwargs):
         self._str = self._str.format(*args, **kwargs)
@@ -79,8 +88,8 @@ class Colors(object):
 class ColorSpec(object):
     def __init__(self, fore=None, back=None, style=None):
         """
-        It is possible to provide fore, back and style arguments. each could be either
-        the color is lower case letter, or the actual color from Colorama.
+        It is possible to provide fore, back and style arguments. Each could be either the
color as
+        lowercase letters, or the full color name for Colorama.
         """
         self._kwargs = dict(fore=fore, back=back, style=style)
         self._str = StringIO()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f903006b/aria/utils/console.py
----------------------------------------------------------------------
diff --git a/aria/utils/console.py b/aria/utils/console.py
index 642cbb1..2f6f622 100644
--- a/aria/utils/console.py
+++ b/aria/utils/console.py
@@ -17,52 +17,71 @@
 Abstraction API above terminal color libraries.
 """
 
-from clint.textui.core import STDOUT
-from clint.textui import puts as _puts
-from clint.textui.colored import ColoredString as _ColoredString
-from clint.textui import indent  # pylint: disable=unused-import
+import os
+import sys
+
+from contextlib import contextmanager
 
 from .formatting import safe_str
+from ..cli import color
+
+
+_indent_string = ''
 
 
-class ColoredString(_ColoredString):
-    def __init__(self, color, str_, always_color=False, bold=False):
-        super(ColoredString, self).__init__(color, safe_str(str_), always_color, bold)
+def puts(string='', newline=True, stream=sys.stdout):
+    stream.write(_indent_string)
+    stream.write(safe_str(string))
+    if newline:
+        stream.write(os.linesep)
 
 
-def puts(string='', newline=True, stream=STDOUT):
-    _puts(safe_str(string), newline, stream)
+@contextmanager
+def indent(size=4):
+    global _indent_string
+    original_indent_string = _indent_string
+    try:
+        _indent_string += ' ' * size
+        yield
+    finally:
+        _indent_string = original_indent_string
 
 
 class Colored(object):
     @staticmethod
     def black(string, always=False, bold=False):
-        return ColoredString('BLACK', string, always_color=always, bold=bold)
+        return Colored._color(string, color.Colors.Fore.BLACK, bold)
 
     @staticmethod
     def red(string, always=False, bold=False):
-        return ColoredString('RED', string, always_color=always, bold=bold)
+        return Colored._color(string, color.Colors.Fore.RED, bold)
 
     @staticmethod
     def green(string, always=False, bold=False):
-        return ColoredString('GREEN', string, always_color=always, bold=bold)
+        return Colored._color(string, color.Colors.Fore.GREEN, bold)
 
     @staticmethod
     def yellow(string, always=False, bold=False):
-        return ColoredString('YELLOW', string, always_color=always, bold=bold)
+        return Colored._color(string, color.Colors.Fore.YELLOW, bold)
 
     @staticmethod
     def blue(string, always=False, bold=False):
-        return ColoredString('BLUE', string, always_color=always, bold=bold)
+        return Colored._color(string, color.Colors.Fore.BLUE, bold)
 
     @staticmethod
     def magenta(string, always=False, bold=False):
-        return ColoredString('MAGENTA', string, always_color=always, bold=bold)
+        return Colored._color(string, color.Colors.Fore.MAGENTA, bold)
 
     @staticmethod
     def cyan(string, always=False, bold=False):
-        return ColoredString('CYAN', string, always_color=always, bold=bold)
+        return Colored._color(string, color.Colors.Fore.CYAN, bold)
 
     @staticmethod
     def white(string, always=False, bold=False):
-        return ColoredString('WHITE', string, always_color=always, bold=bold)
+        return Colored._color(string, color.Colors.Fore.WHITE, bold)
+
+    @staticmethod
+    def _color(string, fore, bold):
+        return color.StringStylizer(string, color.ColorSpec(
+            fore=fore,
+            style=color.Colors.Style.BRIGHT if bold else color.Colors.Style.NORMAL))

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f903006b/requirements.in
----------------------------------------------------------------------
diff --git a/requirements.in b/requirements.in
index 723ed51..a864335 100644
--- a/requirements.in
+++ b/requirements.in
@@ -22,7 +22,6 @@ ruamel.yaml>=0.11.12, <0.12.0  # version 0.12.0 dropped support of
python 2.6
 Jinja2>=2.8, <2.9
 shortuuid>=0.5, <0.6
 CacheControl[filecache]>=0.11.0, <0.13
-clint>=0.5.0, <0.6
 SQLAlchemy>=1.1.0, <1.2  # version 1.2 dropped support of python 2.6
 wagon==0.6.0
 bottle>=0.12.0, <0.13

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/f903006b/requirements.txt
----------------------------------------------------------------------
diff --git a/requirements.txt b/requirements.txt
index 7ee1008..ea97922 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,17 +2,15 @@
 # This file is autogenerated by pip-compile
 # To update, run:
 #
-#    pip-compile --output-file requirements.txt requirements.in
+#    pip-compile --output-file ./requirements.txt ./requirements.in
 #
 appdirs==1.4.3            # via setuptools
-args==0.1.0               # via clint
 backports.shutil_get_terminal_size==1.0.0
 blinker==1.4
 bottle==0.12.13
 cachecontrol[filecache]==0.12.1
 click==6.7
 click_didyoumean==0.0.3
-clint==0.5.1
 colorama==0.3.9
 decorator==4.0.11         # via networkx
 importlib==1.0.4 ; python_version < "2.7"


Mime
View raw message