ConfigSet

ConfigSet: a special dict

The values put in ConfigSet must be serializable (dicts, lists, strings)

class waflib.ConfigSet.ConfigSet(filename=None)[source]

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'
__slots__ = ('table', 'parent')
table

Internal dict holding the object values

__contains__(key)[source]

Enables the in syntax:

if 'foo' in env:
        print(env['foo'])
keys()[source]

Dict interface

__str__()[source]

Text representation of the ConfigSet (for debugging purposes)

__getitem__(key)[source]

Dictionary interface: get value from key:

def configure(conf):
        conf.env['foo'] = {}
        print(env['foo'])
__setitem__(key, value)[source]

Dictionary interface: set value from key

__delitem__(key)[source]

Dictionary interface: mark the value as missing

__getattr__(name)[source]

Attribute access provided for convenience. The following forms are equivalent:

def configure(conf):
        conf.env.value
        conf.env['value']
__setattr__(name, value)[source]

Attribute access provided for convenience. The following forms are equivalent:

def configure(conf):
        conf.env.value = x
        env['value'] = x
__delattr__(name)[source]

Attribute access provided for convenience. The following forms are equivalent:

def configure(conf):
        del env.value
        del env['value']
derive()[source]

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()[source]

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.

get_flat(key)[source]

Returns a value as a string. If the input is a list, the value returned is space-separated.

Parameters:key (string) – key to use
_get_list_value_for_modification(key)[source]

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
append_value(var, val)[source]

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

prepend_value(var, val)[source]

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_unique(var, val)[source]

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

get_merged_dict()[source]

Computes the merged dictionary from the fusion of self and all its parent

Return type:a ConfigSet object
store(filename)[source]

Serializes the ConfigSet data to a file. See ConfigSet.load() for reading such files.

Parameters:filename (string) – file to use
load(filename)[source]

Restores contents from a file (current values are not cleared). Files are written using ConfigSet.store().

Parameters:filename (string) – file to use
update(d)[source]

Dictionary interface: replace values with the ones from another dict

Parameters:d (dict-like object) – object to use the value from
stash()[source]

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()

commit()[source]

Commits transactional changes. See ConfigSet.stash()

revert()[source]

Reverts the object to a previous state. See ConfigSet.stash()