From 0feccb1aa96f7baa4546525857d91fb31d00b2c7 Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Mon, 1 May 2017 15:21:26 +0200 Subject: [PATCH] reformating code, and adding specific rules for examples so it shows up correctly on readthedocs, by default. --- bonobo/_api.py | 11 ++++-- bonobo/basics.py | 1 + bonobo/examples/.style.yapf | 4 +++ bonobo/examples/datasets/fablabs.py | 36 ++++++++++++++----- bonobo/examples/files/json_handlers.py | 2 ++ bonobo/examples/tutorials/tut02_01_read.py | 4 +-- bonobo/examples/tutorials/tut02_02_write.py | 4 +-- .../examples/tutorials/tut02_03_writeasmap.py | 4 +-- bonobo/ext/jupyter/plugin.py | 2 -- bonobo/strategies/executor.py | 6 ++-- bonobo/structs/bags.py | 2 +- bonobo/util/errors.py | 5 +-- setup.py | 32 ++++++++--------- 13 files changed, 70 insertions(+), 43 deletions(-) create mode 100644 bonobo/examples/.style.yapf diff --git a/bonobo/_api.py b/bonobo/_api.py index 7d0f15e..1c05e59 100644 --- a/bonobo/_api.py +++ b/bonobo/_api.py @@ -88,7 +88,15 @@ def open_fs(fs_url, *args, **kwargs): # bonobo.basics -register_api_group(Limit, PrettyPrint, Tee, count, identity, noop, pprint, ) +register_api_group( + Limit, + PrettyPrint, + Tee, + count, + identity, + noop, + pprint, +) # bonobo.io register_api_group(CsvReader, CsvWriter, FileReader, FileWriter, JsonReader, JsonWriter) @@ -116,4 +124,3 @@ def get_examples_path(*pathsegments): @register_api def open_examples_fs(*pathsegments): return open_fs(get_examples_path(*pathsegments)) - diff --git a/bonobo/basics.py b/bonobo/basics.py index 6fd8c3d..97282ab 100644 --- a/bonobo/basics.py +++ b/bonobo/basics.py @@ -66,6 +66,7 @@ pprint = Tee(_pprint) def PrettyPrint(title_keys=('title', 'name', 'id'), print_values=True, sort=True): from bonobo.constants import NOT_MODIFIED + def _pprint(*args, **kwargs): nonlocal title_keys, sort, print_values diff --git a/bonobo/examples/.style.yapf b/bonobo/examples/.style.yapf new file mode 100644 index 0000000..70f7590 --- /dev/null +++ b/bonobo/examples/.style.yapf @@ -0,0 +1,4 @@ +[style] +based_on_style = pep8 +column_limit = 80 +dedent_closing_brackets = true diff --git a/bonobo/examples/datasets/fablabs.py b/bonobo/examples/datasets/fablabs.py index 17ee841..ae74c0b 100644 --- a/bonobo/examples/datasets/fablabs.py +++ b/bonobo/examples/datasets/fablabs.py @@ -25,7 +25,9 @@ from bonobo.ext.opendatasoft import OpenDataSoftAPI try: import pycountry except ImportError as exc: - raise ImportError('You must install package "pycountry" to run this example.') from exc + raise ImportError( + 'You must install package "pycountry" to run this example.' + ) from exc API_DATASET = 'fablabs-in-the-world' API_NETLOC = 'datanova.laposte.fr' @@ -57,20 +59,38 @@ def display(row): address = list( filter( None, ( - ' '.join(filter(None, (row.get('postal_code', None), row.get('city', None)))), row.get('county', None), - row.get('country'), + ' '.join( + filter( + None, + (row.get('postal_code', None), row.get('city', None)) + ) + ), row.get('county', None), row.get('country'), ) ) ) - print(' - {}address{}: {address}'.format(Fore.BLUE, Style.RESET_ALL, address=', '.join(address))) - print(' - {}links{}: {links}'.format(Fore.BLUE, Style.RESET_ALL, links=', '.join(row['links']))) - print(' - {}geometry{}: {geometry}'.format(Fore.BLUE, Style.RESET_ALL, **row)) - print(' - {}source{}: {source}'.format(Fore.BLUE, Style.RESET_ALL, source='datanova/' + API_DATASET)) + print( + ' - {}address{}: {address}'. + format(Fore.BLUE, Style.RESET_ALL, address=', '.join(address)) + ) + print( + ' - {}links{}: {links}'. + format(Fore.BLUE, Style.RESET_ALL, links=', '.join(row['links'])) + ) + print( + ' - {}geometry{}: {geometry}'. + format(Fore.BLUE, Style.RESET_ALL, **row) + ) + print( + ' - {}source{}: {source}'. + format(Fore.BLUE, Style.RESET_ALL, source='datanova/' + API_DATASET) + ) graph = bonobo.Graph( - OpenDataSoftAPI(dataset=API_DATASET, netloc=API_NETLOC, timezone='Europe/Paris'), + OpenDataSoftAPI( + dataset=API_DATASET, netloc=API_NETLOC, timezone='Europe/Paris' + ), normalize, filter_france, bonobo.Tee(display), diff --git a/bonobo/examples/files/json_handlers.py b/bonobo/examples/files/json_handlers.py index 727a137..0bb0436 100644 --- a/bonobo/examples/files/json_handlers.py +++ b/bonobo/examples/files/json_handlers.py @@ -1,9 +1,11 @@ import bonobo from bonobo.commands.run import get_default_services + def get_fields(row): return row['fields'] + graph = bonobo.Graph( bonobo.JsonReader(path='datasets/theaters.json'), get_fields, diff --git a/bonobo/examples/tutorials/tut02_01_read.py b/bonobo/examples/tutorials/tut02_01_read.py index e934c79..28baa9e 100644 --- a/bonobo/examples/tutorials/tut02_01_read.py +++ b/bonobo/examples/tutorials/tut02_01_read.py @@ -6,6 +6,4 @@ graph = bonobo.Graph( ) if __name__ == '__main__': - bonobo.run(graph, services={ - 'fs': bonobo.open_examples_fs('datasets') - }) + bonobo.run(graph, services={'fs': bonobo.open_examples_fs('datasets')}) diff --git a/bonobo/examples/tutorials/tut02_02_write.py b/bonobo/examples/tutorials/tut02_02_write.py index d63dd47..a3c4811 100644 --- a/bonobo/examples/tutorials/tut02_02_write.py +++ b/bonobo/examples/tutorials/tut02_02_write.py @@ -12,6 +12,4 @@ graph = bonobo.Graph( ) if __name__ == '__main__': - bonobo.run(graph, services={ - 'fs': bonobo.open_examples_fs('datasets') - }) + bonobo.run(graph, services={'fs': bonobo.open_examples_fs('datasets')}) diff --git a/bonobo/examples/tutorials/tut02_03_writeasmap.py b/bonobo/examples/tutorials/tut02_03_writeasmap.py index e131acd..bdf3194 100644 --- a/bonobo/examples/tutorials/tut02_03_writeasmap.py +++ b/bonobo/examples/tutorials/tut02_03_writeasmap.py @@ -22,6 +22,4 @@ graph = bonobo.Graph( ) if __name__ == '__main__': - bonobo.run(graph, services={ - 'fs': bonobo.open_examples_fs('datasets') - }) + bonobo.run(graph, services={'fs': bonobo.open_examples_fs('datasets')}) diff --git a/bonobo/ext/jupyter/plugin.py b/bonobo/ext/jupyter/plugin.py index fe907be..a418c83 100644 --- a/bonobo/ext/jupyter/plugin.py +++ b/bonobo/ext/jupyter/plugin.py @@ -22,5 +22,3 @@ class JupyterOutputPlugin(Plugin): self.widget.value = [repr(node) for node in self.context.parent.nodes] finalize = run - - diff --git a/bonobo/strategies/executor.py b/bonobo/strategies/executor.py index d43f2cd..3f34862 100644 --- a/bonobo/strategies/executor.py +++ b/bonobo/strategies/executor.py @@ -29,6 +29,7 @@ class ExecutorStrategy(Strategy): futures = [] for plugin_context in context.plugins: + def _runner(plugin_context=plugin_context): try: plugin_context.start() @@ -45,8 +46,9 @@ class ExecutorStrategy(Strategy): try: node_context.start() except Exception as exc: - print_error(exc, traceback.format_exc(), prefix='Could not start node context', - context=node_context) + print_error( + exc, traceback.format_exc(), prefix='Could not start node context', context=node_context + ) node_context.input.on_end() else: node_context.loop() diff --git a/bonobo/structs/bags.py b/bonobo/structs/bags.py index 4d86f89..1d4a7e8 100644 --- a/bonobo/structs/bags.py +++ b/bonobo/structs/bags.py @@ -32,7 +32,7 @@ class Bag: foo notbaz """ - + def __init__(self, *args, _flags=None, _parent=None, **kwargs): self._flags = _flags or () self._parent = _parent diff --git a/bonobo/util/errors.py b/bonobo/util/errors.py index 468ba2f..bd1f51f 100644 --- a/bonobo/util/errors.py +++ b/bonobo/util/errors.py @@ -21,8 +21,9 @@ def print_error(exc, trace, context=None, prefix=''): print( Style.BRIGHT, Fore.RED, - '\U0001F4A3 {}{}{}'.format((prefix + ': ') if prefix else '', type(exc).__name__, - ' in {!r}'.format(context) if context else ''), + '\U0001F4A3 {}{}{}'.format( + (prefix + ': ') if prefix else '', type(exc).__name__, ' in {!r}'.format(context) if context else '' + ), Style.RESET_ALL, sep='', file=sys.stderr, diff --git a/setup.py b/setup.py index 83bd632..8b02f65 100644 --- a/setup.py +++ b/setup.py @@ -45,39 +45,37 @@ setup( description='Bonobo', license='Apache License, Version 2.0', install_requires=[ - 'colorama >=0.3,<1.0', 'fs >=2.0,<3.0', 'psutil >=5.2,<6.0', - 'requests >=2.0,<3.0', 'stevedore >=1.21,<2.0' + 'colorama >=0.3,<1.0', 'fs >=2.0,<3.0', 'psutil >=5.2,<6.0', 'requests >=2.0,<3.0', 'stevedore >=1.21,<2.0' ], version=version, long_description=read('README.rst'), classifiers=read('classifiers.txt', tolines), packages=find_packages(exclude=['ez_setup', 'example', 'test']), include_package_data=True, - data_files=[('share/jupyter/nbextensions/bonobo-jupyter', [ - 'bonobo/ext/jupyter/static/extension.js', - 'bonobo/ext/jupyter/static/index.js', - 'bonobo/ext/jupyter/static/index.js.map' - ])], + data_files=[ + ( + 'share/jupyter/nbextensions/bonobo-jupyter', [ + 'bonobo/ext/jupyter/static/extension.js', 'bonobo/ext/jupyter/static/index.js', + 'bonobo/ext/jupyter/static/index.js.map' + ] + ) + ], extras_require={ 'dev': [ - 'coverage >=4,<5', 'pylint >=1,<2', 'pytest >=3,<4', - 'pytest-cov >=2,<3', 'pytest-timeout >=1,<2', 'sphinx', + 'coverage >=4,<5', 'pylint >=1,<2', 'pytest >=3,<4', 'pytest-cov >=2,<3', 'pytest-timeout >=1,<2', 'sphinx', 'sphinx_rtd_theme', 'yapf' ], 'jupyter': ['jupyter >=1.0,<1.1', 'ipywidgets >=6.0.0.beta5'] }, entry_points={ 'bonobo.commands': [ - 'init = bonobo.commands.init:register', - 'run = bonobo.commands.run:register', + 'init = bonobo.commands.init:register', 'run = bonobo.commands.run:register', 'version = bonobo.commands.version:register' ], 'console_scripts': ['bonobo = bonobo.commands:entrypoint'], - 'edgy.project.features': - ['bonobo = ' - 'bonobo.ext.edgy.project.feature:BonoboFeature'] + 'edgy.project.features': ['bonobo = ' + 'bonobo.ext.edgy.project.feature:BonoboFeature'] }, url='https://www.bonobo-project.org/', - download_url= - 'https://github.com/python-bonobo/bonobo/tarball/{version}'.format( - version=version), ) + download_url='https://github.com/python-bonobo/bonobo/tarball/{version}'.format(version=version), +)