Repository navigation
Add extension SDK registry - #120
suraj-ranganath merged 2 commits into
Conversation
|
Claude finished @suraj-ranganath's task in 4m 44s —— View job PR Review: Add extension SDK registry
SummarySolid 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 Inline findings
Non-blocking notes
|
| ========================= | ||
| Extension SDK and Registry | ||
| ========================= |
There was a problem hiding this comment.
🤖 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 =.
| ========================= | |
| Extension SDK and Registry | |
| ========================= | |
| ========================== | |
| Extension SDK and Registry | |
| ========================== |
| 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 |
There was a problem hiding this comment.
🤖 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.
| if operator == "~=" and comparison < 0: | ||
| return False |
There was a problem hiding this comment.
🤖 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.
| 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,) |
There was a problem hiding this comment.
🤖 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.
| @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) |
There was a problem hiding this comment.
🤖 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).
| 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,), | ||
| ) |
There was a problem hiding this comment.
🤖 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.
| 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 |
There was a problem hiding this comment.
🤖 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.
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