diff options
Diffstat (limited to 'cli_helpers')
-rw-r--r-- | cli_helpers/__init__.py | 2 | ||||
-rw-r--r-- | cli_helpers/compat.py | 14 | ||||
-rw-r--r-- | cli_helpers/tabular_output/preprocessors.py | 14 | ||||
-rw-r--r-- | cli_helpers/tabular_output/tabulate_adapter.py | 6 | ||||
-rw-r--r-- | cli_helpers/utils.py | 10 |
5 files changed, 29 insertions, 17 deletions
diff --git a/cli_helpers/__init__.py b/cli_helpers/__init__.py index 8a124bf..b19ee4b 100644 --- a/cli_helpers/__init__.py +++ b/cli_helpers/__init__.py @@ -1 +1 @@ -__version__ = "2.2.0" +__version__ = "2.2.1" diff --git a/cli_helpers/compat.py b/cli_helpers/compat.py index c938851..422403c 100644 --- a/cli_helpers/compat.py +++ b/cli_helpers/compat.py @@ -2,6 +2,7 @@ """OS and Python compatibility support.""" from decimal import Decimal +from types import SimpleNamespace import sys PY2 = sys.version_info[0] == 2 @@ -34,9 +35,22 @@ else: HAS_PYGMENTS = True try: + from pygments.token import Token from pygments.formatters.terminal256 import Terminal256Formatter except ImportError: HAS_PYGMENTS = False Terminal256Formatter = None + Token = SimpleNamespace() + Token.Output = SimpleNamespace() + Token.Output.Header = None + Token.Output.OddRow = None + Token.Output.EvenRow = None + Token.Output.Null = None + Token.Output.TableSeparator = None + Token.Results = SimpleNamespace() + Token.Results.Header = None + Token.Results.OddRow = None + Token.Results.EvenRow = None + float_types = (float, Decimal) diff --git a/cli_helpers/tabular_output/preprocessors.py b/cli_helpers/tabular_output/preprocessors.py index 5d91126..8342d67 100644 --- a/cli_helpers/tabular_output/preprocessors.py +++ b/cli_helpers/tabular_output/preprocessors.py @@ -4,7 +4,7 @@ import string from cli_helpers import utils -from cli_helpers.compat import text_type, int_types, float_types, HAS_PYGMENTS +from cli_helpers.compat import text_type, int_types, float_types, HAS_PYGMENTS, Token def truncate_string( @@ -58,9 +58,9 @@ def override_missing_value( data, headers, style=None, - missing_value_token="Token.Output.Null", + missing_value_token=Token.Output.Null, missing_value="", - **_ + **_, ): """Override missing values in the *data* with *missing_value*. @@ -248,10 +248,10 @@ def style_output( data, headers, style=None, - header_token="Token.Output.Header", - odd_row_token="Token.Output.OddRow", - even_row_token="Token.Output.EvenRow", - **_ + header_token=Token.Output.Header, + odd_row_token=Token.Output.OddRow, + even_row_token=Token.Output.EvenRow, + **_, ): """Style the *data* and *headers* (e.g. bold, italic, and colors) diff --git a/cli_helpers/tabular_output/tabulate_adapter.py b/cli_helpers/tabular_output/tabulate_adapter.py index 92e6f1d..a7eabc0 100644 --- a/cli_helpers/tabular_output/tabulate_adapter.py +++ b/cli_helpers/tabular_output/tabulate_adapter.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals from cli_helpers.utils import filter_dict_by_key -from cli_helpers.compat import Terminal256Formatter, StringIO +from cli_helpers.compat import Terminal256Formatter, Token, StringIO from .preprocessors import ( convert_to_string, truncate_string, @@ -105,8 +105,8 @@ def style_output_table(format_name=""): data, headers, style=None, - table_separator_token="Token.Output.TableSeparator", - **_ + table_separator_token=Token.Output.TableSeparator, + **_, ): """Style the *table* a(e.g. bold, italic, and colors) diff --git a/cli_helpers/utils.py b/cli_helpers/utils.py index 3f09cb5..053bdea 100644 --- a/cli_helpers/utils.py +++ b/cli_helpers/utils.py @@ -104,13 +104,11 @@ def filter_style_table(style: "StyleMeta", *relevant_styles: str) -> Dict: """ get a dictionary of styles for given tokens. Typical usage: - filter_style_table(style, 'Token.Output.EvenRow', 'Token.Output.OddRow') == { - 'Token.Output.EvenRow': "", - 'Token.Output.OddRow': "", + filter_style_table(style, Token.Output.EvenRow, Token.Output.OddRow) == { + Token.Output.EvenRow: "", + Token.Output.OddRow: "", } """ - _styles_iter = ( - (str(key), val) for key, val in getattr(style, "styles", {}).items() - ) + _styles_iter = ((key, val) for key, val in getattr(style, "styles", {}).items()) _relevant_styles_iter = filter(lambda tpl: tpl[0] in relevant_styles, _styles_iter) return {key: val for key, val in _relevant_styles_iter} |