Adding warnings to transformation factory, and code formating.

This commit is contained in:
Romain Dorgueil
2017-09-30 11:58:37 +02:00
parent b26dbc83cb
commit ef938c9970
4 changed files with 30 additions and 19 deletions

View File

@ -44,8 +44,9 @@ def resolve_factory(name, filename, factory_type):
if not name in REGISTRY:
raise RuntimeError(
'Could not resolve {factory_type} factory for {filename} ({name}). Try providing it explicitely using -{opt} <format>.'.format(
name=name, filename=filename, factory_type=factory_type, opt=factory_type[0]))
'Could not resolve {factory_type} factory for {filename} ({name}). Try providing it explicitely using -{opt} <format>.'.
format(name=name, filename=filename, factory_type=factory_type, opt=factory_type[0])
)
if factory_type == READER:
return REGISTRY[name][0]
@ -62,9 +63,11 @@ def execute(input, output, reader=None, reader_options=None, writer=None, writer
graph = bonobo.Graph()
graph.add_chain(reader, writer)
return bonobo.run(graph, services={
'fs': bonobo.open_fs(),
})
return bonobo.run(
graph, services={
'fs': bonobo.open_fs(),
}
)
def register(parser):

View File

@ -48,7 +48,6 @@ def normalize(row):
return result
def display(row):
print(Style.BRIGHT, row.get('name'), Style.RESET_ALL, sep='')
@ -69,15 +68,15 @@ def display(row):
print(
' - {}address{}: {address}'.
format(Fore.BLUE, Style.RESET_ALL, address=', '.join(address))
format(Fore.BLUE, Style.RESET_ALL, address=', '.join(address))
)
print(
' - {}links{}: {links}'.
format(Fore.BLUE, Style.RESET_ALL, links=', '.join(row['links']))
format(Fore.BLUE, Style.RESET_ALL, links=', '.join(row['links']))
)
print(
' - {}geometry{}: {geometry}'.
format(Fore.BLUE, Style.RESET_ALL, **row)
format(Fore.BLUE, Style.RESET_ALL, **row)
)
print(
' - {}source{}: {source}'.format(
@ -87,7 +86,9 @@ def display(row):
graph = bonobo.Graph(
OpenDataSoftAPI(dataset=API_DATASET, netloc=API_NETLOC, timezone='Europe/Paris'),
OpenDataSoftAPI(
dataset=API_DATASET, netloc=API_NETLOC, timezone='Europe/Paris'
),
normalize,
bonobo.Filter(filter=lambda row: row.get('country') == 'France'),
bonobo.JsonWriter(path='fablabs.txt', ioformat='arg0'),

View File

@ -8,6 +8,7 @@ from bonobo.config import Configurable
from bonobo.nodes.factory import Factory
from bonobo.nodes.io.json import JsonDictReader
@Factory
def Normalize(self):
self[0].str().title()
@ -15,11 +16,11 @@ def Normalize(self):
self.move(0, 'address')
class PrettyPrinter(Configurable):
def call(self, *args, **kwargs):
for i, (item, value) in enumerate(itertools.chain(enumerate(args), kwargs.items())):
for i, (
item, value
) in enumerate(itertools.chain(enumerate(args), kwargs.items())):
print(' ' if i else '', item, '=', value)

View File

@ -1,8 +1,9 @@
import functools
import warnings
from functools import partial
from bonobo import Bag
from bonobo.config import Configurable, Method
from bonobo.config import Configurable
_isarg = lambda item: type(item) is int
_iskwarg = lambda item: type(item) is str
@ -110,7 +111,10 @@ class Cursor():
setattr(self, item, partial(_operation, self))
return getattr(self, item)
raise AttributeError('Unknown operation {}.{}().'.format(type(self).__name__, item, ))
raise AttributeError('Unknown operation {}.{}().'.format(
type(self).__name__,
item,
))
CURSOR_TYPES['default'] = Cursor
@ -139,12 +143,15 @@ CURSOR_TYPES['str'] = StringCursor
class Factory(Configurable):
setup = Method()
def __init__(self):
warnings.warn(
__file__ +
' is experimental, API may change in the future, use it as a preview only and knowing the risks.',
FutureWarning
)
super(Factory, self).__init__()
self.default_cursor_type = 'default'
self.operations = []
self.setup()
@factory_operation
def move(self, _from, _to, *args, **kwargs):
@ -186,7 +193,6 @@ if __name__ == '__main__':
print('operations:', f.operations)
print(f({'foo': 'bisou'}, foo='blah'))
'''
specs: