Constraint
- class jwst.associations.lib.constraint.Constraint(init=None, reduce=None, name=None, reprocess_on_match=False, reprocess_on_fail=False, work_over=ListCategory.BOTH, reprocess_rules=None)[source]
Bases:
objectConstraint that is made up of multiple
SimpleConstraint.- Parameters:
- initobject or list of object
A single object or list of objects where the objects are as follows:
SimpleConstraintor subclass
- reducefunction
A reduction function with signature
x(iterable)whereiterableis thecomponentslist. Returns boolean indicating state of the components. Default value isall().- namestr or None
Optional name for constraint.
- reprocess_on_matchbool
Reprocess the item if the constraint is satisfied.
- reprocess_on_failbool
Reprocess the item if the constraint is not satisfied.
- work_over
Enum The condition on which this constraint should operate. This is one of the options in
ListCategory.- reprocess_ruleslist of rule or None
List of rules to be applied to. If None, calling function will determine the ruleset. If empty list, all rules will be used.
- Attributes:
- constraintslist
List of
ConstraintorSimpleConstraintthat make this constraint.- matchedbool
Result of the last
check_and_set().- reducefunction
A reduction function with signature
x(iterable)whereiterableis thecomponentslist. Returns boolean indicating state of the components. Predefined functions are:
Examples
Named constraints can be accessed directly through indexing:
>>> from jwst.associations.lib.constraint import Constraint, SimpleConstraint >>> c = Constraint(SimpleConstraint(name="simple", value="a_value")) >>> c["simple"] SimpleConstraint({'sources': <function SimpleConstraint.__init__.<locals>.<lambda>, 'force_unique': True, 'test': <bound method SimpleConstraint.eq of SimpleConstraint({...})>, 'reprocess_on_match': False, 'reprocess_on_fail': False, 'work_over': 1, 'reprocess_rules': None, 'value': 'a_value', 'name': 'simple', 'matched': False})
Attributes Summary
Return dictionary of constraints with duplicate names.
Return identifier for the constraint.
Methods Summary
all(item, constraints)Return positive only if all results are positive.
any(item, constraints)Return the first successful constraint.
append(constraint)Append a new constraint.
check_and_set(item[, work_over])Check and set the constraint.
copy()Copy self.
get_all_attr(attribute[, name])Return the specified attribute for specified constraints.
notall(item, constraints)Check if not all of the constraints match; True if not all do.
notany(item, constraints)Check if none of the constraints matches; True if none does.
preserve()Preserve all constraint states.
restore()Restore all constraint states.
Attributes Documentation
- dup_names
Return dictionary of constraints with duplicate names.
This method is meant to be overridden by classes that need to traverse a list of constraints.
- Returns:
- dupsdict
Returns a mapping between the duplicated name and all the constraints that define that name, in the format of
{str: [constraint[,...]][,...]}.
- id
Return identifier for the constraint.
- Returns:
- idstr
The identifier
Methods Documentation
- static all(item, constraints)[source]
Return positive only if all results are positive.
- Parameters:
- item
ACID The candidate.
- constraintslist of
Constraint The list of constraints to check.
- item
- Returns:
- all_matchbool
- to_reprocesslist of
Constraintor None List is empty if all constraints are positive or there are no constraints. Otherwise, the list contains constraints to reprocess.
- static any(item, constraints)[source]
Return the first successful constraint.
- Parameters:
- item
ACID The candidate.
- constraintslist of
Constraint The list of constraints to check.
- item
- Returns:
- matchbool
- to_reprocesslist of
Constraintor None List is empty if there is no match. Otherwise, it contains any constraints to reprocess.
- check_and_set(item, work_over=ListCategory.BOTH)[source]
Check and set the constraint.
- Returns:
- successbool
Trueif check is successful.- reprocesslist of
ProcessList List of process lists.
- copy()[source]
Copy self.
- Returns:
ConstraintDeepcopy of self.
- get_all_attr(attribute, name=None)[source]
Return the specified attribute for specified constraints.
- Parameters:
- attributestr
The attribute to retrieve.
- namestr or None
Only return attribute if the name of the current constraint matches the requested named constraints. If None, always return value.
- Returns:
- resultlist of tuple
The list of values of the attribute in a tuple, in the format of
[(SimpleConstraint or Constraint, object)[,...]]. If there is no attribute, an empty tuple is returned.
- Raises:
- AttributeError
If the attribute is not found.
- static notall(item, constraints)[source]
Check if not all of the constraints match; True if not all do.
- Parameters:
- item
ACID The candidate.
- constraintslist of
Constraint The list of constraints to check.
- item
- Returns:
- bool
Trueif not all constraints match.
- static notany(item, constraints)[source]
Check if none of the constraints matches; True if none does.
- Parameters:
- item
ACID The candidate.
- constraintslist of
Constraint The list of constraints to check.
- item
- Returns:
- bool
Trueif none of the constraints matches.