Skip to content

The agent that grows with you

fix(plugins): a marker-excluded plugin dependency is never missing

Ben Barclay769c144a3947
diff --git a/hermes_cli/plugins_loader.py b/hermes_cli/plugins_loader.py
index ab54065d995..9f326675b18 100644
--- a/hermes_cli/plugins_loader.py
+++ b/hermes_cli/plugins_loader.py
@@ -216,9 +216,26 @@ def _dist_installed(req: str) -> Optional[bool]:
def missing_python_dependencies(manifest: Any) -> list[str]:
- """The plugin's declared ``python_dependencies`` this process cannot import."""
+ """The plugin's declared ``python_dependencies`` this process cannot import.
+
+ A requirement whose environment marker excludes this interpreter is never missing: PM does not
+ install it here, so reporting it would ask for a restart or repair that can never help."""
return [req for req in getattr(manifest, "python_dependencies", None) or ()
- if _dist_installed(req) is False]
+ if _applies_here(req) and _dist_installed(req) is False]
+
+
+def _applies_here(req: str) -> bool:
+ if ";" not in req:
+ return True
+ try:
+ from packaging.requirements import InvalidRequirement, Requirement
+ except ImportError:
+ return True
+ try:
+ marker = Requirement(req).marker
+ return marker is None or marker.evaluate()
+ except (InvalidRequirement, ValueError, KeyError): # unparseable: keep reporting it
+ return True
def installed_in_selected_environment(requirements: list[str]) -> bool:
diff --git a/tests/hermes_cli/test_plugin_dependency_restart.py b/tests/hermes_cli/test_plugin_dependency_restart.py
index 7136b9c9e62..10d05736fbc 100644
--- a/tests/hermes_cli/test_plugin_dependency_restart.py
+++ b/tests/hermes_cli/test_plugin_dependency_restart.py
@@ -146,3 +146,13 @@ def test_enable_needs_no_restart_when_the_gateway_imports_everything(home, monke
def test_selected_generation_probe_is_false_without_a_selection(home):
assert installed_in_selected_environment([REQ]) is False
+
+
+def test_a_dependency_excluded_by_its_marker_is_never_missing():
+ """PM never installs a marker-excluded requirement here; reporting it would demand a restart
+ (or repair) on every enable that can never help."""
+ from hermes_cli.plugins import PluginManifest
+
+ excluded = f"{DIST}>=1.0,<2; python_version < '3.0'"
+ manifest = PluginManifest(name="depprobe", python_dependencies=[excluded, REQ])
+ assert missing_python_dependencies(manifest) == [REQ]