Minor fixes and update documentation. Preparing the upcoming 0.2 release.
This commit is contained in:
@ -1,30 +1,31 @@
|
||||
""" Bonobo data-processing toolkit.
|
||||
# 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.
|
||||
#
|
||||
# Licensed under Apache License 2.0, read the LICENSE file in the root of the source tree.
|
||||
|
||||
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.
|
||||
"""Bonobo data-processing toolkit main module."""
|
||||
|
||||
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 sys
|
||||
import warnings
|
||||
|
||||
assert (sys.version_info >= (3, 5)), 'Python 3.5+ is required to use Bonobo.'
|
||||
|
||||
from ._version import __version__
|
||||
from .config import __all__ as __all_config__
|
||||
from .context import __all__ as __all_context__
|
||||
from .core import __all__ as __all_core__
|
||||
from .io import __all__ as __all_io__
|
||||
from .util import __all__ as __all_util__
|
||||
|
||||
__all__ = __all_config__ + __all_context__ + __all_core__ + __all_io__ + __all_util__ + [
|
||||
'__version__',
|
||||
'create_strategy',
|
||||
'get_examples_path',
|
||||
'run',
|
||||
]
|
||||
|
||||
from .config import *
|
||||
from .context import *
|
||||
from .core import *
|
||||
@ -40,56 +41,43 @@ STRATEGIES = {
|
||||
}
|
||||
|
||||
|
||||
def run(graph, *chain, strategy=None, plugins=None):
|
||||
def get_examples_path(*pathsegments):
|
||||
import os
|
||||
import pathlib
|
||||
return str(pathlib.Path(os.path.dirname(__file__), 'examples', *pathsegments))
|
||||
|
||||
|
||||
def create_strategy(name=None):
|
||||
from bonobo.core.strategies.base import Strategy
|
||||
import logging
|
||||
|
||||
if isinstance(name, Strategy):
|
||||
return name
|
||||
|
||||
if name is None:
|
||||
name = DEFAULT_STRATEGY
|
||||
|
||||
logging.debug('Creating strategy {}...'.format(name))
|
||||
|
||||
try:
|
||||
factory = STRATEGIES[name]
|
||||
except KeyError as exc:
|
||||
raise RuntimeError('Invalid strategy {}. Available choices: {}.'.format(repr(name), ', '.join(
|
||||
sorted(STRATEGIES.keys())))) from exc
|
||||
|
||||
return factory()
|
||||
|
||||
|
||||
def run(graph, *chain, strategy=None, plugins=None):
|
||||
strategy = create_strategy(strategy)
|
||||
|
||||
if len(chain):
|
||||
warnings.warn('DEPRECATED. You should pass a Graph instance instead of a chain.')
|
||||
from bonobo import Graph
|
||||
graph = Graph(graph, *chain)
|
||||
|
||||
if not isinstance(strategy, Strategy):
|
||||
if strategy is None:
|
||||
strategy = DEFAULT_STRATEGY
|
||||
|
||||
try:
|
||||
strategy = STRATEGIES[strategy]
|
||||
except KeyError as exc:
|
||||
raise RuntimeError('Invalid strategy {}.'.format(repr(strategy))) from exc
|
||||
|
||||
strategy = strategy()
|
||||
|
||||
return strategy.execute(graph, plugins=plugins)
|
||||
|
||||
|
||||
__all__ = [
|
||||
'Bag',
|
||||
'Configurable',
|
||||
'ContextProcessor',
|
||||
'contextual',
|
||||
'CsvReader',
|
||||
'CsvWriter',
|
||||
'FileReader',
|
||||
'FileWriter',
|
||||
'Graph',
|
||||
'JsonReader',
|
||||
'JsonWriter',
|
||||
'NOT_MODIFIED',
|
||||
'NaiveStrategy',
|
||||
'Option',
|
||||
'ProcessPoolExecutorStrategy',
|
||||
'ThreadPoolExecutorStrategy',
|
||||
'__version__',
|
||||
'console_run',
|
||||
'inject',
|
||||
'jupyter_run',
|
||||
'limit',
|
||||
'log',
|
||||
'noop',
|
||||
'pprint',
|
||||
'service',
|
||||
'tee',
|
||||
]
|
||||
|
||||
del warnings
|
||||
del sys
|
||||
del warnings
|
||||
|
||||
Reference in New Issue
Block a user