ConfigSet: a special dict
The values put in ConfigSet must be lists
Bases: object
A dict that honor serialization and parent relationships. The serialization format is human-readable (python-like) and performed by using eval() and repr(). For high performance prefer pickle. Do not store functions as they are not serializable.
The values can be accessed by attributes or by keys:
from waflib.ConfigSet import ConfigSet
env = ConfigSet()
env.FOO = 'test'
env['FOO'] = 'test'
Internal dict holding the object values
Dictionary interface: get value from key:
def configure(conf):
conf.env['foo'] = {}
print(env['foo'])
Attribute access provided for convenience. The following forms are equivalent:
def configure(conf):
conf.env.value
conf.env['value']
Attribute access provided for convenience. The following forms are equivalent:
def configure(conf):
conf.env.value = x
env['value'] = x
Attribute access provided for convenience. The following forms are equivalent:
def configure(conf):
del env.value
del env['value']
Returns a new ConfigSet deriving from self. The copy returned will be a shallow copy:
from waflib.ConfigSet import ConfigSet
env = ConfigSet()
env.append_value('CFLAGS', ['-O2'])
child = env.derive()
child.CFLAGS.append('test') # warning! this will modify 'env'
child.CFLAGS = ['-O3'] # new list, ok
child.append_value('CFLAGS', ['-O3']) # ok
Use ConfigSet.detach() to detach the child from the parent.
Detach self from its parent (if existing)
Modifying the parent ConfigSet will not change the current object Modifying this ConfigSet will not modify the parent one.
Return a value as a string. If the input is a list, the value returned is space-separated.
Parameters: | key (string) – key to use |
---|
Return a list value for further modification.
The list may be modified inplace and there is no need to do this afterwards:
self.table[var] = value
Appends a value to the specified config key:
def build(bld):
bld.env.append_value('CFLAGS', ['-O2'])
The value must be a list or a tuple
Prepends a value to the specified item:
def configure(conf):
conf.env.prepend_value('CFLAGS', ['-O2'])
The value must be a list or a tuple
Append a value to the specified item only if it’s not already present:
def build(bld):
bld.env.append_unique('CFLAGS', ['-O2', '-g'])
The value must be a list or a tuple
Compute the merged dictionary from the fusion of self and all its parent
Return type: | a ConfigSet object |
---|
Write the ConfigSet data into a file. See ConfigSet.load() for reading such files.
Parameters: | filename (string) – file to use |
---|
Retrieve the ConfigSet data from a file. See ConfigSet.store() for writing such files
Parameters: | filename (string) – file to use |
---|
Dictionary interface: replace values from another dict
Parameters: | d (dict-like object) – object to use the value from |
---|
Store the object state, to provide a kind of transaction support:
env = ConfigSet()
env.stash()
try:
env.append_value('CFLAGS', '-O3')
call_some_method(env)
finally:
env.revert()
The history is kept in a stack, and is lost during the serialization by ConfigSet.store()
Reverts the object to a previous state. See ConfigSet.stash()