Module registry reimported as it is needed for "bonobo convert".
This commit is contained in:
@ -1 +1 @@
|
|||||||
__version__ = '0.6-dev'
|
__version__ = '0.6.dev0'
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
|
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
|
|
||||||
from bonobo.constants import BEGIN, END
|
from bonobo.constants import BEGIN, END
|
||||||
|
|||||||
@ -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.compat import deprecated, deprecated_alias
|
||||||
from bonobo.util.inspect import (
|
from bonobo.util.inspect import (
|
||||||
inspect_node,
|
inspect_node,
|
||||||
@ -21,6 +21,7 @@ __all__ = [
|
|||||||
'ValueHolder',
|
'ValueHolder',
|
||||||
'deprecated',
|
'deprecated',
|
||||||
'deprecated_alias',
|
'deprecated_alias',
|
||||||
|
'ensure_tuple',
|
||||||
'get_attribute_or_create',
|
'get_attribute_or_create',
|
||||||
'get_name',
|
'get_name',
|
||||||
'inspect_node',
|
'inspect_node',
|
||||||
@ -34,4 +35,6 @@ __all__ = [
|
|||||||
'ismethod',
|
'ismethod',
|
||||||
'isoption',
|
'isoption',
|
||||||
'istype',
|
'istype',
|
||||||
|
'sortedlist',
|
||||||
|
'tuplize',
|
||||||
]
|
]
|
||||||
|
|||||||
@ -22,9 +22,9 @@ def ensure_tuple(tuple_or_mixed):
|
|||||||
|
|
||||||
|
|
||||||
def tuplize(generator):
|
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
|
Decorates a generator and make it a tuple-returning function. As a side effect, it can also decorate any
|
||||||
return value to be a tuple.
|
iterator-returning function to force return value to be a tuple.
|
||||||
|
|
||||||
>>> tuplized_lambda = tuplize(lambda: [1, 2, 3])
|
>>> tuplized_lambda = tuplize(lambda: [1, 2, 3])
|
||||||
>>> tuplized_lambda()
|
>>> tuplized_lambda()
|
||||||
|
|||||||
@ -4,10 +4,29 @@ This package is considered private, and should only be used within bonobo.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
import runpy
|
||||||
|
|
||||||
import bonobo
|
import bonobo
|
||||||
from bonobo.util.collections import tuplize
|
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):
|
def _parse_option(option):
|
||||||
@ -52,7 +71,7 @@ def _resolve_transformations(transformations):
|
|||||||
:param transformations: tuple(str)
|
:param transformations: tuple(str)
|
||||||
:return: tuple(object)
|
:return: tuple(object)
|
||||||
"""
|
"""
|
||||||
registry = WorkingDirectoryModulesRegistry()
|
registry = _ModulesRegistry()
|
||||||
for t in transformations:
|
for t in transformations:
|
||||||
try:
|
try:
|
||||||
mod, attr = t.split(':', 1)
|
mod, attr = t.split(':', 1)
|
||||||
|
|||||||
@ -1,6 +0,0 @@
|
|||||||
from bonobo.util.python import require
|
|
||||||
|
|
||||||
|
|
||||||
def test_require():
|
|
||||||
dummy = require('requireable.dummy')
|
|
||||||
assert dummy.foo == 'bar'
|
|
||||||
Reference in New Issue
Block a user