diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2012-12-13 14:33:53 +0100 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2012-12-13 14:33:53 +0100 |
commit | 0c2331cf53047d60f6507d416e13d5c00395ecf2 (patch) | |
tree | 8406313738a626b56931aecd8dc5684883c1d103 | |
parent | a1a73d8548c845536d15e849513949cf0f7ebae2 (diff) | |
download | logilab-common-0c2331cf53047d60f6507d416e13d5c00395ecf2.tar.gz |
[configuration] enhance merge_options function: copy option dictionaries and allow to ensure all options are in the same group using optional optgroup argument. Closes #113458
-rw-r--r-- | configuration.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/configuration.py b/configuration.py index 0eafa10..993f759 100644 --- a/configuration.py +++ b/configuration.py @@ -1,4 +1,4 @@ -# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This file is part of logilab-common. @@ -1055,8 +1055,13 @@ def read_old_config(newconfig, changes, configfile): newconfig.set_option(optname, oldconfig[optname], optdict=optdef) -def merge_options(options): - """preprocess options to remove duplicate""" +def merge_options(options, optgroup=None): + """preprocess a list of options and remove duplicates, returning a new list + (tuple actually) of options. + + Options dictionaries are copied to avoid later side-effect. Also, if + `otpgroup` argument is specified, ensure all options are in the given group. + """ alloptions = {} options = list(options) for i in range(len(options)-1, -1, -1): @@ -1065,5 +1070,9 @@ def merge_options(options): options.pop(i) alloptions[optname].update(optdict) else: + optdict = optdict.copy() + options[i] = (optname, optdict) alloptions[optname] = optdict + if optgroup is not None: + alloptions[optname]['group'] = optgroup return tuple(options) |