Skip to content

Add extension SDK registry - #120

Merged
suraj-ranganath merged 2 commits into
feature/eegprep-extension-completionfrom
phase/1-extension-sdk-registry
Jun 3, 2026
Merged

suraj-ranganath merged 2 commits into
feature/eegprep-extension-completionfrom
phase/1-extension-sdk-registry

Conversation

@suraj-ranganath

Copy link
Copy Markdown
Member

Add the public extension SDK and registry for entry-point discovery, status reporting, validation, compatibility checks, disabled state, bundled inventory records, and lazy action/pop-function targets. Tests cover duplicate, failing, incompatible, disabled, missing-resource, and no-plugin behavior. Menu/action/help/console wiring remains for later extension phases.

Closes #113

@claude

claude Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 4m 44s —— View job


PR Review: Add extension SDK registry

  • Gather PR context and read changed files
  • Review src/eegprep/extensions.py (core SDK + registry)
  • Review tests (tests/test_extensions.py, tests/test_package_exports.py)
  • Review docs (docs/source/api/extensions.rst, docs/source/api/index.rst)
  • Review src/eegprep/__init__.py re-exports
  • Post inline comments and final summary

Summary

Solid first phase. The SDK is well-scoped: small, declarative dataclasses, lazy targets, deterministic discovery, and a status model that keeps broken extensions visible instead of crashing startup. Bundled-plugin records cleanly reuse the existing bundled_plugins() inventory, and entry-point discovery uses dependency-injectable providers (entry_points_provider, version_provider) which make the tests fast and reproducible. Test coverage spans the important paths: empty, duplicate, failing-import, invalid spec, incompatible API/version, missing dependency, disabled, missing resource, lazy-target-import failure. Public surface is added via the existing lazy _LAZY_EXPORTS pattern in src/eegprep/__init__.py, so import cost stays low (verified by test_import_eegprep_is_lightweight).

Inline findings

  1. docs/source/api/extensions.rst:3-5 – Title Extension SDK and Registry is 26 chars but the over/underline is 25 =. Sphinx will emit "Title overline & underline too short". Suggested a fix.
  2. src/eegprep/extensions.py:68 (and 90, 97) – # pragma: no cover is applied to error paths that are exercised (LazyImport.load) or are silently excluded from coverage (ExtensionResource.read_text/read_bytes). Misleading either way; remove the pragma or add explicit tests.
  3. src/eegprep/extensions.py:735-736 – ~= (compatible release) is implemented as a bare lower bound. PEP 440 says ~=1.4 means >=1.4, <2.0. As-is, ~=1.4 would accept 2.0, defeating its purpose. Either implement the upper bound or document the limitation.
  4. src/eegprep/extensions.py:769-778 – _as_tuple accepts set, which produces non-deterministic ordering for every collection field in ExtensionSpec. The registry is otherwise deterministic; this is a footgun for duplicate-contribution detection (which iterates actions/pop_functions). Drop the set branch or sort.
  5. src/eegprep/extensions.py:55-61 – LazyImport.from_string is unused and untested; either add a test (and document the "module:attribute" form) or remove per AGENTS.md "Don't add features beyond what the task requires".
  6. src/eegprep/extensions.py:336-352 – try block wraps both entry_point.load() and loaded(), so an exception from the register() callable is reported as "failed to import". Minor message accuracy issue when triaging plugin bugs.
  7. src/eegprep/extensions.py:613-632 – INVALID_SPEC outranks DISABLED, so a disabled extension with structural spec errors reports INVALID_SPEC. Worth a short test pinning the intended contract; my read of the docstring suggests DISABLED should win, but the current behavior is defensible.

Non-blocking notes

  • docs/source/api/extensions.rst / docs/source/api/index.rst don't list eegprep.ExtensionLoadError or eegprep.ExtensionValidationResult in autosummary, even though they're public exports and tested in test_phase_6b_public_exports_are_intentional. Worth adding for API completeness.
  • The bundled records are appended in _BUNDLED_PLUGINS insertion order, while entry-point records are sorted via _record_sort_key. Combined output is deterministic; just noting the asymmetry — the test pins the insertion order, which is fine.
  • _select_entry_points includes a TypeError fallback for older entry_points() signatures. Python 3.10+ supports entry_points(group=...) natively, so this branch is only reached by custom providers — harmless, but it's effectively dead for the default metadata.entry_points path.
    · branch phase/1-extension-sdk-registry

Comment thread docs/source/api/extensions.rst Outdated
Comment on lines +3 to +5
=========================
Extension SDK and Registry
=========================

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 The title Extension SDK and Registry is 26 characters, but the over/underline rules are only 25 =. Sphinx will emit a warning ("Title overline & underline too short"). Pad both to at least 26 =.

Suggested change
=========================
Extension SDK and Registry
=========================
==========================
Extension SDK and Registry
==========================

Comment thread src/eegprep/extensions.py
Comment on lines +63 to +69
def load(self) -> Any:
"""Import and return the referenced object."""
try:
module = importlib.import_module(self.module)
return getattr(module, self.attr)
except Exception as exc: # pragma: no cover - exact import failures vary by platform
raise ExtensionLoadError(f"Could not load extension target {self.module}:{self.attr}") from exc

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 The # pragma: no cover is misleading here — tests/test_extensions.py::test_lazy_action_import_failure_happens_after_valid_discovery exercises exactly this branch (it asserts RuntimeError from a LazyImport to a missing module). The pragma is also applied on ExtensionResource.read_text/read_bytes at lines 90 and 97 although neither error path is actually covered. Suggest removing the no cover directive on LazyImport.load (the test covers it) and either covering or removing the ExtensionResource ones — silently excluding error paths from coverage hides real gaps.

Comment thread src/eegprep/extensions.py Outdated
Comment on lines +735 to +736
if operator == "~=" and comparison < 0:
return False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 The ~= (compatible release) operator is implemented as a plain lower bound, which doesn't match PEP 440 semantics. PEP 440 says ~=1.4 means >=1.4, <2.0 and ~=1.4.5 means >=1.4.5, <1.5. As written, an extension declaring dependencies=(ExtensionDependency("foo", "~=1.4"),) would silently accept foo==2.0, which defeats the point of using ~=. Either implement the upper bound or document that ~= is treated as >= so authors don't rely on it.

Comment thread src/eegprep/extensions.py
Comment on lines +769 to +778
def _as_tuple(value: Any) -> tuple[Any, ...]:
if value is None:
return ()
if isinstance(value, tuple):
return value
if isinstance(value, list):
return tuple(value)
if isinstance(value, set):
return tuple(value)
return (value,)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Accepting a set here produces a non-deterministic tuple ordering for every collection field (capabilities, dependencies, menus, actions, pop_functions, etc.). The registry is otherwise carefully deterministic (_record_sort_key, sorted entry-point records). Two extensions that pass capabilities={"a","b"} could yield different ExtensionSpec tuples across runs, undermining reproducible status reporting and duplicate detection (which depends on iteration order of actions/pop_functions). I'd either drop the set branch and require a tuple/list, or sort when converting from set.

Comment thread src/eegprep/extensions.py Outdated
Comment on lines +55 to +61
@classmethod
def from_string(cls, value: str) -> "LazyImport":
"""Build a lazy reference from ``"module:attribute"`` text."""
module, separator, attr = value.partition(":")
if not separator or not module or not attr:
raise ValueError("Lazy imports must use 'module:attribute' syntax")
return cls(module=module, attr=attr)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 LazyImport.from_string isn't called or covered anywhere in the package or tests (only the constructor is used, including by entry-point spec authors who instantiate LazyImport("mod", "attr") directly). Per AGENTS.md ("Don't add features beyond what the task requires"), this looks like a speculative public helper. Either remove it or add a test that exercises it (and document "module:attribute" syntax in the rst).

Comment thread src/eegprep/extensions.py
Comment on lines +336 to +352
def _record_from_entry_point(self, entry_point: Any) -> ExtensionRecord:
entry_point_name = str(getattr(entry_point, "name", "") or "<unknown>")
package_name = _entry_point_package_name(entry_point)
try:
loaded = entry_point.load()
candidate = loaded() if callable(loaded) and not isinstance(loaded, ExtensionSpec) else loaded
except Exception as exc:
message = f"Entry point {entry_point_name!r} failed to import: {exc}"
return ExtensionRecord(
name=entry_point_name,
status=ExtensionStatus.FAILED_IMPORT,
source_type=ExtensionSourceType.UNKNOWN,
package_name=package_name,
entry_point_name=entry_point_name,
enabled=True,
errors=(message,),
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 The try block wraps both entry_point.load() and loaded(). If the entry point loads cleanly but the register() callable itself raises (e.g. user-introduced bug at config time), the resulting message is "Entry point 'X' failed to import: ...", which is misleading — the import succeeded. Consider splitting the two steps or rewording, e.g. "Entry point 'X' failed during registration: ..." when loaded() raises. Minor wording, but the message ends up in record.errors and gets logged, so accuracy helps when triaging plugin issues.

Comment thread src/eegprep/extensions.py
Comment on lines +613 to +632
def _status_for_spec(
source_type: ExtensionSourceType,
enabled: bool,
validation: ExtensionValidationResult,
) -> ExtensionStatus:
if validation.invalid_spec:
return ExtensionStatus.INVALID_SPEC
if not enabled:
return ExtensionStatus.DISABLED
if validation.incompatible:
return ExtensionStatus.INCOMPATIBLE
if validation.missing_dependency:
return ExtensionStatus.MISSING_DEPENDENCY
if source_type == ExtensionSourceType.BUNDLED:
return ExtensionStatus.BUNDLED
if source_type == ExtensionSourceType.CURATED:
return ExtensionStatus.CURATED
if source_type == ExtensionSourceType.INSTALLED:
return ExtensionStatus.INSTALLED
return ExtensionStatus.UNKNOWN

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 The status priority puts INVALID_SPEC ahead of DISABLED, but _record_from_spec already skips the compatibility/dependency/resource checks for disabled extensions (passing check_*=False). However basic structural checks (_validate_actions, _validate_pop_functions, _validate_menus, name pattern) still run unconditionally and feed invalid_spec. The net effect is that a disabled extension with a structurally bad spec is reported as INVALID_SPEC rather than DISABLED, which contradicts the docstring intent that disabled extensions "stay visible without dependency checks". Worth deciding which wins — I'd lean toward DISABLED overriding everything (it's a deliberate user/operator state and they may not care about the spec being broken), but the current behavior is at least defensible. Either way, a quick test that pins the contract would help.

@suraj-ranganath
suraj-ranganath merged commit 25bcf16 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