How to use the merlin.utils.contains_token function in merlin

To help you get started, we’ve selected a few merlin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LLNL / merlin / merlin / spec / expansion.py View on Github external
def var_ref(string):
    """
    Given a string , return that string surrounded
    by $().
    """
    string = string.upper()
    if contains_token(string):
        LOG.warning(f"Bad var_ref usage on string '{string}'.")
        return string
    return f"$({string})"
github LLNL / merlin / merlin / spec / expansion.py View on Github external
{'TARGET': 'target_dir',
        'PATH': '$(SPECROOT)/$(TARGET)'}

    ...would be determined as:
        {'TARGET': 'target_dir',
        'PATH': '$(SPECROOT)/target_dir'}
    """
    all_var_dicts = dict(ChainMap(*user_var_dicts))
    determined_results = {}
    for key, val in all_var_dicts.items():
        if key in RESERVED:
            raise ValueError(
                f"Cannot reassign value of reserved word '{key}'! Reserved words are: {RESERVED}."
            )
        new_val = str(val)
        if contains_token(new_val):
            for determined_key in determined_results.keys():
                var_determined_key = var_ref(determined_key)
                if var_determined_key in new_val:
                    new_val = new_val.replace(
                        var_determined_key, determined_results[determined_key]
                    )
        new_val = expandvars(expanduser(new_val))
        determined_results[key.upper()] = new_val
    return determined_results
github LLNL / merlin / merlin / spec / expansion.py View on Github external
def expand_line(line, var_dict, env_vars=False):
    """
    Expand one line of text by substituting user variables, 
    optionally environment variables, as well as variables in 'var_dict'.
    """
    if (
        (not contains_token(line))
        and (not contains_shell_ref(line))
        and ("~" not in line)
    ):
        return line
    for key, val in var_dict.items():
        if key in line:
            line = line.replace(var_ref(key), str(val))
    if env_vars:
        line = expandvars(expanduser(line))
    return line