Fix PrettyPrinter, output verbosity is now slightly more discreete.

This commit is contained in:
Romain Dorgueil
2017-12-01 07:42:23 +01:00
parent d8c0dfe11a
commit db54ff41ef
8 changed files with 36 additions and 19 deletions

View File

@ -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. # All changes will be overriden.
PACKAGE ?= bonobo PACKAGE ?= bonobo

View File

@ -46,7 +46,7 @@ python.add_requirements(
'fs >=2.0,<2.1', 'fs >=2.0,<2.1',
'graphviz >=0.8,<0.9', 'graphviz >=0.8,<0.9',
'jinja2 >=2.9,<3', 'jinja2 >=2.9,<3',
'mondrian >=0.5,<0.6', 'mondrian >=0.6,<0.7',
'packaging >=16,<17', 'packaging >=16,<17',
'psutil >=5.4,<6', 'psutil >=5.4,<6',
'python-slugify >=1.2,<1.3', 'python-slugify >=1.2,<1.3',

View File

@ -19,6 +19,13 @@ class ConvertCommand(BaseCommand):
help= help=
'Choose the writer factory if it cannot be detected from extension, or if detection is wrong (use - for console pretty print).' '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( parser.add_argument(
'--transformation', '--transformation',
'-t', '-t',
@ -57,24 +64,32 @@ class ConvertCommand(BaseCommand):
writer=None, writer=None,
writer_option=None, writer_option=None,
option=None, option=None,
transformation=None limit=None,
transformation=None,
): ):
reader_factory = default_registry.get_reader_factory_for(input_filename, format=reader) 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 == '-': if output_filename == '-':
writer_factory = bonobo.PrettyPrinter writer_factory = bonobo.PrettyPrinter
writer_args = ()
else: else:
writer_factory = default_registry.get_writer_factory_for(output_filename, format=writer) 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 = bonobo.Graph()
graph.add_chain( graph.add_chain(
reader_factory(input_filename, **reader_options), reader_factory(input_filename, **reader_kwargs),
*transformations, *transformations,
writer_factory(output_filename, **writer_options), writer_factory(*writer_args, **writer_kwargs),
) )
return bonobo.run( return bonobo.run(

View File

@ -119,21 +119,21 @@ class PrettyPrinter(Configurable):
return ' '.join(((' ' if index else '-'), str(key), ':', str(value).strip())) return ' '.join(((' ' if index else '-'), str(key), ':', str(value).strip()))
def print_console(self, context, *args, **kwargs): 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())): for index, (key, value) in enumerate(itertools.chain(enumerate(args), kwargs.items())):
if self.filter(index, key, value): if self.filter(index, key, value):
print(self.format_console(index, key, value, fields=context.get_input_fields())) 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): def format_console(self, index, key, value, *, fields=None):
fields = fields or [] fields = fields or []
if not isinstance(key, str): 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))) key = '{}{}'.format(fields[key], term.lightblack('[{}]'.format(key)))
else: else:
key = str(index) key = str(index)
prefix = '\u2503 {} = '.format(key) prefix = '\u2502 {} = '.format(key)
prefix_length = len(prefix) prefix_length = len(prefix)
def indent(text, prefix): def indent(text, prefix):
@ -141,7 +141,7 @@ class PrettyPrinter(Configurable):
yield (prefix if i else '') + line + CLEAR_EOL + '\n' yield (prefix if i else '') + line + CLEAR_EOL + '\n'
repr_of_value = ''.join( 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() ).strip()
return '{}{}{}'.format(prefix, repr_of_value.replace('\n', CLEAR_EOL + '\n'), CLEAR_EOL) return '{}{}{}'.format(prefix, repr_of_value.replace('\n', CLEAR_EOL + '\n'), CLEAR_EOL)

View File

@ -1,5 +1,6 @@
-e .[dev] -e .[dev]
alabaster==0.7.10 alabaster==0.7.10
attrs==17.3.0
babel==2.5.1 babel==2.5.1
certifi==2017.11.5 certifi==2017.11.5
chardet==3.0.4 chardet==3.0.4
@ -9,12 +10,13 @@ idna==2.6
imagesize==0.7.1 imagesize==0.7.1
jinja2==2.10 jinja2==2.10
markupsafe==1.0 markupsafe==1.0
pluggy==0.6.0
py==1.5.2 py==1.5.2
pygments==2.2.0 pygments==2.2.0
pytest-cov==2.5.1 pytest-cov==2.5.1
pytest-sugar==0.9.0 pytest-sugar==0.9.0
pytest-timeout==1.2.0 pytest-timeout==1.2.1
pytest==3.2.5 pytest==3.3.0
pytz==2017.3 pytz==2017.3
requests==2.18.4 requests==2.18.4
six==1.11.0 six==1.11.0

View File

@ -19,7 +19,7 @@ markupsafe==1.0
mistune==0.8.1 mistune==0.8.1
nbconvert==5.3.1 nbconvert==5.3.1
nbformat==4.4.0 nbformat==4.4.0
notebook==5.2.1 notebook==5.2.2
pandocfilters==1.4.2 pandocfilters==1.4.2
parso==0.1.0 parso==0.1.0
pexpect==4.3.0 pexpect==4.3.0
@ -32,7 +32,7 @@ pyzmq==16.0.3
qtconsole==4.3.1 qtconsole==4.3.1
simplegeneric==0.8.1 simplegeneric==0.8.1
six==1.11.0 six==1.11.0
terminado==0.8 terminado==0.8.1
testpath==0.3.1 testpath==0.3.1
tornado==4.5.2 tornado==4.5.2
traitlets==4.3.2 traitlets==4.3.2

View File

@ -8,7 +8,7 @@ graphviz==0.8.1
idna==2.6 idna==2.6
jinja2==2.10 jinja2==2.10
markupsafe==1.0 markupsafe==1.0
mondrian==0.5.1 mondrian==0.6.0
packaging==16.8 packaging==16.8
pbr==3.1.1 pbr==3.1.1
psutil==5.4.1 psutil==5.4.1

View File

@ -60,7 +60,7 @@ setup(
include_package_data=True, include_package_data=True,
install_requires=[ install_requires=[
'colorama (>= 0.3)', 'fs (>= 2.0, < 2.1)', 'graphviz (>= 0.8, < 0.9)', 'jinja2 (>= 2.9, < 3)', '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)' 'requests (>= 2, < 3)', 'stevedore (>= 1.27, < 1.28)', 'whistle (>= 1.0, < 1.1)'
], ],
extras_require={ extras_require={