FEAT: BuildableRegistry Creation#2057
Open
rlundeen2 wants to merge 9 commits into
Open
Conversation
Move the declarative Parameter contract to pyrit/models/parameter.py as the canonical home, add ComponentRegistryKind / RegistryReference / ParameterDestination, and re-key the registry resolver off registry kind instead of inline issubclass checks. pyrit/common/parameter.py becomes a compatibility re-export. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rename ComponentRegistryKind -> ComponentType and have identifiers own their reference-derivation. Replace the fabricated class-level ConverterIdentifier with a declarative Param.ClassAttr marker plus a generic class-attribute reader; ClassRegistryEntry now carries class_attributes. Rename the converter nested-converter slot sub_converters -> sub_converter and model it as a proper buildable reference. Promote three identifier structure/child-tree methods to public contracts (get_reference_component_types, get_class_attribute_values, plus internal child-eval-hash collection). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make the universal registry base a standalone top-level class named `Registry` (renamed from BuildableRegistry; buildable_registry.py -> registry.py). It no longer inherits BaseClassRegistry: it owns its own singleton machinery, class catalog (dict[str, type[T]]), lazy discovery, metadata cache, validation, and build path. - Single add path: _discover() -> register_class() -> _validate_class, so every class is validated at registration time (dropped public validate_all/ validate_buildable and the ClassEntry/factory/default_kwargs wrapper). - Migrate only ConverterRegistry onto Registry; scenarios/initializers/targets/ scorers stay on the transitional BaseClassRegistry for now. - Renames: reset_instance -> reset_registry_singleton, register -> register_class, get_names -> get_class_names, list_metadata -> get_all_registered_class_metadata, get_entry -> get_registered_class_metadata; add get_class_metadata(cls). create_instance keeps its name. - Remove issubclass fallback in resolution.py; update converter_service and docstrings; update tests for the new surface and add-time validation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reverts incidental removal of find_dependents_of_tag (and its tests) from the legacy instance stack; it is unrelated to the standalone Registry migration and will be shared by the not-yet-migrated target/scorer registries. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Encapsulate the low-level 'reference points at this component family' check as Parameter.is_reference_to(component_type), the single source of truth. ConverterMetadata.is_llm_based and the converter tests now read through it instead of re-deriving reference.component_type inline. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make Registry._build_metadata concrete: it assembles the shared ClassRegistryEntry fields and constructs whatever metadata type the subclass declares via the new abstract _metadata_class() hook. Adds _derive_parameters/_class_attributes/_describe helpers; _derive_parameters is now reused by _validate_class, removing the double parameter derivation. ConverterRegistry drops its hand-rolled _build_metadata in favor of a one-line _metadata_class() returning ConverterMetadata. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
_registry_getter_for_component_type returns a deferred getter to a name->instance registry and reaches through .instances for converters but not for target/scorer (whose legacy singletons are themselves the instance registry). It wants to be a flat ComponentType -> registry class mapping, but that requires target/scorer to migrate onto Registry + .instances first (Phase 4). Add code notes marking the deferral on both that function and the is_component_type_resolvable gate that wraps it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add tests/unit/registry/test_registry.py covering the Registry base directly (default snake_case naming, no-identifier path, eager vs lazy discovery, the metadata getters, and the filter-path wiring). - Move first-paragraph description extraction onto ClassRegistryEntry (summary_from_docstring); _build_metadata delegates to the metadata class and the bespoke Registry._describe is removed. - Inline _matches_filters/_get_metadata_value into registry.py (base.py is slated for deletion except ClassRegistryEntry) and drop the function-local import. - Simplify __iter__ to reuse get_class_names(). - ConverterRegistry._discover keys off the class (drop redundant name=) and logs cls.__name__; annotate _get_registry_name as type[PromptConverter]. - Comment the deliberate double-derivation of parameters in _validate_class. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR hashes out Registry, making it the single source of truth for component contracts. This PR
Phase 2 and 3: https://gist.github.com/rlundeen2/f7960f7e8973fbb705b1b4bb48d8cdb2
Note, I thought this PR was actually more readable combining 2 and 3 because you get a "fairly final" version of ConverterRegistry working end to end. Next steps are to move other registries