Module registry reimported as it is needed for "bonobo convert".

This commit is contained in:
Romain Dorgueil
2017-11-01 12:46:03 +01:00
parent b6c7d598dc
commit 40a745fe08
6 changed files with 29 additions and 14 deletions

View File

@ -1 +1 @@
__version__ = '0.6-dev'
__version__ = '0.6.dev0'

View File

@ -15,7 +15,6 @@
# limitations under the License.
from abc import ABCMeta, abstractmethod
from queue import Queue
from bonobo.constants import BEGIN, END

View File

@ -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',
]

View File

@ -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()

View File

@ -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)

View File

@ -1,6 +0,0 @@
from bonobo.util.python import require
def test_require():
dummy = require('requireable.dummy')
assert dummy.foo == 'bar'