ConfigSet: a special dict
The values put in ConfigSet must be serializable (dicts, lists, strings)
Bases: object
A copy-on-write dict with human-readable serialized format. 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:
Attribute access provided for convenience. The following forms are equivalent:
Attribute access provided for convenience. The following forms are equivalent:
Attribute access provided for convenience. The following forms are equivalent:
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.
Detaches this instance from its parent (if present)
Modifying the parent ConfigSet will not change the current object Modifying this ConfigSet will not modify the parent one.
Returns a value as a string. If the input is a list, the value returned is space-separated.
Parameters: | key (string) – key to use |
---|
Returns 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
Appends 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
Computes the merged dictionary from the fusion of self and all its parent
Return type: | a ConfigSet object |
---|
Serializes the ConfigSet data to a file. See ConfigSet.load() for reading such files.
Parameters: | filename (string) – file to use |
---|
Restores contents from a file (current values are not cleared). Files are written using ConfigSet.store().
Parameters: | filename (string) – file to use |
---|
Dictionary interface: replace values with the ones from another dict
Parameters: | d (dict-like object) – object to use the value from |
---|
Stores the object state to provide transactionality semantics:
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()
Commits transactional changes. See ConfigSet.stash()
Reverts the object to a previous state. See ConfigSet.stash()