AssociationRegistry

class jwst.associations.AssociationRegistry(definition_files=None, include_default=True, global_constraints=None, name=None, include_bases=False)[source]

Bases: dict

The available association rules to match against.

Notes

The general workflow is as follows:

  • Create the registry
    >>> from jwst.associations.registry import AssociationRegistry
    >>> registry = AssociationRegistry()
    
  • Create associations from an item
    >>> associations, reprocess = registry.match(item)
    
  • Finalize the associations
    >>> final_asns = registry.callback.reduce("finalize", associations)
    

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 more information.

Initialize a new registry.

Parameters:
definition_files[str,] or None

The files to find the association definitions in.

include_defaultbool

True to include the default definitions.

global_constraintsConstraint or None

Constraints to be added to each rule.

namestr or None

An identifying string, used to prefix rule names.

include_basesbool

If True, include base classes not considered rules.

Attributes Summary

rule_set

Generate set of rules within the registry.

Methods Summary

add_rule(name, obj[, global_constraints])

Add object as rule to registry.

load(serialized[, fmt, validate, first])

Load 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 and add them to the registry.

validate(association)

Validate a given association.

Attributes Documentation

rule_set

Generate set of rules within the registry.

Returns:
set

The set of rules.

Methods Documentation

add_rule(name, obj, global_constraints=None)[source]

Add object as rule to registry.

Parameters:
namestr

Name of the object.

objobject

The object to be considered a rule.

global_constraintsdict

The global constraints to attach to the rule.

load(serialized, fmt=None, validate=True, first=True, **kwargs)[source]

Load a previously serialized association.

Parameters:
serializedobject

The serialized form of the association.

fmtstr or None

The format to force. If None, try all available.

validatebool

Validate against the class’s defined schema, if any.

firstbool

A serialization potentially matches many rules. Only return the first successful load.

**kwargsdict

Other arguments to pass to the load method.

Returns:
association or [association, …]

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:
itemdict

An item, like from a Pool, to find associations for.

version_idstr

If specified, a string appended 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.

ignorelist

A list of associations to ignore when looking for a match. Intended to ensure that already created associations are not re-created.

Returns:
associations[association,…]

List of associations item belongs to, empty if none match.

reprocess_list[AssociationReprocess, …]

List of reprocess events.

populate(module, global_constraints=None, include_bases=None)[source]

Parse out all rules and callbacks in a module and add them to the registry.

Parameters:
modulemodule

The module, and all submodules, to be parsed.

validate(association)[source]

Validate a given association.

Parameters:
associationassociation-like

The data to validate.

Returns:
ruleslist

List of rules that validated.

Raises:
AssociationNotValidError

Association did not validate.