[misc] Fixes formatting.
This commit is contained in:
@ -51,7 +51,7 @@ class ConfigurableMeta(type):
|
|||||||
return (processor for _, processor in cls.__processors)
|
return (processor for _, processor in cls.__processors)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return ' '.join(('<Configurable', super(ConfigurableMeta, self).__repr__().split(' ', 1)[1],))
|
return ' '.join(('<Configurable', super(ConfigurableMeta, self).__repr__().split(' ', 1)[1], ))
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -61,6 +61,7 @@ except:
|
|||||||
|
|
||||||
PartiallyConfigured = functools.partial
|
PartiallyConfigured = functools.partial
|
||||||
else:
|
else:
|
||||||
|
|
||||||
class PartiallyConfigured(_functools.partial):
|
class PartiallyConfigured(_functools.partial):
|
||||||
@property # TODO XXX cache this shit
|
@property # TODO XXX cache this shit
|
||||||
def _options_values(self):
|
def _options_values(self):
|
||||||
@ -160,9 +161,7 @@ class Configurable(metaclass=ConfigurableMeta):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
# initialize option's value dictionary, used by descriptor implementation (see Option).
|
# initialize option's value dictionary, used by descriptor implementation (see Option).
|
||||||
self._options_values = {
|
self._options_values = {**kwargs}
|
||||||
**kwargs
|
|
||||||
}
|
|
||||||
|
|
||||||
# set option values.
|
# set option values.
|
||||||
for name, value in kwargs.items():
|
for name, value in kwargs.items():
|
||||||
|
|||||||
@ -130,13 +130,12 @@ class Method(Option):
|
|||||||
|
|
||||||
def __set__(self, inst, value):
|
def __set__(self, inst, value):
|
||||||
if not hasattr(value, '__call__'):
|
if not hasattr(value, '__call__'):
|
||||||
raise TypeError('Option of type {!r} is expecting a callable value, got {!r} object (which is not).'.format(
|
raise TypeError(
|
||||||
type(self).__name__, type(value).__name__))
|
'Option of type {!r} is expecting a callable value, got {!r} object (which is not).'.
|
||||||
|
format(type(self).__name__, type(value).__name__)
|
||||||
|
)
|
||||||
inst._options_values[self.name] = self.type(value) if self.type else value
|
inst._options_values[self.name] = self.type(value) if self.type else value
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
# only here to trick IDEs into thinking this is callable.
|
# only here to trick IDEs into thinking this is callable.
|
||||||
raise NotImplementedError('You cannot call the descriptor')
|
raise NotImplementedError('You cannot call the descriptor')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -73,15 +73,15 @@ def display(row):
|
|||||||
|
|
||||||
print(
|
print(
|
||||||
' - {}address{}: {address}'.
|
' - {}address{}: {address}'.
|
||||||
format(Fore.BLUE, Style.RESET_ALL, address=', '.join(address))
|
format(Fore.BLUE, Style.RESET_ALL, address=', '.join(address))
|
||||||
)
|
)
|
||||||
print(
|
print(
|
||||||
' - {}links{}: {links}'.
|
' - {}links{}: {links}'.
|
||||||
format(Fore.BLUE, Style.RESET_ALL, links=', '.join(row['links']))
|
format(Fore.BLUE, Style.RESET_ALL, links=', '.join(row['links']))
|
||||||
)
|
)
|
||||||
print(
|
print(
|
||||||
' - {}geometry{}: {geometry}'.
|
' - {}geometry{}: {geometry}'.
|
||||||
format(Fore.BLUE, Style.RESET_ALL, **row)
|
format(Fore.BLUE, Style.RESET_ALL, **row)
|
||||||
)
|
)
|
||||||
print(
|
print(
|
||||||
' - {}source{}: {source}'.format(
|
' - {}source{}: {source}'.format(
|
||||||
|
|||||||
@ -12,7 +12,7 @@ class IOFormatEnabled(Configurable):
|
|||||||
if len(args) != 1 or len(kwargs):
|
if len(args) != 1 or len(kwargs):
|
||||||
raise UnrecoverableValueError(
|
raise UnrecoverableValueError(
|
||||||
'Wrong input formating: IOFORMAT=ARG0 implies one arg and no kwargs, got args={!r} and kwargs={!r}.'.
|
'Wrong input formating: IOFORMAT=ARG0 implies one arg and no kwargs, got args={!r} and kwargs={!r}.'.
|
||||||
format(args, kwargs)
|
format(args, kwargs)
|
||||||
)
|
)
|
||||||
return args[0]
|
return args[0]
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ class IOFormatEnabled(Configurable):
|
|||||||
if len(args) or not len(kwargs):
|
if len(args) or not len(kwargs):
|
||||||
raise UnrecoverableValueError(
|
raise UnrecoverableValueError(
|
||||||
'Wrong input formating: IOFORMAT=KWARGS ioformat implies no arg, got args={!r} and kwargs={!r}.'.
|
'Wrong input formating: IOFORMAT=KWARGS ioformat implies no arg, got args={!r} and kwargs={!r}.'.
|
||||||
format(args, kwargs)
|
format(args, kwargs)
|
||||||
)
|
)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|||||||
@ -68,14 +68,15 @@ def istype(mixed):
|
|||||||
return isinstance(mixed, type)
|
return isinstance(mixed, type)
|
||||||
|
|
||||||
|
|
||||||
ConfigurableInspection = namedtuple('ConfigurableInspection',
|
ConfigurableInspection = namedtuple(
|
||||||
[
|
'ConfigurableInspection', [
|
||||||
'type',
|
'type',
|
||||||
'instance',
|
'instance',
|
||||||
'options',
|
'options',
|
||||||
'processors',
|
'processors',
|
||||||
'partial',
|
'partial',
|
||||||
])
|
]
|
||||||
|
)
|
||||||
|
|
||||||
ConfigurableInspection.__enter__ = lambda self: self
|
ConfigurableInspection.__enter__ = lambda self: self
|
||||||
ConfigurableInspection.__exit__ = lambda *exc_details: None
|
ConfigurableInspection.__exit__ = lambda *exc_details: None
|
||||||
@ -103,7 +104,8 @@ def inspect_node(mixed, *, _partial=None):
|
|||||||
return inspect_node(mixed.func, _partial=(mixed.args, mixed.keywords))
|
return inspect_node(mixed.func, _partial=(mixed.args, mixed.keywords))
|
||||||
else:
|
else:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
'Not a Configurable, nor a Configurable instance and not even a partially configured Configurable. Check your inputs.')
|
'Not a Configurable, nor a Configurable instance and not even a partially configured Configurable. Check your inputs.'
|
||||||
|
)
|
||||||
|
|
||||||
return ConfigurableInspection(
|
return ConfigurableInspection(
|
||||||
typ,
|
typ,
|
||||||
|
|||||||
@ -134,4 +134,3 @@ def test_no_opt_configurable():
|
|||||||
|
|
||||||
with inspect_node(o) as ni:
|
with inspect_node(o) as ni:
|
||||||
assert not ni.partial
|
assert not ni.partial
|
||||||
|
|
||||||
|
|||||||
@ -50,7 +50,7 @@ def test_define_with_decorator():
|
|||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
def my_handler(*args, **kwargs):
|
def my_handler(*args, **kwargs):
|
||||||
calls.append((args, kwargs,))
|
calls.append((args, kwargs, ))
|
||||||
|
|
||||||
Concrete = MethodBasedConfigurable(my_handler)
|
Concrete = MethodBasedConfigurable(my_handler)
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ def test_late_binding_method_decoration():
|
|||||||
|
|
||||||
@MethodBasedConfigurable(foo='foo')
|
@MethodBasedConfigurable(foo='foo')
|
||||||
def Concrete(*args, **kwargs):
|
def Concrete(*args, **kwargs):
|
||||||
calls.append((args, kwargs,))
|
calls.append((args, kwargs, ))
|
||||||
|
|
||||||
assert callable(Concrete.handler)
|
assert callable(Concrete.handler)
|
||||||
t = Concrete(bar='baz')
|
t = Concrete(bar='baz')
|
||||||
@ -89,7 +89,7 @@ def test_define_with_argument():
|
|||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
def concrete_handler(*args, **kwargs):
|
def concrete_handler(*args, **kwargs):
|
||||||
calls.append((args, kwargs,))
|
calls.append((args, kwargs, ))
|
||||||
|
|
||||||
t = MethodBasedConfigurable(concrete_handler, 'foo', bar='baz')
|
t = MethodBasedConfigurable(concrete_handler, 'foo', bar='baz')
|
||||||
assert callable(t.handler)
|
assert callable(t.handler)
|
||||||
@ -103,7 +103,7 @@ def test_define_with_inheritance():
|
|||||||
|
|
||||||
class Inheriting(MethodBasedConfigurable):
|
class Inheriting(MethodBasedConfigurable):
|
||||||
def handler(self, *args, **kwargs):
|
def handler(self, *args, **kwargs):
|
||||||
calls.append((args, kwargs,))
|
calls.append((args, kwargs, ))
|
||||||
|
|
||||||
t = Inheriting('foo', bar='baz')
|
t = Inheriting('foo', bar='baz')
|
||||||
assert callable(t.handler)
|
assert callable(t.handler)
|
||||||
@ -120,7 +120,7 @@ def test_inheritance_then_decorate():
|
|||||||
|
|
||||||
@Inheriting
|
@Inheriting
|
||||||
def Concrete(*args, **kwargs):
|
def Concrete(*args, **kwargs):
|
||||||
calls.append((args, kwargs,))
|
calls.append((args, kwargs, ))
|
||||||
|
|
||||||
assert callable(Concrete.handler)
|
assert callable(Concrete.handler)
|
||||||
t = Concrete('foo', bar='baz')
|
t = Concrete('foo', bar='baz')
|
||||||
|
|||||||
@ -40,7 +40,7 @@ def test_partial():
|
|||||||
assert len(ci.options) == 4
|
assert len(ci.options) == 4
|
||||||
assert len(ci.processors) == 1
|
assert len(ci.processors) == 1
|
||||||
assert ci.partial
|
assert ci.partial
|
||||||
assert ci.partial[0] == (f1,)
|
assert ci.partial[0] == (f1, )
|
||||||
assert not len(ci.partial[1])
|
assert not len(ci.partial[1])
|
||||||
|
|
||||||
# instanciate a more complete partial instance ...
|
# instanciate a more complete partial instance ...
|
||||||
@ -53,7 +53,7 @@ def test_partial():
|
|||||||
assert len(ci.options) == 4
|
assert len(ci.options) == 4
|
||||||
assert len(ci.processors) == 1
|
assert len(ci.processors) == 1
|
||||||
assert ci.partial
|
assert ci.partial
|
||||||
assert ci.partial[0] == (f1, f2,)
|
assert ci.partial[0] == (f1, f2, )
|
||||||
assert not len(ci.partial[1])
|
assert not len(ci.partial[1])
|
||||||
|
|
||||||
c = C('foo')
|
c = C('foo')
|
||||||
|
|||||||
@ -99,9 +99,7 @@ def test_exclusive():
|
|||||||
def test_requires():
|
def test_requires():
|
||||||
vcr = VCR()
|
vcr = VCR()
|
||||||
|
|
||||||
services = Container(
|
services = Container(output=vcr.append)
|
||||||
output=vcr.append
|
|
||||||
)
|
|
||||||
|
|
||||||
@requires('output')
|
@requires('output')
|
||||||
def append(out, x):
|
def append(out, x):
|
||||||
@ -110,7 +108,3 @@ def test_requires():
|
|||||||
svcargs = services.args_for(append)
|
svcargs = services.args_for(append)
|
||||||
assert len(svcargs) == 1
|
assert len(svcargs) == 1
|
||||||
assert svcargs[0] == vcr.append
|
assert svcargs[0] == vcr.append
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user