Replace pluggy with an entry-point registry and reshape LanguageRegistration#69
Open
janrito wants to merge 4 commits into
Open
Replace pluggy with an entry-point registry and reshape LanguageRegistration#69janrito wants to merge 4 commits into
LanguageRegistration#69janrito wants to merge 4 commits into
Conversation
…tion Drop pluggy (languages are single-dispatch by id, so a multi-dispatch hook framework earns nothing): discover plugins from the `rbtr.languages` entry-point group via `importlib.metadata`, each resolving to a module-level `LanguageRegistration`. Make `load_query` public and rename `hookspec` to `registration`. The constructor is now pure data; extraction overrides attach via wrap-style decorator methods (the built-in resolver is passed in), and `extract_symbols` takes the registration and delegates resolution to it.
The bash and sql package pyprojects still described the entry-point value as a plugin instance; it now resolves to a LanguageRegistration, matching core's comment.
The skill taught removed Phase-9 symbols (_QUERY constants, resolve_name/ resolve_scope/build_import_from_captures, and the old non-wrap name_extractor(capture_name, ...) signature) and the pre-packaging model (a plugin as a file under rbtr/languages/, samples under tests/languages/samples/). Update it to wrap-style resolvers (default_*, resolver-first, attached via @reg decorator methods), entry-point discovery (no pluggy), and the packaged layout (rbtr_lang_<x> package with co-located .scm queries and per-package tests/samples/).
The class docstring examples passed chunker= and import_extractor= as constructor arguments, contradicting the adjacent 'attach via decorator methods' prose. Fix them to the decorator form, drop the mixed Attributes: block in favour of an inline per-field docstring on every field (removing the class_scope_types duplication), and flesh out the under-documented import-resolution fields (import_targets, source_roots, path_substitutions, index_files). Also fix a stale samples path in the module docstring.
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 removes pluggy from the plugin system and replaces it with an
entry-point registry, and changes how a language plugin is declared: a
data-only
LanguageRegistrationvalue with decorator-based overrides forcustom extraction.
pluggy is a multi-dispatch hook framework. Languages are rbtr's only
plugin type, and every file maps to exactly one language by id, so the
dispatch is single. pluggy adds no value here and adds a cost: entry
points had to resolve to a plugin instance (a class with
@hookimplplusplugin = XPlugin()), which is easy to get wrong. tree-sitter uses noplugin framework — it passes objects directly — and this change follows
that approach.
Plugins are discovered from the
rbtr.languagesentry-point group withimportlib.metadata. Each entry point resolves to a module-levelLanguageRegistrationnamed by its language id(
rbtr_lang_bash.plugin:bash): no class, no hook markers, no instance. Aduplicate id raises, because two packages claiming one id is a bug and
entry-point order across distributions is not deterministic. A plugin
that fails to import is logged and skipped, so one broken third-party
plugin does not stop the rest.
The registration constructor is now pure data. Custom name, scope,
import, or chunker logic attaches through decorator methods
(
@bash.name_extractor) shaped like a pydanticWrapValidator: theoverride receives the built-in resolver as its first argument and calls
it to delegate.
extract_symbolstakes the registration and asks it toresolve names, scopes, and imports, instead of the orchestrator reading
private fields. Behaviour stays in injected callables rather than a base
class, following the abstraction-design guidance against template-method
hierarchies. The trade-off: with one slot per hook, every
name/scope/import override takes the resolver argument even when it does
not delegate.
The authoring documentation is updated to the new API and packaged model:
the
rbtr-languagesskill, and an inline docstring on everyLanguageRegistrationfield.No behaviour change: a language extracts what it did before. The registry
loader is tested for the cases that matter — a duplicate id raises, and a
broken plugin is skipped without taking the others down.