ReMe/reme/core/entry_point.py
jinliyl 54fa3381d7
Some checks failed
CI and Release / Docker / Build and test / amd64 (push) Has been cancelled
CI and Release / Docker / Build and test / arm64 (push) Has been cancelled
Security / CodeQL / Analyze python (push) Has been cancelled
CI / Python quality / Pre-commit (push) Has been cancelled
CI / Python tests / Unit Tests - py3.12 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.13 (push) Has been cancelled
CI / Python tests / Unit Tests - py3.14 (push) Has been cancelled
CI / Python packages / Build and verify distributions (push) Has been cancelled
CI / Python quality / GitHub Actions (push) Has been cancelled
CI / Python tests / Hermes embedded - ubuntu-latest (push) Has been cancelled
CI / Python tests / Hermes embedded - windows-latest (push) Has been cancelled
CI / Python tests / Unit Tests - py3.11 (push) Has been cancelled
CI / ReMe Studio / Studio checks (push) Has been cancelled
Deploy / Documentation / Build documentation (push) Has been cancelled
CI / Windows / CLI smoke - py3.11 (push) Has been cancelled
Security / CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI and Release / Docker / Publish multi-platform tags (push) Has been cancelled
Deploy / Documentation / deploy (push) Has been cancelled
refactor(core): reorganize the ReMe runtime and shared helpers (#769)
* refactor(core): reorganize the ReMe runtime and shared helpers

* test(status): import the base component from its canonical module

* test: remove redundant unit checks

* refactor(core): use canonical runtime imports and shared CLI discovery

Restore evolve behavior to the base branch and update its imports. Use Application as the runtime entry point and encode SSE in the HTTP service.

* fix(cli): honor caller config when service replay is incomplete

Use partial startup overrides for port probes and resolve named configs before requesting the service process working directory.
2026-11-20 22:06:46 +08:00

35 lines
1.3 KiB
Python

"""Safe loading boundary for third-party Python entry points."""
from importlib import metadata
from typing import Any
PLUGIN_ENTRY_POINT_GROUP = "reme.plugins"
CONFIG_ENTRY_POINT_GROUP = "reme.configs"
def find_entry_points(group: str, name: str) -> list[metadata.EntryPoint]:
"""Return all matching entry points without importing their providers."""
return list(metadata.entry_points().select(group=group, name=name))
def unique_entry_point(
entries: list[metadata.EntryPoint],
name: str,
*,
provider: str,
) -> metadata.EntryPoint | None:
"""Return the sole matching entry point, rejecting ambiguous providers."""
if len(entries) > 1:
values = ", ".join(sorted(entry.value for entry in entries))
raise ValueError(f"{provider} '{name}' has multiple installed providers: {values}")
return entries[0] if entries else None
def load_entry_point(entry: metadata.EntryPoint, *, invoke: bool = False) -> Any:
"""Load and optionally invoke an entry point without retaining registrations."""
# Import lazily so config parser imports do not pull in the component graph.
from .registry import R
with R.preserve(allow_mutation=True):
loaded = entry.load()
return loaded() if invoke and callable(loaded) else loaded