Fix PrettyPrinter, output verbosity is now slightly more discreete.
This commit is contained in:
2
Makefile
2
Makefile
@ -1,4 +1,4 @@
|
||||
# Generated by Medikit 0.4.2 on 2017-11-27.
|
||||
# Generated by Medikit 0.4.2 on 2017-12-01.
|
||||
# All changes will be overriden.
|
||||
|
||||
PACKAGE ?= bonobo
|
||||
|
||||
@ -46,7 +46,7 @@ python.add_requirements(
|
||||
'fs >=2.0,<2.1',
|
||||
'graphviz >=0.8,<0.9',
|
||||
'jinja2 >=2.9,<3',
|
||||
'mondrian >=0.5,<0.6',
|
||||
'mondrian >=0.6,<0.7',
|
||||
'packaging >=16,<17',
|
||||
'psutil >=5.4,<6',
|
||||
'python-slugify >=1.2,<1.3',
|
||||
|
||||
@ -19,6 +19,13 @@ class ConvertCommand(BaseCommand):
|
||||
help=
|
||||
'Choose the writer factory if it cannot be detected from extension, or if detection is wrong (use - for console pretty print).'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--limit',
|
||||
'-l',
|
||||
type=int,
|
||||
help='Adds a Limit() after the reader instance.',
|
||||
default=None,
|
||||
)
|
||||
parser.add_argument(
|
||||
'--transformation',
|
||||
'-t',
|
||||
@ -57,24 +64,32 @@ class ConvertCommand(BaseCommand):
|
||||
writer=None,
|
||||
writer_option=None,
|
||||
option=None,
|
||||
transformation=None
|
||||
limit=None,
|
||||
transformation=None,
|
||||
):
|
||||
reader_factory = default_registry.get_reader_factory_for(input_filename, format=reader)
|
||||
reader_options = _resolve_options((option or []) + (reader_option or []))
|
||||
reader_kwargs = _resolve_options((option or []) + (reader_option or []))
|
||||
|
||||
if output_filename == '-':
|
||||
writer_factory = bonobo.PrettyPrinter
|
||||
writer_args = ()
|
||||
else:
|
||||
writer_factory = default_registry.get_writer_factory_for(output_filename, format=writer)
|
||||
writer_options = _resolve_options((option or []) + (writer_option or []))
|
||||
writer_args = (output_filename, )
|
||||
writer_kwargs = _resolve_options((option or []) + (writer_option or []))
|
||||
|
||||
transformations = _resolve_transformations(transformation)
|
||||
transformations = ()
|
||||
|
||||
if limit:
|
||||
transformations += (bonobo.Limit(limit), )
|
||||
|
||||
transformations += _resolve_transformations(transformation)
|
||||
|
||||
graph = bonobo.Graph()
|
||||
graph.add_chain(
|
||||
reader_factory(input_filename, **reader_options),
|
||||
reader_factory(input_filename, **reader_kwargs),
|
||||
*transformations,
|
||||
writer_factory(output_filename, **writer_options),
|
||||
writer_factory(*writer_args, **writer_kwargs),
|
||||
)
|
||||
|
||||
return bonobo.run(
|
||||
|
||||
@ -119,21 +119,21 @@ class PrettyPrinter(Configurable):
|
||||
return ' '.join(((' ' if index else '-'), str(key), ':', str(value).strip()))
|
||||
|
||||
def print_console(self, context, *args, **kwargs):
|
||||
print('\u250e' + '\u2500' * (self.max_width - 1))
|
||||
print('\u250c')
|
||||
for index, (key, value) in enumerate(itertools.chain(enumerate(args), kwargs.items())):
|
||||
if self.filter(index, key, value):
|
||||
print(self.format_console(index, key, value, fields=context.get_input_fields()))
|
||||
print('\u2516' + '\u2500' * (self.max_width - 1))
|
||||
print('\u2514')
|
||||
|
||||
def format_console(self, index, key, value, *, fields=None):
|
||||
fields = fields or []
|
||||
if not isinstance(key, str):
|
||||
if len(fields) >= key and str(key) != str(fields[key]):
|
||||
if len(fields) > key and str(key) != str(fields[key]):
|
||||
key = '{}{}'.format(fields[key], term.lightblack('[{}]'.format(key)))
|
||||
else:
|
||||
key = str(index)
|
||||
|
||||
prefix = '\u2503 {} = '.format(key)
|
||||
prefix = '\u2502 {} = '.format(key)
|
||||
prefix_length = len(prefix)
|
||||
|
||||
def indent(text, prefix):
|
||||
@ -141,7 +141,7 @@ class PrettyPrinter(Configurable):
|
||||
yield (prefix if i else '') + line + CLEAR_EOL + '\n'
|
||||
|
||||
repr_of_value = ''.join(
|
||||
indent(pprint.pformat(value, width=self.max_width - prefix_length), '\u2503' + ' ' * (len(prefix) - 1))
|
||||
indent(pprint.pformat(value, width=self.max_width - prefix_length), '\u2502' + ' ' * (len(prefix) - 1))
|
||||
).strip()
|
||||
return '{}{}{}'.format(prefix, repr_of_value.replace('\n', CLEAR_EOL + '\n'), CLEAR_EOL)
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
-e .[dev]
|
||||
alabaster==0.7.10
|
||||
attrs==17.3.0
|
||||
babel==2.5.1
|
||||
certifi==2017.11.5
|
||||
chardet==3.0.4
|
||||
@ -9,12 +10,13 @@ idna==2.6
|
||||
imagesize==0.7.1
|
||||
jinja2==2.10
|
||||
markupsafe==1.0
|
||||
pluggy==0.6.0
|
||||
py==1.5.2
|
||||
pygments==2.2.0
|
||||
pytest-cov==2.5.1
|
||||
pytest-sugar==0.9.0
|
||||
pytest-timeout==1.2.0
|
||||
pytest==3.2.5
|
||||
pytest-timeout==1.2.1
|
||||
pytest==3.3.0
|
||||
pytz==2017.3
|
||||
requests==2.18.4
|
||||
six==1.11.0
|
||||
|
||||
@ -19,7 +19,7 @@ markupsafe==1.0
|
||||
mistune==0.8.1
|
||||
nbconvert==5.3.1
|
||||
nbformat==4.4.0
|
||||
notebook==5.2.1
|
||||
notebook==5.2.2
|
||||
pandocfilters==1.4.2
|
||||
parso==0.1.0
|
||||
pexpect==4.3.0
|
||||
@ -32,7 +32,7 @@ pyzmq==16.0.3
|
||||
qtconsole==4.3.1
|
||||
simplegeneric==0.8.1
|
||||
six==1.11.0
|
||||
terminado==0.8
|
||||
terminado==0.8.1
|
||||
testpath==0.3.1
|
||||
tornado==4.5.2
|
||||
traitlets==4.3.2
|
||||
|
||||
@ -8,7 +8,7 @@ graphviz==0.8.1
|
||||
idna==2.6
|
||||
jinja2==2.10
|
||||
markupsafe==1.0
|
||||
mondrian==0.5.1
|
||||
mondrian==0.6.0
|
||||
packaging==16.8
|
||||
pbr==3.1.1
|
||||
psutil==5.4.1
|
||||
|
||||
2
setup.py
2
setup.py
@ -60,7 +60,7 @@ setup(
|
||||
include_package_data=True,
|
||||
install_requires=[
|
||||
'colorama (>= 0.3)', 'fs (>= 2.0, < 2.1)', 'graphviz (>= 0.8, < 0.9)', 'jinja2 (>= 2.9, < 3)',
|
||||
'mondrian (>= 0.5, < 0.6)', 'packaging (>= 16, < 17)', 'psutil (>= 5.4, < 6)', 'python-slugify (>= 1.2, < 1.3)',
|
||||
'mondrian (>= 0.6, < 0.7)', 'packaging (>= 16, < 17)', 'psutil (>= 5.4, < 6)', 'python-slugify (>= 1.2, < 1.3)',
|
||||
'requests (>= 2, < 3)', 'stevedore (>= 1.27, < 1.28)', 'whistle (>= 1.0, < 1.1)'
|
||||
],
|
||||
extras_require={
|
||||
|
||||
Reference in New Issue
Block a user