attempt to improve landscape scores. (#6)

This commit is contained in:
Romain Dorgueil
2016-12-26 13:01:49 +01:00
committed by GitHub
parent b658c1f536
commit 8b42ff0bc3
16 changed files with 132 additions and 82 deletions

View File

@ -8,3 +8,7 @@ python-targets:
ignore-paths: ignore-paths:
- docs - docs
- examples - examples
pep257:
disable:
- D205
- D210

View File

@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier same "printed page" as the copyright notice for easier
identification within third-party archives. identification within third-party archives.
Copyright {yyyy} {name of copyright owner} Copyright 2012-2017 Romain Dorgueil
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -1,4 +1,27 @@
""" Bonobo data-processing toolkit.
Bonobo is a line-by-line data-processing toolkit for python 3.5+ emphasizing simplicity and atomicity of data
transformations using a simple directed graph of python callables.
Read more at http://docs.bonobo-project.org/
Copyright 2012-2014 Romain Dorgueil
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import os
import sys import sys
from .core import * from .core import *
from .io import * from .io import *
from .util import * from .util import *
@ -8,8 +31,21 @@ PY35 = (sys.version_info >= (3, 5))
assert PY35, 'Python 3.5+ is required to use Bonobo.' assert PY35, 'Python 3.5+ is required to use Bonobo.'
# Version infos # Version infos
try: with open(os.path.realpath(os.path.join(os.path.dirname(__file__), '../version.txt'))) as f:
with open('../version.txt') as f: __version__ = f.read().strip()
__version__ = f.read().strip()
except Exception as e: __all__ = [
__version__ = 'dev' 'Bag',
'Graph',
'NaiveStrategy',
'NotModified',
'ProcessPoolExecutorStrategy',
'ThreadPoolExecutorStrategy',
'head',
'inject',
'log',
'noop',
'service',
'tee',
'to_json',
]

View File

@ -1,3 +1,5 @@
""" Core required libraries. """
from .bags import Bag from .bags import Bag
from .graphs import Graph from .graphs import Graph
from .services import inject, service from .services import inject, service

View File

@ -21,7 +21,7 @@ class ExecutionContext:
for i, component_context in enumerate(self): for i, component_context in enumerate(self):
try: try:
component_context.outputs = [self[j].input for j in self.graph.outputs_of(i)] component_context.outputs = [self[j].input for j in self.graph.outputs_of(i)]
except KeyError as e: except KeyError:
continue continue
component_context.input.on_begin = partial(component_context.send, Begin, _control=True) component_context.input.on_begin = partial(component_context.send, Begin, _control=True)
component_context.input.on_end = partial(component_context.send, End, _control=True) component_context.input.on_end = partial(component_context.send, End, _control=True)
@ -55,23 +55,23 @@ class PluginExecutionContext:
def run(self): def run(self):
try: try:
get_initializer(self.plugin)(self) get_initializer(self.plugin)(self)
except Exception as e: except Exception as exc:
print('error in initializer', type(e), e) print('error in initializer', type(exc), exc)
while self.alive: while self.alive:
# todo with wrap_errors .... # todo with wrap_errors ....
try: try:
self.plugin.run(self) self.plugin.run(self)
except Exception as e: except Exception as exc:
print('error', type(e), e) print('error', type(exc), exc)
sleep(0.25) sleep(0.25)
try: try:
get_finalizer(self.plugin)(self) get_finalizer(self.plugin)(self)
except Exception as e: except Exception as exc:
print('error in finalizer', type(e), e) print('error in finalizer', type(exc), exc)
def shutdown(self): def shutdown(self):
self.alive = False self.alive = False
@ -193,35 +193,23 @@ class ComponentExecutionContext(WithStatistics):
while True: while True:
try: try:
output = next(outputs) output = next(outputs)
except StopIteration as e: except StopIteration:
break break
self.send(_resolve(input_bag, output)) self.send(_resolve(input_bag, output))
def run(self): def initialize(self):
assert self.state is New, ('A {} can only be run once, and thus is expected to be in {} state at the ' assert self.state is New, ('A {} can only be run once, and thus is expected to be in {} state at '
'beginning of a run().').format(type(self).__name__, New) 'initialization time.').format(type(self).__name__, New)
self.state = Running self.state = Running
try: try:
get_initializer(self.component)(self) get_initializer(self.component)(self)
except Exception as e: except Exception as e:
self.handle_error(e, traceback.format_exc()) self.handle_error(e, traceback.format_exc())
while True: def finalize(self):
try: assert self.state is Running, ('A {} must be in {} state at finalization time.').format(
self.step()
except KeyboardInterrupt as e:
raise
except InactiveReadableError as e:
sleep(1)
# Terminated, exit loop.
break # BREAK !!!
except Empty as e:
continue
except Exception as e:
self.handle_error(e, traceback.format_exc())
assert self.state is Running, ('A {} must be in {} state when finalization starts.').format(
type(self).__name__, Running) type(self).__name__, Running)
self.state = Terminated self.state = Terminated
@ -230,6 +218,25 @@ class ComponentExecutionContext(WithStatistics):
except Exception as e: except Exception as e:
self.handle_error(e, traceback.format_exc()) self.handle_error(e, traceback.format_exc())
def run(self):
self.initialize()
while True:
try:
self.step()
except KeyboardInterrupt:
raise
except InactiveReadableError:
sleep(1)
# Terminated, exit loop.
break # BREAK !!!
except Empty as e:
continue
except Exception as e:
self.handle_error(e, traceback.format_exc())
self.finalize()
def handle_error(self, exc, tb): def handle_error(self, exc, tb):
self.stats['err'] += 1 self.stats['err'] += 1
print('\U0001F4A3 {} in {}'.format(type(exc).__name__, self.component)) print('\U0001F4A3 {} in {}'.format(type(exc).__name__, self.component))

View File

@ -20,8 +20,8 @@ class Graph:
self.components.append(c) self.components.append(c)
return i return i
def add_chain(self, *components, input=Begin): def add_chain(self, *components, _input=Begin):
for component in components: for component in components:
next = self.add_component(component) _next = self.add_component(component)
self.outputs_of(input, create=True).add(next) self.outputs_of(_input, create=True).add(_next)
input = next _input = _next

View File

@ -3,9 +3,7 @@ from concurrent.futures import Executor
from concurrent.futures import ProcessPoolExecutor from concurrent.futures import ProcessPoolExecutor
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from bonobo.core.bags import Bag
from bonobo.core.strategies.base import Strategy from bonobo.core.strategies.base import Strategy
from bonobo.util.tokens import Begin, End
class ExecutorStrategy(Strategy): class ExecutorStrategy(Strategy):

View File

@ -0,0 +1 @@
""" Extensions, not required. """

View File

@ -2,6 +2,6 @@ from .helpers import console_run
from .plugin import ConsoleOutputPlugin from .plugin import ConsoleOutputPlugin
__all__ = [ __all__ = [
ConsoleOutputPlugin, 'ConsoleOutputPlugin',
console_run, 'console_run',
] ]

View File

@ -7,7 +7,6 @@ def _jupyter_nbextension_paths():
__all__ = [ __all__ = [
JupyterOutputPlugin, 'JupyterOutputPlugin',
_jupyter_nbextension_paths, 'jupyter_run',
jupyter_run,
] ]

View File

@ -1,5 +1,6 @@
from IPython.core.display import display from IPython.core.display import display
from bonobo.core.plugins import Plugin
from bonobo.ext.jupyter.widget import BonoboWidget from bonobo.ext.jupyter.widget import BonoboWidget

View File

@ -6,26 +6,26 @@ USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.
def create_profile(use_tor=False): def create_profile(use_tor=False):
profile = webdriver.FirefoxProfile() _profile = webdriver.FirefoxProfile()
profile.set_preference("toolkit.startup.max_resumed_crashes", "-1") _profile.set_preference("toolkit.startup.max_resumed_crashes", "-1")
if use_tor: if use_tor:
# tor connection # tor connection
profile.set_preference('network.proxy.type', 1) _profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', '127.0.0.1') _profile.set_preference('network.proxy.socks', '127.0.0.1')
profile.set_preference('network.proxy.socks_port', 9050) _profile.set_preference('network.proxy.socks_port', 9050)
# user agent # user agent
profile.set_preference("general.useragent.override", USER_AGENT) _profile.set_preference("general.useragent.override", USER_AGENT)
return profile return _profile
def create_browser(profile): def create_browser(profile):
browser = webdriver.Firefox(profile) _browser = webdriver.Firefox(profile)
browser.implicitly_wait(10) _browser.implicitly_wait(10)
browser.set_page_load_timeout(10) _browser.set_page_load_timeout(10)
return browser return _browser
@service @service

View File

@ -1 +1,5 @@
""" Readers and writers for common file formats. """
from .json import * from .json import *
__all__ = ['to_json', ]

View File

@ -1,3 +1,5 @@
""" Various simple utilities. """
import functools import functools
import pprint import pprint

View File

@ -86,11 +86,9 @@ html_sidebars = {
] ]
} }
html_theme_path = ['_themes'] html_theme_path = ['_themes']
html_additional_pages = {'index': 'index.html'} html_additional_pages = {'index': 'index.html'}
# Add any paths that contain custom static files (such as style sheets) here, # Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files, # relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css". # so a file named "default.css" will overwrite the builtin "default.css".

View File

@ -5,40 +5,38 @@ from setuptools import setup, find_packages
tolines = lambda c: list(filter(None, map(lambda s: s.strip(), c.split('\n')))) tolines = lambda c: list(filter(None, map(lambda s: s.strip(), c.split('\n'))))
def read(filename, flt=None): def read(filename, flt=None):
with open(filename) as f: with open(filename) as f:
content = f.read().strip() content = f.read().strip()
return flt(content) if callable(flt) else content return flt(content) if callable(flt) else content
try: try:
version = read('version.txt') version = read('version.txt')
except: except:
version = 'dev' version = 'dev'
setup( setup(
name = 'bonobo', name='bonobo',
description = 'Bonobo', description='Bonobo',
license = 'Apache License, Version 2.0', license='Apache License, Version 2.0',
install_requires = ['blessings >=1.6,<1.7', 'psutil >=5.0,<5.1'], install_requires=['blessings >=1.6,<1.7', 'psutil >=5.0,<5.1'],
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=[('share/jupyter/nbextensions/bonobo-jupyter', [
['bonobo/ext/jupyter/static/extension.js', 'bonobo/ext/jupyter/static/extension.js', 'bonobo/ext/jupyter/static/index.js',
'bonobo/ext/jupyter/static/index.js', 'bonobo/ext/jupyter/static/index.js.map'
'bonobo/ext/jupyter/static/index.js.map'])], ])],
extras_require = {'dev': ['coverage >=4.2,<4.3', extras_require={
'mock >=2.0,<2.1', 'dev': [
'nose >=1.3,<1.4', 'coverage >=4.2,<4.3', 'mock >=2.0,<2.1', 'nose >=1.3,<1.4', 'pylint >=1.6,<1.7', 'pytest >=3,<4',
'pylint >=1.6,<1.7', 'pytest-cov >=2.4,<2.5', 'sphinx', 'sphinx_rtd_theme', 'yapf'
'pytest >=3,<4', ],
'pytest-cov >=2.4,<2.5', 'jupyter': ['jupyter >=1.0,<1.1', 'ipywidgets >=6.0.0.beta5']
'sphinx', },
'sphinx_rtd_theme', url='https://github.com/python-bonobo/bonobo',
'yapf'], download_url='https://github.com/python-bonobo/bonobo/tarball/{version}'.format(version=version), )
'jupyter': ['jupyter >=1.0,<1.1', 'ipywidgets >=6.0.0.beta5']},
url = 'https://github.com/python-bonobo/bonobo',
download_url = 'https://github.com/python-bonobo/bonobo/tarball/{version}'.format(version=version),
)