Skip to content

[Extensions] Integrate runtime contributions - #125

Merged
suraj-ranganath merged 2 commits into
feature/eegprep-extension-completionfrom
phase/2-extension-runtime-integration
Jun 3, 2026
Merged

suraj-ranganath merged 2 commits into
feature/eegprep-extension-completionfrom
phase/2-extension-runtime-integration

Conversation

@suraj-ranganath

Copy link
Copy Markdown
Member

Wire active extension specs into EEGPrep menu construction, GUI dispatch, packaged help lookup, and eegprep-console pop_* wrappers. Bundled plugin menus now use the same declarative runtime path while --no-plugins still hides plugin contributions without hiding core menus. Closes #114

@claude

claude Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 5m 13s —— View job


Code review — PR #125: Integrate extension runtime contributions

  • Read changed files and gather context
  • Review extension_runtime.py (new)
  • Review extensions.py changes
  • Review console / menu / pophelp / GUI integration
  • Review tests
  • Post review feedback

Code review

  • Overall assessment: Looks good — safe to merge.
  • Highest-risk area: Menu insertion ordering/anchors in extension_runtime.apply_extension_menus and the new bundled-spec list in extensions._bundled_records.
  • Merge recommendation: Safe to merge (a couple of maintainability notes below).

I verified the declarative menu path reproduces the previous hardcoded insertions: clean_rawdata after pop_eegplot:data, iclabel after pop_selectcomps, dipfit after pop_rmbase, firfilt items before pop_eegfilt (which is the only child of the filter submenu, so insert_before is equivalent to the old prepend), BIDS import/export under File > Import data/export, and viewprops under Plot. Anchor matching on the unfiltered tree before visible_menu_items is correct. --no-plugins correctly yields an empty runtime while still rendering core menus.

Blocking

None.

Important

Dual source of truth for bundled plugin metadata — src/eegprep/extensions.py _bundled_records (diff) now hardcodes the bundled plugin set (clean_rawdata, ICLabel, firfilt, dipfit, EEG_BIDS), while plugin_menu.bundled_plugins() / _BUNDLED_PLUGINS remains the separate source feeding the extension-manager dialog and format_plugin_menu. Before this PR, _bundled_records was derived from bundled_plugins(), so there was one list. Now they can drift — e.g. adding a plugin to one without the other yields a plugin that appears in the manager dialog but not the menus (or vice-versa). Why it matters: silent inconsistency between the menu integration and the plugin manager. Suggested fix: derive one from the other, or add a test asserting the two sets agree on plugin names. Acceptable to defer, but worth a tracking note.

Nits

  • MenuActionDispatcher._call_extension_target (diff) always selects with allow_multiple=True for pop_* targets, unlike _run_pop_function, which gates on _MULTIPLE_DATASET_ACTIONS. With multiple datasets selected this passes a list of EEG dicts as the EEG/first argument to extension pop functions that expect a single EEG dict. Low impact (the common path has a single current dataset), but consider matching the core gating for consistency.
  • action_kind gained an extension_runtime parameter, but the only production caller (menu_actions.py:226) doesn't pass it — the new arg is currently exercised only by tests. Not a bug (placeholder detection is registry-based via is_placeholder_action, so external extension actions still fall through to the runtime dispatch fallback), just noting the param has no production consumer yet.

Test gaps

None blocking. Coverage is strong: enable-state matrix, --no-plugins for both extension and bundled menus, missing-path warning, duplicate-menu invalidation, malformed help resource, all four action result shapes (EEG-only / EEG+command / command-only / no-mutation), GUI dispatch, error-without-mutation, console bare + assigned calls, packaged help lookup, and runtime-backed action_kind.

Optional addition: a test asserting bundled plugin menu items land at the expected positions with include_plugins=True (e.g. "Reject data using Clean Rawdata and ASR" appears right after the pop_eegplot:data item under Tools), to lock the anchor ordering that this refactor reorganizes.

EEGLAB parity notes

The refactor preserves EEGLAB-style menu placement and ordering relative to the prior hardcoded inserters (verified against eeglab_core_menus anchors). No parity regressions spotted. Note that bundled plugin pop functions (pop_iclabel, pop_clean_rawdata, etc.) remain in IMPLEMENTED_ACTIONS, so they keep dispatching through their dedicated handlers; the new extension fallback only fires for genuinely external extension actions.

Note: I couldn't run the test suite in this environment (sandbox blocked uv run), so findings are from static analysis of the diff and surrounding code rather than executed tests.
· phase/2-extension-runtime-integration

@suraj-ranganath

Copy link
Copy Markdown
Member Author

🤖 Specification

Problem
src/eegprep/functions/guifunc/eeglab_menu.py previously inserted bundled plugin menus directly, so external ExtensionSpec menu declarations had no route into the real main-window menu tree. src/eegprep/functions/guifunc/menu_actions.py and src/eegprep/functions/adminfunc/console.py only dispatched built-in pop_* exports, and src/eegprep/functions/guifunc/pophelp.py only searched core packaged Markdown resources.

Approach
Extend ExtensionMenu with pure declarative menu metadata, recursive children, and stable insertion anchors. Add src/eegprep/extension_runtime.py to turn active ExtensionRecord values into menu contributions, action/pop function maps, and help-resource maps. Main-window construction, GUI action dispatch, pophelp, and eegprep-console now share that runtime. Bundled plugin menu specs are converted into bundled extension records so --no-plugins and include_plugins=False still suppress all plugin contributions through one path.

Key code

@dataclass(frozen=True)
class ExtensionRuntime:
    records: tuple[ExtensionRecord, ...] = ()
    actions: Mapping[str, ExtensionAction] | None = None
    pop_functions: Mapping[str, ExtensionPopFunction] | None = None
    help_resources: Mapping[str, ExtensionResource] | None = None
    menu_contributions: tuple[ExtensionMenuContribution, ...] = ()

    def action(self, name: str) -> ExtensionAction | ExtensionPopFunction | None:
        key = _key(name)
        actions = self.actions or {}
        pop_functions = self.pop_functions or {}
        return actions.get(key) or pop_functions.get(key)

Tests
Added tests/test_extension_runtime.py for extension menu enabled states, include_plugins=False, missing paths, duplicate menus, malformed help resources, GUI action return shapes, raised action errors, registered extension pop_* dispatch, console bare/assigned pop_* calls, help lookup, and runtime-backed action classification. Existing focused console, help, menu, plugin inventory, package export, and GUI entry tests pass, plus the non-slow suite passes locally with EEGPREP_SKIP_MATLAB=1.

@suraj-ranganath
suraj-ranganath merged commit cc27b3d into feature/eegprep-extension-completion Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant