def read_constraints_from_config(cp, transforms=None,
                                 constraint_section='constraint'):
    """Loads parameter constraints from a configuration file.

    Parameters
    ----------
    cp : WorkflowConfigParser
        An open config parser to read from.
    transforms : list, optional
        List of transforms to apply to parameters before applying constraints.
    constraint_section : str, optional
        The section to get the constraints from. Default is 'constraint'.

    Returns
    -------
    list
        List of ``Constraint`` objects. Empty if no constraints were provided.
    """
    cons = []
    for subsection in cp.get_subsections(constraint_section):
        name = cp.get_opt_tag(constraint_section, "name", subsection)
        constraint_arg = cp.get_opt_tag(
            constraint_section, "constraint_arg", subsection)
        # get any other keyword arguments
        kwargs = {}
        section = constraint_section + "-" + subsection
        extra_opts = [key for key in cp.options(section)
                      if key not in ["name", "constraint_arg"]]
        for key in extra_opts:
            val = cp.get(section, key)
            if key == "required_parameters":
                val = val.split(_VARARGS_DELIM)
            else:
                try:
                    val = float(val)
                except ValueError:
                    pass
            kwargs[key] = val
        cons.append(constraints.constraints[name](constraint_arg,
                                                  transforms=transforms,
                                                  **kwargs))

    return cons
def read_constraints_from_config ( cp , transforms = None , constraint_section = 'constraint' ) : cons = [ ] for subsection in cp . get_subsections ( constraint_section ) : name = cp . get_opt_tag ( constraint_section , "name" , subsection ) constraint_arg = cp . get_opt_tag ( constraint_section , "constraint_arg" , subsection ) kwargs = { } section = constraint_section + "-" + subsection extra_opts = [ key for key in cp . options ( section ) if key not in [ "name" , "constraint_arg" ] ] for key in extra_opts : val = cp . get ( section , key ) if key == "required_parameters" : val = val . split ( _VARARGS_DELIM ) else : try : val = float ( val ) except ValueError : pass kwargs [ key ] = val cons . append ( constraints . constraints [ name ] ( constraint_arg , transforms = transforms , ** kwargs ) ) return cons
Loads parameter constraints from a configuration file.

    Parameters
    ----------
    cp : WorkflowConfigParser
        An open config parser to read from.
    transforms : list, optional
        List of transforms to apply to parameters before applying constraints.
    constraint_section : str, optional
        The section to get the constraints from. Default is 'constraint'.

    Returns
    -------
    list
        List of ``Constraint`` objects. Empty if no constraints were provided.