Replacements

class sconstool.util.Replacements[source]

Enables one to temporarily replace variables in a dict-like object (SCons Environment).

The Replacements are designed to be used with ReplacingBuilder or ReplacingAction.

apply(subj, include_unmapped=False)[source]

Apply replacements to subj.

Returns a dictionary of variables from subj set to their replacement values. By default, only variables having their replacements are extracted. If include_unmapped is True, remaining variables from subj will also be added to the returned dictionary.

Parameters:
  • subj (dict) – a dictionary with variables, some of which may be replacement variables,
  • include_unmapped (bool) – also include the variables from subj which are not replacement variables.
Return dict:

replaced variables from subj*.

inject(dest, setter='__setitem__', only_present=False)[source]

Inject replacement variables into the dest.

This method is supposed to be used to initialize replacement variables in the dictionary dest. For each mapping {'FOO': 'BAR'} in Replacements dest['BAR'] = '$FOO' assignment will be performed using the provided setter. If only_present is True, the assignment will be performed only if the variable dest['FOO'] is already defined.

Parameters:
  • dest (dict) – destination dictionary to be modified,
  • setter (str,callable) – a method (or method name) of dest that sets items in dest, should be a function with prototype dest.setter(name, value), except for SetDefault, Replace, Append, Prepend, AppendUnique, PrependUnique methods of SCons environment where the prototype is dest.setter(**kw),
  • only_present (bool) – if True, only the replacements for variables already present in dest will be set.