ConfigSet

ConfigSet: a special dict

The values put in ConfigSet must be lists

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

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'
table

Internal dict holding the object values

__contains__(key)[source]

Enable the in syntax:

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

Dict interface (unknown purpose)

__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: get value from key

__delitem__(key)[source]

Dictionary interface: get value from key

__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]

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.

get_flat(key)[source]

Return 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]

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
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]

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

get_merged_dict()[source]

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

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

Write the ConfigSet data into a file. See ConfigSet.load() for reading such files.

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

Retrieve the ConfigSet data from a file. See ConfigSet.store() for writing such files

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

Dictionary interface: replace values from another dict

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

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

revert()[source]

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

Previous topic

Build

Next topic

Configure

This Page