From 40a745fe083f620b98fe72b112ee3b5cc48026c2 Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Wed, 1 Nov 2017 12:46:03 +0100 Subject: [PATCH] Module registry reimported as it is needed for "bonobo convert". --- bonobo/_version.py | 2 +- bonobo/structs/inputs.py | 1 - bonobo/util/__init__.py | 5 ++++- bonobo/util/collections.py | 6 +++--- bonobo/util/resolvers.py | 23 +++++++++++++++++++++-- tests/util/test_python.py | 6 ------ 6 files changed, 29 insertions(+), 14 deletions(-) delete mode 100644 tests/util/test_python.py diff --git a/bonobo/_version.py b/bonobo/_version.py index ebc2ff2..2724bac 100644 --- a/bonobo/_version.py +++ b/bonobo/_version.py @@ -1 +1 @@ -__version__ = '0.6-dev' +__version__ = '0.6.dev0' diff --git a/bonobo/structs/inputs.py b/bonobo/structs/inputs.py index 7cfe12f..9b3cd14 100644 --- a/bonobo/structs/inputs.py +++ b/bonobo/structs/inputs.py @@ -15,7 +15,6 @@ # limitations under the License. from abc import ABCMeta, abstractmethod - from queue import Queue from bonobo.constants import BEGIN, END diff --git a/bonobo/util/__init__.py b/bonobo/util/__init__.py index 27e50b2..586fe3b 100644 --- a/bonobo/util/__init__.py +++ b/bonobo/util/__init__.py @@ -1,4 +1,4 @@ -from bonobo.util.collections import sortedlist, ensure_tuple +from bonobo.util.collections import ensure_tuple, sortedlist, tuplize from bonobo.util.compat import deprecated, deprecated_alias from bonobo.util.inspect import ( inspect_node, @@ -21,6 +21,7 @@ __all__ = [ 'ValueHolder', 'deprecated', 'deprecated_alias', + 'ensure_tuple', 'get_attribute_or_create', 'get_name', 'inspect_node', @@ -34,4 +35,6 @@ __all__ = [ 'ismethod', 'isoption', 'istype', + 'sortedlist', + 'tuplize', ] diff --git a/bonobo/util/collections.py b/bonobo/util/collections.py index d53a7da..31765c4 100644 --- a/bonobo/util/collections.py +++ b/bonobo/util/collections.py @@ -22,9 +22,9 @@ def ensure_tuple(tuple_or_mixed): def tuplize(generator): - """ Takes a generator and make it a tuple-returning function. As a side - effect, it can also decorate any iterator-returning function to force - return value to be a tuple. + """ + Decorates a generator and make it a tuple-returning function. As a side effect, it can also decorate any + iterator-returning function to force return value to be a tuple. >>> tuplized_lambda = tuplize(lambda: [1, 2, 3]) >>> tuplized_lambda() diff --git a/bonobo/util/resolvers.py b/bonobo/util/resolvers.py index 0590fc7..c4a1a90 100644 --- a/bonobo/util/resolvers.py +++ b/bonobo/util/resolvers.py @@ -4,10 +4,29 @@ This package is considered private, and should only be used within bonobo. """ import json +import os +import runpy import bonobo from bonobo.util.collections import tuplize -from bonobo.util.python import WorkingDirectoryModulesRegistry + + +class _RequiredModule: + def __init__(self, dct): + self.__dict__ = dct + + +class _ModulesRegistry(dict): + @property + def pathname(self): + return os.getcwd() + + def require(self, name): + if name not in self: + bits = name.split('.') + filename = os.path.join(self.pathname, *bits[:-1], bits[-1] + '.py') + self[name] = _RequiredModule(runpy.run_path(filename, run_name=name)) + return self[name] def _parse_option(option): @@ -52,7 +71,7 @@ def _resolve_transformations(transformations): :param transformations: tuple(str) :return: tuple(object) """ - registry = WorkingDirectoryModulesRegistry() + registry = _ModulesRegistry() for t in transformations: try: mod, attr = t.split(':', 1) diff --git a/tests/util/test_python.py b/tests/util/test_python.py deleted file mode 100644 index 6b1b591..0000000 --- a/tests/util/test_python.py +++ /dev/null @@ -1,6 +0,0 @@ -from bonobo.util.python import require - - -def test_require(): - dummy = require('requireable.dummy') - assert dummy.foo == 'bar'