Skip to content

Commit 8b42ff0

Browse files
authored
attempt to improve landscape scores. (#6)
1 parent b658c1f commit 8b42ff0

File tree

16 files changed

+127
-77
lines changed

16 files changed

+127
-77
lines changed

.landscape.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ python-targets:
88
ignore-paths:
99
- docs
1010
- examples
11+
pep257:
12+
disable:
13+
- D205
14+
- D210

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright 2012-2017 Romain Dorgueil
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

bonobo/__init__.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1+
""" Bonobo data-processing toolkit.
2+
3+
Bonobo is a line-by-line data-processing toolkit for python 3.5+ emphasizing simplicity and atomicity of data
4+
transformations using a simple directed graph of python callables.
5+
6+
Read more at http://docs.bonobo-project.org/
7+
8+
Copyright 2012-2014 Romain Dorgueil
9+
10+
Licensed under the Apache License, Version 2.0 (the "License");
11+
you may not use this file except in compliance with the License.
12+
You may obtain a copy of the License at
13+
14+
http://www.apache.org/licenses/LICENSE-2.0
15+
16+
Unless required by applicable law or agreed to in writing, software
17+
distributed under the License is distributed on an "AS IS" BASIS,
18+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
See the License for the specific language governing permissions and
20+
limitations under the License.
21+
"""
22+
import os
123
import sys
24+
225
from .core import *
326
from .io import *
427
from .util import *
@@ -8,8 +31,21 @@
831
assert PY35, 'Python 3.5+ is required to use Bonobo.'
932

1033
# Version infos
11-
try:
12-
with open('../version.txt') as f:
13-
__version__ = f.read().strip()
14-
except Exception as e:
15-
__version__ = 'dev'
34+
with open(os.path.realpath(os.path.join(os.path.dirname(__file__), '../version.txt'))) as f:
35+
__version__ = f.read().strip()
36+
37+
__all__ = [
38+
'Bag',
39+
'Graph',
40+
'NaiveStrategy',
41+
'NotModified',
42+
'ProcessPoolExecutorStrategy',
43+
'ThreadPoolExecutorStrategy',
44+
'head',
45+
'inject',
46+
'log',
47+
'noop',
48+
'service',
49+
'tee',
50+
'to_json',
51+
]

bonobo/core/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
""" Core required libraries. """
2+
13
from .bags import Bag
24
from .graphs import Graph
35
from .services import inject, service

bonobo/core/contexts.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, graph, plugins=None):
2121
for i, component_context in enumerate(self):
2222
try:
2323
component_context.outputs = [self[j].input for j in self.graph.outputs_of(i)]
24-
except KeyError as e:
24+
except KeyError:
2525
continue
2626
component_context.input.on_begin = partial(component_context.send, Begin, _control=True)
2727
component_context.input.on_end = partial(component_context.send, End, _control=True)
@@ -55,23 +55,23 @@ def __init__(self, plugin, parent):
5555
def run(self):
5656
try:
5757
get_initializer(self.plugin)(self)
58-
except Exception as e:
59-
print('error in initializer', type(e), e)
58+
except Exception as exc:
59+
print('error in initializer', type(exc), exc)
6060

6161
while self.alive:
6262
# todo with wrap_errors ....
6363

6464
try:
6565
self.plugin.run(self)
66-
except Exception as e:
67-
print('error', type(e), e)
66+
except Exception as exc:
67+
print('error', type(exc), exc)
6868

6969
sleep(0.25)
7070

7171
try:
7272
get_finalizer(self.plugin)(self)
73-
except Exception as e:
74-
print('error in finalizer', type(e), e)
73+
except Exception as exc:
74+
print('error in finalizer', type(exc), exc)
7575

7676
def shutdown(self):
7777
self.alive = False
@@ -193,26 +193,40 @@ def step(self):
193193
while True:
194194
try:
195195
output = next(outputs)
196-
except StopIteration as e:
196+
except StopIteration:
197197
break
198198
self.send(_resolve(input_bag, output))
199199

200-
def run(self):
201-
assert self.state is New, ('A {} can only be run once, and thus is expected to be in {} state at the '
202-
'beginning of a run().').format(type(self).__name__, New)
200+
def initialize(self):
201+
assert self.state is New, ('A {} can only be run once, and thus is expected to be in {} state at '
202+
'initialization time.').format(type(self).__name__, New)
203203

204204
self.state = Running
205+
205206
try:
206207
get_initializer(self.component)(self)
207208
except Exception as e:
208209
self.handle_error(e, traceback.format_exc())
209210

211+
def finalize(self):
212+
assert self.state is Running, ('A {} must be in {} state at finalization time.').format(
213+
type(self).__name__, Running)
214+
215+
self.state = Terminated
216+
try:
217+
get_finalizer(self.component)(self)
218+
except Exception as e:
219+
self.handle_error(e, traceback.format_exc())
220+
221+
def run(self):
222+
self.initialize()
223+
210224
while True:
211225
try:
212226
self.step()
213-
except KeyboardInterrupt as e:
227+
except KeyboardInterrupt:
214228
raise
215-
except InactiveReadableError as e:
229+
except InactiveReadableError:
216230
sleep(1)
217231
# Terminated, exit loop.
218232
break # BREAK !!!
@@ -221,14 +235,7 @@ def run(self):
221235
except Exception as e:
222236
self.handle_error(e, traceback.format_exc())
223237

224-
assert self.state is Running, ('A {} must be in {} state when finalization starts.').format(
225-
type(self).__name__, Running)
226-
227-
self.state = Terminated
228-
try:
229-
get_finalizer(self.component)(self)
230-
except Exception as e:
231-
self.handle_error(e, traceback.format_exc())
238+
self.finalize()
232239

233240
def handle_error(self, exc, tb):
234241
self.stats['err'] += 1

bonobo/core/graphs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def add_component(self, c):
2020
self.components.append(c)
2121
return i
2222

23-
def add_chain(self, *components, input=Begin):
23+
def add_chain(self, *components, _input=Begin):
2424
for component in components:
25-
next = self.add_component(component)
26-
self.outputs_of(input, create=True).add(next)
27-
input = next
25+
_next = self.add_component(component)
26+
self.outputs_of(_input, create=True).add(_next)
27+
_input = _next

bonobo/core/strategies/executor.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
from concurrent.futures import ProcessPoolExecutor
44
from concurrent.futures import ThreadPoolExecutor
55

6-
from bonobo.core.bags import Bag
76
from bonobo.core.strategies.base import Strategy
8-
from bonobo.util.tokens import Begin, End
97

108

119
class ExecutorStrategy(Strategy):

bonobo/ext/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
""" Extensions, not required. """

bonobo/ext/console/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
from .plugin import ConsoleOutputPlugin
33

44
__all__ = [
5-
ConsoleOutputPlugin,
6-
console_run,
5+
'ConsoleOutputPlugin',
6+
'console_run',
77
]

bonobo/ext/jupyter/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ def _jupyter_nbextension_paths():
77

88

99
__all__ = [
10-
JupyterOutputPlugin,
11-
_jupyter_nbextension_paths,
12-
jupyter_run,
10+
'JupyterOutputPlugin',
11+
'jupyter_run',
1312
]

0 commit comments

Comments
 (0)