AssociationRegistry¶
-
class
jwst.associations.
AssociationRegistry
(definition_files=None, include_default=True, global_constraints=None, name=None, include_bases=False)[source]¶ Bases:
dict
The available assocations
Parameters: - definition_files ([str,]) – The files to find the association definitions in.
- include_default (bool) – True to include the default definitions.
- global_constraints (Constraint) – Constraints to be added to each rule.
- name (str) – An identifying string, used to prefix rule names.
- include_bases (bool) – If True, include base classes not considered rules.
-
rule_set
¶ The rules in the registry.
Type: {rule [, ..]}
-
validate
(association)[source]¶ Determine whether an association is valid, or complete, according to any of the rules in the registry.
-
finalize
(associations)¶ Validate and execute post-processing hooks to produce a completed and valid set of associations.
Notes
The general workflow is as follows:
- Create the registry
>>> registry = AssociationRegistry()
- Create associations from an item
>>> associations, reprocess = registry.match(item)
- Finalize the associations
>>> final_asns = registry.finalize(assocations)
In practice, this is one step in a larger loop over all items to be associated. This does not account for adding items to already existing associations. See generate for a full example of using the registry.
Attributes Summary
rule_set
Methods Summary
add_rule
(name, obj[, global_constraints])Add object as rule to registry load
(serialized[, format, validate, first])Marshall a previously serialized association match
(item[, version_id, allow, ignore])See if item belongs to any of the associations defined. populate
(module[, global_constraints, …])Parse out all rules and callbacks in a module validate
(association)Validate a given association against schema Attributes Documentation
-
rule_set
Methods Documentation
-
load
(serialized, format=None, validate=True, first=True, **kwargs)[source] Marshall a previously serialized association
Parameters: - serialized (object) – The serialized form of the association.
- format (str or None) – The format to force. If None, try all available.
- validate (bool) – Validate against the class’ defined schema, if any.
- first (bool) – A serialization potentially matches many rules. Only return the first succesful load.
- kwargs (dict) – Other arguments to pass to the
load
method
Returns: Return type: The Association object, or the list of association objects.
Raises: AssociationError
– Cannot create or validate the association.
-
match
(item, version_id=None, allow=None, ignore=None)[source] See if item belongs to any of the associations defined.
Parameters: - item (dict) – A item, like from a Pool, to find assocations for.
- version_id (str) – If specified, a string appened to association names. If None, nothing is used.
- allow ([type(Association), ..]) – List of rules to allow to be matched. If None, all available rules will be used.
- ignore (list) – A list of associations to ignore when looking for a match. Intended to ensure that already created associations are not re-created.
Returns: (associations, reprocess_list) –
- associations: [association,…]
List of associations item belongs to. Empty if none match
- reprocess_list: [AssociationReprocess, …]
List of reprocess events.
Return type: 2-tuple
-
populate
(module, global_constraints=None, include_bases=None)[source]¶ Parse out all rules and callbacks in a module
Parameters: - module (module) – The module, and all submodules, to be parsed.
- Modifies –
- -------- –
- self.callback – Found callbacks are added to the callback registry
-
validate
(association)[source] Validate a given association against schema
Parameters: association (association-like) – The data to validate Returns: rules – List of rules that validated Return type: list Raises: AssociationNotValidError
– Association did not validate