style(integrations): apply repository formatting

This commit is contained in:
jinli.yl 2026-09-10 19:21:12 +08:00
parent 47dfd638b8
commit 46d4f3f620
3 changed files with 18 additions and 44 deletions

View file

@ -23,9 +23,7 @@ from .http_backend import HttpReMeBackend
logger = logging.getLogger(__name__)
_NON_FILENAME_CHARS = re.compile(r"[^A-Za-z0-9._-]+")
_SDK_INSTALL_HINT = (
'Embedded ReMe mode requires the SDK. Install it with: pip install "reme-ai[core]"'
)
_SDK_INSTALL_HINT = 'Embedded ReMe mode requires the SDK. Install it with: pip install "reme-ai[core]"'
def _slug(value: str, fallback: str, *, limit: int) -> str:
@ -122,11 +120,7 @@ class ReMeMemoryProvider(MemoryProvider):
with self._backend_lock:
self._close_backend_locked()
self._config = config
self._backend_label = (
config.endpoint
if config.mode == "http"
else f"embedded:{config.workspace_dir}"
)
self._backend_label = config.endpoint if config.mode == "http" else f"embedded:{config.workspace_dir}"
self._recall_timeout = config.recall_timeout
self._health_timeout = config.health_timeout
self._health_retry_seconds = config.health_retry_seconds
@ -266,11 +260,7 @@ class ReMeMemoryProvider(MemoryProvider):
config = load_config()
except ReMeConfigError:
return []
return (
[config.workspace_dir]
if config.mode == "embedded" and config.workspace_dir
else []
)
return [config.workspace_dir] if config.mode == "embedded" and config.workspace_dir else []
def recall_status(self) -> Optional[RecallStatus]:
"""Describe only the content injected by the latest prefetch call."""
@ -294,11 +284,11 @@ class ReMeMemoryProvider(MemoryProvider):
timeout=self._recall_timeout,
)
except ReMeBackendError as exc:
self._next_recall_attempt = (
time.monotonic() + self._health_retry_seconds
)
self._next_recall_attempt = time.monotonic() + self._health_retry_seconds
logger.warning(
"ReMe retrieval failed at %s: %s", self._backend_label, exc
"ReMe retrieval failed at %s: %s",
self._backend_label,
exc,
)
return ""
finally:
@ -320,11 +310,7 @@ class ReMeMemoryProvider(MemoryProvider):
counts = metadata.get("counts")
if isinstance(counts, dict):
returned = counts.get("returned")
if (
isinstance(returned, int)
and not isinstance(returned, bool)
and returned >= 0
):
if isinstance(returned, int) and not isinstance(returned, bool) and returned >= 0:
return returned
results = metadata.get("results")
return len(results) if isinstance(results, list) else 0
@ -494,7 +480,9 @@ class ReMeMemoryProvider(MemoryProvider):
except ReMeBackendError as exc:
self._next_write_attempt = time.monotonic() + self._health_retry_seconds
logger.warning(
"ReMe recording failed at %s: %s", self._backend_label, exc
"ReMe recording failed at %s: %s",
self._backend_label,
exc,
)
finally:
self._close_backend_if_shutdown_locked()

View file

@ -111,7 +111,7 @@ def parse_config(values: dict[str, Any], *, hermes_home: str | Path) -> ReMeConf
endpoint = normalize_http_endpoint(endpoint)
except ValueError as exc:
raise ReMeConfigError(
"ReMe endpoint must be an absolute http(s) URL"
"ReMe endpoint must be an absolute http(s) URL",
) from exc
raw_workspace = str(
@ -119,9 +119,7 @@ def parse_config(values: dict[str, Any], *, hermes_home: str | Path) -> ReMeConf
).strip()
if mode == "embedded" and not raw_workspace:
raise ReMeConfigError("'workspace_dir' is required in embedded mode")
workspace_dir = (
str(Path(raw_workspace).expanduser().absolute()) if raw_workspace else ""
)
workspace_dir = str(Path(raw_workspace).expanduser().absolute()) if raw_workspace else ""
reme_config = str(values.get("reme_config", defaults.reme_config) or "").strip()
if mode == "embedded" and not reme_config:
@ -167,11 +165,7 @@ def parse_config(values: dict[str, Any], *, hermes_home: str | Path) -> ReMeConf
def load_config(hermes_home: str | Path | None = None) -> ReMeConfig:
"""Load current config, falling back to the legacy file when necessary."""
home = (
Path(hermes_home).expanduser()
if hermes_home is not None
else _default_hermes_home()
)
home = Path(hermes_home).expanduser() if hermes_home is not None else _default_hermes_home()
current = config_path(home)
source = current if current.is_file() else legacy_config_path(home)
return parse_config(_read_json_object(source), hermes_home=home)

View file

@ -155,11 +155,7 @@ class EmbeddedReMeBackend:
allowed = {_State.RUNNING}
if allow_starting:
allowed.add(_State.STARTING)
if (
self._state not in allowed
or self._loop is None
or not self._loop.is_running()
):
if self._state not in allowed or self._loop is None or not self._loop.is_running():
coroutine.close()
raise ReMeBackendError(
f"Embedded ReMe is not running (state: {self._state.value})",
@ -236,7 +232,7 @@ class EmbeddedReMeBackend:
)
if not acquired:
raise ReMeBackendError(
"Timed out waiting for an embedded ReMe operation to finish"
"Timed out waiting for an embedded ReMe operation to finish",
)
try:
self._close_locked(deadline)
@ -264,7 +260,7 @@ class EmbeddedReMeBackend:
except concurrent.futures.TimeoutError:
future.cancel()
close_error = TimeoutError(
"Timed out while closing the embedded ReMe Application"
"Timed out while closing the embedded ReMe Application",
)
except BaseException as exc:
close_error = exc
@ -276,11 +272,7 @@ class EmbeddedReMeBackend:
thread.join(timeout=max(0.0, deadline - time.monotonic()))
with self._state_lock:
self._state = (
_State.CLOSED
if thread is None or not thread.is_alive()
else _State.FAILED
)
self._state = _State.CLOSED if thread is None or not thread.is_alive() else _State.FAILED
if self._state is _State.FAILED and self._failure is None:
self._failure = TimeoutError(
"Timed out while stopping the embedded ReMe event loop",