Repository navigation
Closed
Labels
phaseEpic implementation phase
Description
Summary
Define the stable EEGPrep extension contract. This phase creates the core SDK and registry but does not need to fully wire every GUI/menu/runtime surface yet.
The design should preserve EEGLAB plugin familiarity while using Python-native packaging. EEGLAB's eegplugin_*.m functions mutate menus and MATLAB paths; EEGPrep should instead discover installed Python packages through entry points and register declarative extension specs.
Key Work
- Add an extension SDK module, likely under
src/eegprep/functions/adminfunc/or a small top-level package module such assrc/eegprep/extensions.pyif public API clarity warrants it. - Define
ExtensionSpecwith fields for name, display name, version, API version, package name, entry point name, source type, description, docs URL, maintainer, capabilities, dependencies, menus, actions,pop_*functions, help resources, and package-data resources. - Define a registry that can discover entry points from
importlib.metadata.entry_points(group="eegprep.extensions"). - Validate extension specs before activating them.
- Add compatibility checks for EEGPrep version requirements and extension API version.
- Support lazy loading so heavy extension modules do not slow GUI startup.
- Support enable/disable state without hidden globals. Store only minimal user preferences in an explicit config location or session-owned state.
- Define status values for bundled, installed, curated, disabled, incompatible, failed import, invalid spec, missing dependency, and unknown.
- Isolate failures: one broken extension must not crash EEGPrep startup.
- Keep runtime code independent of
src/eegprep/eeglab.
Edge Cases To Cover
- Duplicate extension names.
- Duplicate action names or
pop_*function names. - Entry point imports but returns the wrong type.
- Extension requires a newer EEGPrep or unsupported API version.
- Extension import raises an exception.
- Extension metadata is valid but a lazy action import later fails.
- Extension is installed but disabled.
- Extension package data/help resource is missing.
- No extensions installed.
--no-plugins/include_plugins=Falsekeeps behavior predictable.
Acceptance Criteria
- EEGPrep can discover extension entry points without importing heavy action modules eagerly.
- Registry returns a deterministic list of extension records and statuses.
- Invalid/failing extensions are visible in registry status and logged without crashing.
- The API is documented enough that later phases can build against it without guessing.
- Existing bundled plugin inventory behavior remains stable.
- Unit tests cover discovery, validation, status, duplicate handling, lazy loading, and failure isolation.
uv run --no-sync ruff check .,uv run --no-sync ruff format --check .,uv run --no-sync ty check, and focused pytest pass.
/goal Prompt
/goal Implement EEGPrep's external extension SDK, registry, entry-point discovery, lazy loading, compatibility checks, and status model. Use EEGLAB's eegplugin_* startup model only as a behavior reference, not as a Python implementation pattern. Preserve existing bundled plugin behavior, isolate broken extensions, avoid runtime EEGLAB dependencies, add thorough tests for edge cases, and keep lint/type/focused tests green.
Metadata
Metadata
Assignees
Labels
phaseEpic implementation phase
Activity
claude commentedon Jun 2, 2026
🤖 Plan:
Scope: Phase 1 is a new multi-module SDK + registry with discovery, validation, status, lazy loading, and tests. This is well over the 100-line bug-fix bar, so no PR yet - design first.
Research
EEGPrep already ships an EEGLAB-flavored "plugin inventory" but it is a hard-coded tuple plus a read-only Qt dialog; there is no discovery, no entry-point group, no API/compat version, no per-extension lifecycle, and the GUI hard-wires each bundled plugin's menu by name. The Phase 1 contract has to replace the static inventory with a registry that bundled and external packages can both feed, while keeping the existing GUI/console flows working through the same data shape (
{plugin, name, version, status, source, menu, ...}already consumed byplugin_menu,plugin_status,session.PLUGINLIST).Key constraints from AGENTS.md: no globals for processing, runtime must not depend on
src/eegprep/eeglab, GUI/console state must flow throughEEGPrepSession, help text must be EEGPrep-owned Markdown underresources/help/, andpop_*functions must remainreturn_com-compatible. The new SDK has to honor all of these.Relevant code
src/eegprep/functions/adminfunc/plugin_menu.py#L14-L189- current static_BUNDLED_PLUGINS,bundled_plugins,plugin_status,plugin_menu,format_plugin_menusrc/eegprep/functions/guifunc/menu_spec.py#L12-L57-MenuItemSpecalready has anoriginfield that tags plugin-contributed itemssrc/eegprep/functions/guifunc/eeglab_menu.py#L371-L425- hard-coded_insert_*_pluginsinjection points; Phase 2 will replace these with registry-driven insertionsrc/eegprep/plugins/firfilt/__init__.py,plugins/firfilt/menu.py,plugins/dipfit/menu.py,plugins/ICLabel/menu.py- bundled-plugin lazy-import +menu_item(..., origin="<plugin>")pattern the SDK will formalizesrc/eegprep/functions/guifunc/session.py#L82-L100-EEGPrepSession.PLUGINLISTand history hooks the registry must feedsrc/eegprep/functions/adminfunc/console.py#L455-L470andfunctions/guifunc/main_window.py#L53-L390---no-plugins/include_plugins=Falseboundary that must remain meaningful with the registryProposed Design
1. Public SDK module
Add
src/eegprep/extensions.pyas the only public import path; everything in this module is the Phase 1 contract. Internal helpers (discovery walk, validation, status enum, defaults) live insrc/eegprep/functions/adminfunc/extensions/so the public surface stays small. Re-export the same names througheegprep.__init__via the existing lazy-export table.Public names:
ExtensionSpec(frozen@dataclass)ExtensionRecord(frozen@dataclass- runtime view: spec + status + load error + source)ExtensionStatus(StrEnum)EEGPREP_EXTENSION_API_VERSION(int constant,1)EEGPREP_EXTENSION_ENTRY_GROUP="eegprep.extensions"ExtensionRegistry(class; iterable, indexable by name)get_registry()(returns the process-local registry; first call performs discovery)discover_extensions(*, include_external=True, include_bundled=True)(pure function - does not mutate the cached registry; useful for tests and the Extension Manager refresh)register_bundled(spec)(only called from bundled plugin__init__modules; not part of the external author API but needed so Phase 2 can migratefirfilt/ICLabel/dipfit/EEG_BIDS/clean_rawdataoff the hard-coded tuple)ExtensionError,InvalidExtensionSpec,IncompatibleExtensionexception types2. ExtensionSpec fields
MenuContributionreusesMenuItemSpecplus aninsert_afteranchor (e.g."pop_eegplot:data") so Phase 2 can drop the hand-coded_insert_*_pluginshelpers.ActionContributioncarriesname,dotted_target, andallows_multiple.HelpResourcecarriesfunction_nameandpackage_resource(importlib.resourcesref, never a filesystem path undersrc/eegprep/eeglab).Action / pop-function / help references are stored as strings, never resolved at registration time - that is what gives us lazy loading.
3. Discovery
register_bundled(spec)from the existingplugins/*/__init__.pymodules. Phase 1 lands the API and (to keep the change reviewable) provides a bridge that synthesizesExtensionSpecinstances from the existing_BUNDLED_PLUGINStuple; Phase 2 migrates each bundled plugin to callregister_bundleddirectly.bundled_plugins()stays as a thin shim around the registry so the old call sites and tests remain green.importlib.metadata.entry_points(group="eegprep.extensions"). We do not import the action / pop modules at discovery; only the entry-point factory is imported, and it is expected to return a declarativeExtensionSpec.--no-plugins/include_plugins=Falseshort-circuits external discovery only; bundled extensions still register.4. Status model
ExtensionRecordwraps the spec withstatus,load_error(str),source(bundled / external / curated), andinstalled(bool). The existingplugin_status()keeps its tuple return contract by translating these to1/0for backwards compatibility with EEGLAB-shaped callers.5. Validation rules (raised as
InvalidExtensionSpecor surfaced asINVALID_SPEC)namematches^[a-z][a-z0-9_]*$;versionparses as PEP 440.api_versionis anintand<=EEGPREP_EXTENSION_API_VERSION.eegprep_requires(if set) parses as a PEP 440 specifier and matcheseegprep.__version__.nameacross entry points -> first wins, later ones recorded withstatus=INVALID_SPECand a deterministicload_error.action.nameorpop_functionname across extensions -> both extensions markedINVALID_SPEC; registry logs a single warning naming both.INVALID_SPEC.requiresreferences unknown extension ->MISSING_DEPENDENCY.get_registry().6. Lazy loading
The registry only stores specs. The first call that needs an actual implementation (
registry.resolve_action(name),registry.resolve_pop_function(name)) importsmodule:attrand caches the resolved object inside the record. A lazy-resolution failure flips that record toFAILED_IMPORTbut does not affect other records. Importantly,get_registry()itself must not import any plugin action module - that guarantee is what keeps GUI startup fast and is one of the test cases.7. State and user preferences
No global mutable state for enable/disable. The set of disabled extension names lives in
EEG_OPTIONS(existing options file mechanism) under a newdisabled_extensionskey, queried by the registry at construction time. Tests pass an explicitdisabled={...}argument; the registry never reads environment variables.8. EEGLAB vs EEGPrep equivalence
eegplugin_<name>.mstartup functioneegprep.extensionsentry-point factory returningExtensionSpecplugin_status.mplugin_status()shim overregistry.find()plugin_menu.mGUIThis keeps the EEGLAB user mental model ("my plugin is something with a name, version, menu, and pop functions") while replacing the MATLAB-specific lifecycle with Python packaging.
9. Testing (all under
tests/test_extensions_registry.py, plus targeted updates totests/test_plugin_menu.pyandtests/test_console_workspace.py)ExtensionStatus.BUNDLEDand matches the existingbundled_plugins()names/order.importlib.metadata(usingimportlib.metadata.EntryPointplus a monkey-patchedentry_pointsfor the test) is discovered, validated, and shows up asINSTALLED.FAILED_IMPORT, registry construction does not raise, other entries still load.ExtensionSpec->INVALID_SPEC.INVALID_SPEC, first remains usable.api_versionnewer than runtime, oreegprep_requiresmismatch ->INCOMPATIBLEand not active.disabled_extensionssetting ->DISABLEDand not active, but still listed.actionsorpop_functions; explicitly resolving one then does.include_external=Falsereturns only bundled records; "no extensions installed" returns an empty external list without errors.eegprepand callingget_registry()with one malformed entry point still yields the bundled five.No mocks for the registry logic itself; the only patched boundary is
importlib.metadata.entry_pointsfor the synthetic external entry-point cases.10. Out of scope for Phase 1
_insert_*_pluginsmenu insertion (Phase 2).__init__.pyto callregister_bundledinstead of going through the bridge (Phase 2, behind the shim).11. Estimated size
Roughly 600-900 LOC in
src/eegprep/(most of it in the newextensions/package plus theextensions.pyfacade), plus ~250-350 LOC of new tests. The legacyplugin_menu.pyshrinks to a shim over the registry, andfunctions/guifunc/main_window.py/adminfunc/console.pychange only enough to consume the newExtensionRegistryAPI where they currently consultbundled_plugins().12. Open questions for human review
eegprep.extensions(new top-level) vseegprep.functions.adminfunc.extensions? I prefer the former because the SDK is a public surface and AGENTS.md only forbids generic "utilities" at the top level, not stable public APIs - but happy to defer.EEGPREP_EXTENSION_API_VERSIONstart at1(clean break) or0(signals "unstable" for the duration of the epic)? I propose1.disabled_extensionsbelongs inEEG_OPTIONSor in a separateextensions_state.json? Current plan:EEG_OPTIONSto match EEGLAB's single-options-file pattern.register_bundledpublic function at all, or should bundled plugins go through the same entry-point mechanism via internal entry-point metadata? Going through entry points is purer but adds packaging complexity topyproject.tomlfor code we already ship; current plan is the explicitregister_bundledcall.MenuContribution.insert_afteranchor format - string action id like"pop_eegplot:data"(current de-facto pattern) or a structured(menu_path, action)tuple? Leaning string for parity withMenuItemSpec.action.Once these are settled (or explicitly deferred) I will open an implementation PR on an
agent/20260602-fix-113branch.