Merging upstream version 2.2.1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
4db980c3c4
commit
04b7f07412
9 changed files with 50 additions and 22 deletions
1
AUTHORS
1
AUTHORS
|
@ -23,6 +23,7 @@ This project receives help from these awesome contributors:
|
||||||
- Michał Górny
|
- Michał Górny
|
||||||
- Waldir Pimenta
|
- Waldir Pimenta
|
||||||
- Mel Dafert
|
- Mel Dafert
|
||||||
|
- Andrii Kohut
|
||||||
|
|
||||||
Thanks
|
Thanks
|
||||||
------
|
------
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
Version 2.2.1
|
||||||
|
-------------
|
||||||
|
|
||||||
|
(released on 2022-01-17)
|
||||||
|
|
||||||
|
* Fix pygments tokens passed as strings
|
||||||
|
|
||||||
Version 2.2.0
|
Version 2.2.0
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
__version__ = "2.2.0"
|
__version__ = "2.2.1"
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
"""OS and Python compatibility support."""
|
"""OS and Python compatibility support."""
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from types import SimpleNamespace
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
PY2 = sys.version_info[0] == 2
|
PY2 = sys.version_info[0] == 2
|
||||||
|
@ -34,9 +35,22 @@ else:
|
||||||
|
|
||||||
HAS_PYGMENTS = True
|
HAS_PYGMENTS = True
|
||||||
try:
|
try:
|
||||||
|
from pygments.token import Token
|
||||||
from pygments.formatters.terminal256 import Terminal256Formatter
|
from pygments.formatters.terminal256 import Terminal256Formatter
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_PYGMENTS = False
|
HAS_PYGMENTS = False
|
||||||
Terminal256Formatter = None
|
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)
|
float_types = (float, Decimal)
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
import string
|
import string
|
||||||
|
|
||||||
from cli_helpers import utils
|
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(
|
def truncate_string(
|
||||||
|
@ -58,9 +58,9 @@ def override_missing_value(
|
||||||
data,
|
data,
|
||||||
headers,
|
headers,
|
||||||
style=None,
|
style=None,
|
||||||
missing_value_token="Token.Output.Null",
|
missing_value_token=Token.Output.Null,
|
||||||
missing_value="",
|
missing_value="",
|
||||||
**_
|
**_,
|
||||||
):
|
):
|
||||||
"""Override missing values in the *data* with *missing_value*.
|
"""Override missing values in the *data* with *missing_value*.
|
||||||
|
|
||||||
|
@ -248,10 +248,10 @@ def style_output(
|
||||||
data,
|
data,
|
||||||
headers,
|
headers,
|
||||||
style=None,
|
style=None,
|
||||||
header_token="Token.Output.Header",
|
header_token=Token.Output.Header,
|
||||||
odd_row_token="Token.Output.OddRow",
|
odd_row_token=Token.Output.OddRow,
|
||||||
even_row_token="Token.Output.EvenRow",
|
even_row_token=Token.Output.EvenRow,
|
||||||
**_
|
**_,
|
||||||
):
|
):
|
||||||
"""Style the *data* and *headers* (e.g. bold, italic, and colors)
|
"""Style the *data* and *headers* (e.g. bold, italic, and colors)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from cli_helpers.utils import filter_dict_by_key
|
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 (
|
from .preprocessors import (
|
||||||
convert_to_string,
|
convert_to_string,
|
||||||
truncate_string,
|
truncate_string,
|
||||||
|
@ -105,8 +105,8 @@ def style_output_table(format_name=""):
|
||||||
data,
|
data,
|
||||||
headers,
|
headers,
|
||||||
style=None,
|
style=None,
|
||||||
table_separator_token="Token.Output.TableSeparator",
|
table_separator_token=Token.Output.TableSeparator,
|
||||||
**_
|
**_,
|
||||||
):
|
):
|
||||||
"""Style the *table* a(e.g. bold, italic, and colors)
|
"""Style the *table* a(e.g. bold, italic, and colors)
|
||||||
|
|
||||||
|
|
|
@ -104,13 +104,11 @@ def filter_style_table(style: "StyleMeta", *relevant_styles: str) -> Dict:
|
||||||
"""
|
"""
|
||||||
get a dictionary of styles for given tokens. Typical usage:
|
get a dictionary of styles for given tokens. Typical usage:
|
||||||
|
|
||||||
filter_style_table(style, 'Token.Output.EvenRow', 'Token.Output.OddRow') == {
|
filter_style_table(style, Token.Output.EvenRow, Token.Output.OddRow) == {
|
||||||
'Token.Output.EvenRow': "",
|
Token.Output.EvenRow: "",
|
||||||
'Token.Output.OddRow': "",
|
Token.Output.OddRow: "",
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
_styles_iter = (
|
_styles_iter = ((key, val) for key, val in getattr(style, "styles", {}).items())
|
||||||
(str(key), val) for key, val in getattr(style, "styles", {}).items()
|
|
||||||
)
|
|
||||||
_relevant_styles_iter = filter(lambda tpl: tpl[0] in relevant_styles, _styles_iter)
|
_relevant_styles_iter = filter(lambda tpl: tpl[0] in relevant_styles, _styles_iter)
|
||||||
return {key: val for key, val in _relevant_styles_iter}
|
return {key: val for key, val in _relevant_styles_iter}
|
||||||
|
|
|
@ -214,13 +214,21 @@ def test_enforce_iterable():
|
||||||
assert False, "{0} doesn't return iterable".format(format_name)
|
assert False, "{0} doesn't return iterable".format(format_name)
|
||||||
|
|
||||||
|
|
||||||
def test_all_text_type():
|
@pytest.mark.parametrize(
|
||||||
|
"extra_kwargs",
|
||||||
|
[
|
||||||
|
{},
|
||||||
|
{"style": "default"},
|
||||||
|
{"style": "colorful"},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_all_text_type(extra_kwargs):
|
||||||
"""Test the TabularOutputFormatter class."""
|
"""Test the TabularOutputFormatter class."""
|
||||||
data = [[1, "", None, Decimal(2)]]
|
data = [[1, "", None, Decimal(2)]]
|
||||||
headers = ["col1", "col2", "col3", "col4"]
|
headers = ["col1", "col2", "col3", "col4"]
|
||||||
output_formatter = TabularOutputFormatter()
|
output_formatter = TabularOutputFormatter()
|
||||||
for format_name in output_formatter.supported_formats:
|
for format_name in output_formatter.supported_formats:
|
||||||
for row in output_formatter.format_output(
|
for row in output_formatter.format_output(
|
||||||
iter(data), headers, format_name=format_name
|
iter(data), headers, format_name=format_name, **extra_kwargs
|
||||||
):
|
):
|
||||||
assert isinstance(row, text_type), "not unicode for {}".format(format_name)
|
assert isinstance(row, text_type), "not unicode for {}".format(format_name)
|
||||||
|
|
|
@ -250,9 +250,9 @@ def test_style_output_custom_tokens():
|
||||||
data,
|
data,
|
||||||
headers,
|
headers,
|
||||||
style=CliStyle,
|
style=CliStyle,
|
||||||
header_token="Token.Results.Headers",
|
header_token=Token.Results.Headers,
|
||||||
odd_row_token="Token.Results.OddRows",
|
odd_row_token=Token.Results.OddRows,
|
||||||
even_row_token="Token.Results.EvenRows",
|
even_row_token=Token.Results.EvenRows,
|
||||||
)
|
)
|
||||||
|
|
||||||
assert (expected_data, expected_headers) == (list(output[0]), output[1])
|
assert (expected_data, expected_headers) == (list(output[0]), output[1])
|
||||||
|
|
Loading…
Add table
Reference in a new issue