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 # bonobo.basics
register_api_group(Limit, PrettyPrint, Tee, count, identity, noop, pprint, ) register_api_group(
Limit,
PrettyPrint,
Tee,
count,
identity,
noop,
pprint,
)
# bonobo.io # bonobo.io
register_api_group(CsvReader, CsvWriter, FileReader, FileWriter, JsonReader, JsonWriter) register_api_group(CsvReader, CsvWriter, FileReader, FileWriter, JsonReader, JsonWriter)
@ -116,4 +124,3 @@ def get_examples_path(*pathsegments):
@register_api @register_api
def open_examples_fs(*pathsegments): def open_examples_fs(*pathsegments):
return open_fs(get_examples_path(*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): def PrettyPrint(title_keys=('title', 'name', 'id'), print_values=True, sort=True):
from bonobo.constants import NOT_MODIFIED from bonobo.constants import NOT_MODIFIED
def _pprint(*args, **kwargs): def _pprint(*args, **kwargs):
nonlocal title_keys, sort, print_values 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: try:
import pycountry import pycountry
except ImportError as exc: 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_DATASET = 'fablabs-in-the-world'
API_NETLOC = 'datanova.laposte.fr' API_NETLOC = 'datanova.laposte.fr'
@ -57,20 +59,38 @@ def display(row):
address = list( address = list(
filter( filter(
None, ( None, (
' '.join(filter(None, (row.get('postal_code', None), row.get('city', None)))), row.get('county', None), ' '.join(
row.get('country'), 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(
print(' - {}links{}: {links}'.format(Fore.BLUE, Style.RESET_ALL, links=', '.join(row['links']))) ' - {}address{}: {address}'.
print(' - {}geometry{}: {geometry}'.format(Fore.BLUE, Style.RESET_ALL, **row)) format(Fore.BLUE, Style.RESET_ALL, address=', '.join(address))
print(' - {}source{}: {source}'.format(Fore.BLUE, Style.RESET_ALL, source='datanova/' + API_DATASET)) )
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( graph = bonobo.Graph(
OpenDataSoftAPI(dataset=API_DATASET, netloc=API_NETLOC, timezone='Europe/Paris'), OpenDataSoftAPI(
dataset=API_DATASET, netloc=API_NETLOC, timezone='Europe/Paris'
),
normalize, normalize,
filter_france, filter_france,
bonobo.Tee(display), bonobo.Tee(display),

View File

@ -1,9 +1,11 @@
import bonobo import bonobo
from bonobo.commands.run import get_default_services from bonobo.commands.run import get_default_services
def get_fields(row): def get_fields(row):
return row['fields'] return row['fields']
graph = bonobo.Graph( graph = bonobo.Graph(
bonobo.JsonReader(path='datasets/theaters.json'), bonobo.JsonReader(path='datasets/theaters.json'),
get_fields, get_fields,

View File

@ -6,6 +6,4 @@ graph = bonobo.Graph(
) )
if __name__ == '__main__': if __name__ == '__main__':
bonobo.run(graph, services={ bonobo.run(graph, services={'fs': bonobo.open_examples_fs('datasets')})
'fs': bonobo.open_examples_fs('datasets')
})

View File

@ -12,6 +12,4 @@ graph = bonobo.Graph(
) )
if __name__ == '__main__': if __name__ == '__main__':
bonobo.run(graph, services={ bonobo.run(graph, services={'fs': bonobo.open_examples_fs('datasets')})
'fs': bonobo.open_examples_fs('datasets')
})

View File

@ -22,6 +22,4 @@ graph = bonobo.Graph(
) )
if __name__ == '__main__': if __name__ == '__main__':
bonobo.run(graph, services={ bonobo.run(graph, services={'fs': bonobo.open_examples_fs('datasets')})
'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] self.widget.value = [repr(node) for node in self.context.parent.nodes]
finalize = run finalize = run

View File

@ -29,6 +29,7 @@ class ExecutorStrategy(Strategy):
futures = [] futures = []
for plugin_context in context.plugins: for plugin_context in context.plugins:
def _runner(plugin_context=plugin_context): def _runner(plugin_context=plugin_context):
try: try:
plugin_context.start() plugin_context.start()
@ -45,8 +46,9 @@ class ExecutorStrategy(Strategy):
try: try:
node_context.start() node_context.start()
except Exception as exc: except Exception as exc:
print_error(exc, traceback.format_exc(), prefix='Could not start node context', print_error(
context=node_context) exc, traceback.format_exc(), prefix='Could not start node context', context=node_context
)
node_context.input.on_end() node_context.input.on_end()
else: else:
node_context.loop() node_context.loop()

View File

@ -21,8 +21,9 @@ def print_error(exc, trace, context=None, prefix=''):
print( print(
Style.BRIGHT, Style.BRIGHT,
Fore.RED, Fore.RED,
'\U0001F4A3 {}{}{}'.format((prefix + ': ') if prefix else '', type(exc).__name__, '\U0001F4A3 {}{}{}'.format(
' in {!r}'.format(context) if context else ''), (prefix + ': ') if prefix else '', type(exc).__name__, ' in {!r}'.format(context) if context else ''
),
Style.RESET_ALL, Style.RESET_ALL,
sep='', sep='',
file=sys.stderr, file=sys.stderr,

View File

@ -45,39 +45,37 @@ setup(
description='Bonobo', description='Bonobo',
license='Apache License, Version 2.0', license='Apache License, Version 2.0',
install_requires=[ install_requires=[
'colorama >=0.3,<1.0', 'fs >=2.0,<3.0', 'psutil >=5.2,<6.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'
'requests >=2.0,<3.0', 'stevedore >=1.21,<2.0'
], ],
version=version, version=version,
long_description=read('README.rst'), long_description=read('README.rst'),
classifiers=read('classifiers.txt', tolines), classifiers=read('classifiers.txt', tolines),
packages=find_packages(exclude=['ez_setup', 'example', 'test']), packages=find_packages(exclude=['ez_setup', 'example', 'test']),
include_package_data=True, include_package_data=True,
data_files=[('share/jupyter/nbextensions/bonobo-jupyter', [ data_files=[
'bonobo/ext/jupyter/static/extension.js', (
'bonobo/ext/jupyter/static/index.js', 'share/jupyter/nbextensions/bonobo-jupyter', [
'bonobo/ext/jupyter/static/extension.js', 'bonobo/ext/jupyter/static/index.js',
'bonobo/ext/jupyter/static/index.js.map' 'bonobo/ext/jupyter/static/index.js.map'
])], ]
)
],
extras_require={ extras_require={
'dev': [ 'dev': [
'coverage >=4,<5', 'pylint >=1,<2', 'pytest >=3,<4', 'coverage >=4,<5', 'pylint >=1,<2', 'pytest >=3,<4', 'pytest-cov >=2,<3', 'pytest-timeout >=1,<2', 'sphinx',
'pytest-cov >=2,<3', 'pytest-timeout >=1,<2', 'sphinx',
'sphinx_rtd_theme', 'yapf' 'sphinx_rtd_theme', 'yapf'
], ],
'jupyter': ['jupyter >=1.0,<1.1', 'ipywidgets >=6.0.0.beta5'] 'jupyter': ['jupyter >=1.0,<1.1', 'ipywidgets >=6.0.0.beta5']
}, },
entry_points={ entry_points={
'bonobo.commands': [ 'bonobo.commands': [
'init = bonobo.commands.init:register', 'init = bonobo.commands.init:register', 'run = bonobo.commands.run:register',
'run = bonobo.commands.run:register',
'version = bonobo.commands.version:register' 'version = bonobo.commands.version:register'
], ],
'console_scripts': ['bonobo = bonobo.commands:entrypoint'], 'console_scripts': ['bonobo = bonobo.commands:entrypoint'],
'edgy.project.features': 'edgy.project.features': ['bonobo = '
['bonobo = '
'bonobo.ext.edgy.project.feature:BonoboFeature'] 'bonobo.ext.edgy.project.feature:BonoboFeature']
}, },
url='https://www.bonobo-project.org/', url='https://www.bonobo-project.org/',
download_url= download_url='https://github.com/python-bonobo/bonobo/tarball/{version}'.format(version=version),
'https://github.com/python-bonobo/bonobo/tarball/{version}'.format( )
version=version), )