kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Support an overridable default for single-registration hooks (register_as_default)

Open rtibbles opened this issue 4 months ago • 3 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Overview

Single-registration (only_one_registered) hooks cannot express a built-in default that a plugin overrides. Add a register_as_default registration that provides one.

Complexity: Low Target branch: develop

Context

  • define_hook(only_one_registered=True) (kolibri/plugins/hooks.py:204) makes a second registration raise (hooks.py:337).
  • There is no mechanism to disable a specific registered hook, so an overridable default must be expressed at registration time.
  • The only current only_one_registered hook is ThemeHook (kolibri/core/theme_hook.py:29).
  • ThemeHook.get_theme hand-rolls the "nothing registered → default" case, falling back to {}.

The Change

  • Add a way to register a single-registration hook implementation as the default (e.g. @register_hook(as_default=True)).
  • A default registration does not count toward the only_one_registered limit.
  • Resolution prefers a non-default registration.
  • Resolution falls back to the default when no non-default is registered.
  • Two non-default registrations still raise, as today.
  • Expose the effective implementation via a single accessor (e.g. registered_hook).
  • Migrate ThemeHook to the new mechanism, preserving its current no-registration behaviour.

Out of Scope

  • Disabling or unregistering arbitrary hooks.
  • Multi-registration (non-single) hooks — behaviour unchanged.

Acceptance Criteria

General

  • [ ] A single-registration hook can register one implementation as the default.
  • [ ] With only a default registered, resolution returns the default.
  • [ ] With a non-default registered, resolution returns the non-default whether or not a default is present.
  • [ ] Two non-default registrations still raise.
  • [ ] ThemeHook uses the new mechanism, with unchanged behaviour when no theme is registered.

Testing

  • [ ] Unit tests cover default-only, override, no-registration, and two-non-default (raises).

References

  • Hook framework — kolibri/plugins/hooks.py (define_hook, register_hook, only_one_registered at lines 204/337).
  • ThemeHook — kolibri/core/theme_hook.py.

AI usage

Drafted with Claude Code in an interactive design session. The author made every design decision in dialogue and verified the code references.

rtibbles avatar Jul 11 '26 19:07 rtibbles

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 16 '26 22:07 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 17 '26 09:07 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 17 '26 17:07 rtibblesbot