Skip to content

Commit

Permalink
:add: revision version
Browse files Browse the repository at this point in the history
  • Loading branch information
b3j0f committed Apr 3, 2016
1 parent c918799 commit d207510
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 17 deletions.
60 changes: 44 additions & 16 deletions b3j0f/conf/configurable/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def __init__(
*args, **kwargs
):
"""
:param Configuration conf: conf to use at instance level.
:param conf: conf to use at instance level.
:type conf: Configuration, Category or Parameter.
:param Iterable paths: paths to parse.
:param targets: object(s) to reconfigure. Such object may
implement the methods configure applyconfiguration and configure.
Expand Down Expand Up @@ -227,8 +228,10 @@ def _interception(self, joinpoint):

if self.callparams:

conf = self.getconf()

args, kwargs = self.getcallparams(
conf=self.getconf(), target=target, args=list(args), kwargs=kwargs,
conf=conf, target=target, args=list(args), kwargs=kwargs,
exec_ctx=joinpoint.exec_ctx.setdefault(self.exec_ctx, set())
)

Expand Down Expand Up @@ -356,19 +359,31 @@ def conf(self, value):
:type value: Category or Configuration
"""

if value is None:
value = Configuration()
self._conf = self._toconf(value)

elif isinstance(value, Category):
value = configuration(value)
if self.autoconf:
self.applyconfiguration()

elif isinstance(value, Parameter):
value = configuration(category('', value))
def _toconf(self, conf):
"""Convert input parameter to a Configuration.
self._conf = value
:param conf: configuration to convert to a Configuration object.
:type conf: Configuration, Category or Parameter.
if self.autoconf:
self.applyconfiguration()
:rtype: Configuration"""

result = conf

if result is None:
result = Configuration()

elif isinstance(result, Category):
result = configuration(result)

elif isinstance(result, Parameter):
result = configuration(category('', result))

return result

@property
def paths(self):
Expand Down Expand Up @@ -408,7 +423,8 @@ def applyconfiguration(
4. fill input conf with resolved parameters.
5. apply filled conf on targets.
:param Configuration conf: conf from where get conf.
:param conf: conf from where get conf.
:type conf: Configuration, Category or Parameter
:param paths: conf files to parse. If paths is a str, it is
automatically putted into a list.
:type paths: list of str
Expand Down Expand Up @@ -442,6 +458,8 @@ def applyconfiguration(
if keepstate is None:
keepstate = self.keepstate

conf = self._toconf(conf)

# get conf from drivers and paths
conf = self.getconf(
conf=conf, paths=paths, logger=logger, drivers=drivers
Expand All @@ -465,7 +483,8 @@ def applyconfiguration(
def getconf(self, conf=None, paths=None, drivers=None, logger=None):
"""Get a configuration from paths.
:param Configuration conf: conf to update. Default this conf.
:param conf: conf to update. Default this conf.
:type conf: Configuration, Category or Parameter
:param str(s) paths: list of conf files. Default this paths.
:param Logger logger: logger to use for logging info/error messages.
:param list drivers: ConfDriver to use. Default this drivers.
Expand All @@ -475,9 +494,16 @@ def getconf(self, conf=None, paths=None, drivers=None, logger=None):

result = None

conf = self._toconf(conf)

# start to initialize input params
if conf is None:
conf = self.conf
conf = self.conf.copy()

else:
selfconf = self.conf.copy()
selfconf.update(conf)
conf = selfconf

if paths is None:
paths = self.paths
Expand Down Expand Up @@ -528,8 +554,8 @@ def configure(
Specialization of this method is done in the _configure method.
:param Configuration conf: configuration model to configure. Default is
this conf.
:param conf: configuration model to configure. Default is this conf.
:type conf: Configuration, Category or Parameter
:param Iterable targets: objects to configure. self targets by default.
:param Logger logger: specific logger to use.
:param bool callconf: if True (False by default), the configuration is
Expand All @@ -543,6 +569,8 @@ def configure(

result = []

conf = self._toconf(conf)

if conf is None:
conf = self.conf

Expand Down
29 changes: 29 additions & 0 deletions b3j0f/conf/configurable/test/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,5 +440,34 @@ def __init__(self, param=None):

self.assertIsNot(test.subtest.param, oldsubtestparam)

def test_ptype(self):
"""Test application of ptype."""

conf = configuration(
category('test', Parameter('test', ptype=int, svalue='9'))
)

@Configurable(conf=conf)
class Test(object):

def __init__(self, test=None, *args, **kwargs):

super(Test, self).__init__(*args, **kwargs)

self.testy = test

test = Test()

self.assertEqual(test.testy, 9)
self.assertEqual(test.test, 9)

conf = conf.copy()
conf['test']['test'].svalue = '10'
conf['test']['test'].ptype = None

applyconfiguration(targets=[test], conf=conf)

self.assertEqual(test.test, 10)

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion b3j0f/conf/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
# thanks to https://github.com/pycontribs/jira/blob/master/jira/version.py

#: project version
__version__ = '0.3.8'
__version__ = '0.3.9'
6 changes: 6 additions & 0 deletions changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
ChangeLog
=========

0.3.9 (2016/04/03)
------------------

- improve the API in authorizing the use of Configuration, Category or Parameter when a configuration is requested.
- fix a bug when calling the applyconfiguration function with inheritance requirements between the default conf and a new conf.

0.3.8 (2016/04/02)
------------------

Expand Down

0 comments on commit d207510

Please sign in to comment.