reformating code, and adding specific rules for examples so it shows up correctly on readthedocs, by default.

This commit is contained in:
Romain Dorgueil
2017-05-01 15:21:26 +02:00
parent 474999a87e
commit 0feccb1aa9
13 changed files with 70 additions and 43 deletions

View File

@ -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))

View File

@ -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

View File

@ -0,0 +1,4 @@
[style]
based_on_style = pep8
column_limit = 80
dedent_closing_brackets = true

View File

@ -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),

View File

@ -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,

View File

@ -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')})

View File

@ -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')})

View File

@ -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')})

View File

@ -22,5 +22,3 @@ class JupyterOutputPlugin(Plugin):
self.widget.value = [repr(node) for node in self.context.parent.nodes]
finalize = run

View File

@ -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()

View File

@ -32,7 +32,7 @@ class Bag:
foo notbaz
"""
def __init__(self, *args, _flags=None, _parent=None, **kwargs):
self._flags = _flags or ()
self._parent = _parent

View File

@ -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,