Skip to content

The agent that grows with you

fix(pm): a plugin whose pyproject installs nothing no longer rebuilds the dependency environment

Teknium66610802381d
diff --git a/pm/plugin_declarations.py b/pm/plugin_declarations.py
index 2434bcb8974..9c65c5130e2 100644
--- a/pm/plugin_declarations.py
+++ b/pm/plugin_declarations.py
@@ -72,20 +72,18 @@ class PythonDeclaration:
@property
def installs_packages(self) -> bool:
- """Admission would put packages into the shared environment, the thing dependency consent
- is about. ``dependencies = []`` installs nothing, so it asks no more than no pyproject does."""
+ """Admission would put packages into the shared environment: what dependency consent asks
+ about and what makes the plugin a workspace member. ``dependencies = []`` installs nothing,
+ so like no pyproject it asks no consent and stays out of the environment stamp, which hashes
+ a member's whole tree (each enable or update would build a generation for nothing)."""
return not self.external and (bool(self.install_requirements) or self.pyproject_installs)
- @property
- def is_member(self) -> bool:
- return not self.external and (self.pyproject is not None or bool(self.install_requirements))
-
def python_error(self, version: str) -> str | None:
"""Why this member cannot join a workspace built for *version*; uv intersects every
member's requires-python, so one excluding member fails the whole lock."""
from packaging.specifiers import SpecifierSet
- if not self.is_member or not self.requires_python:
+ if not self.installs_packages or not self.requires_python:
return None
if SpecifierSet(self.requires_python).contains(version, prereleases=True):
return None
diff --git a/pm/workspace.py b/pm/workspace.py
index 98b7fd614eb..67b275dddc2 100644
--- a/pm/workspace.py
+++ b/pm/workspace.py
@@ -158,7 +158,7 @@ def _without_release_age(text: str) -> str:
def _is_member_candidate(plugin_dir: Path) -> bool:
- return read_python_declaration(plugin_dir).is_member
+ return read_python_declaration(plugin_dir).installs_packages
def enabled_plugin_entries(*, proposed_home=None, enabled=None, disabled=None,
@@ -218,7 +218,7 @@ def enabled_member_dirs(*, proposed_home=None, enabled=None, disabled=None) -> l
reason = manifest_version_error(declaration.manifest, path.name)
if reason:
raise InstallError("venv", reason)
- if declaration.is_member:
+ if declaration.installs_packages:
members.append(path)
return members
diff --git a/tests/hermes_cli/test_plugin_historic_compat.py b/tests/hermes_cli/test_plugin_historic_compat.py
index 6e0f1dfb8ad..611f9261ba4 100644
--- a/tests/hermes_cli/test_plugin_historic_compat.py
+++ b/tests/hermes_cli/test_plugin_historic_compat.py
@@ -25,7 +25,7 @@ def _plugin(home, name, *, dependencies=True):
path.mkdir(parents=True)
(path / "plugin.yaml").write_text(f"name: {name}\n", encoding="utf-8")
if dependencies:
- (path / "pyproject.toml").write_text("[project]\n", encoding="utf-8")
+ (path / "pyproject.toml").write_text('[project]\ndependencies = ["requests>=2"]\n', encoding="utf-8")
return path
diff --git a/tests/pm/_fixtures.py b/tests/pm/_fixtures.py
index a15f7f166b1..616470fc8f5 100644
--- a/tests/pm/_fixtures.py
+++ b/tests/pm/_fixtures.py
@@ -7,6 +7,7 @@ import hashlib
from http.server import ThreadingHTTPServer, SimpleHTTPRequestHandler
import importlib
import io
+import json
import os
from pathlib import Path
import shutil
@@ -35,6 +36,21 @@ def _wheel(directory: Path, name: str, version: str = "1.0", requirements=()) ->
return wheel
+def installing_member(plugin: Path, name: str, wheels: Path, *, requires_python: str = ">=3.11") -> None:
+ """Give *plugin* a pyproject that installs one real package, resolvable offline.
+
+ Only a plugin that installs something is a dependency-workspace member: ``dependencies = []``
+ leaves the environment alone, so it cannot stand in for a member.
+ """
+ wheels.mkdir(parents=True, exist_ok=True)
+ wheel = _wheel(wheels, "member_dep")
+ plugin.mkdir(parents=True, exist_ok=True)
+ (plugin / "pyproject.toml").write_text(
+ f'[project]\nname="{name}"\nversion="1"\nrequires-python="{requires_python}"\n'
+ 'dependencies=["member-dep==1.0"]\n[tool.uv]\npackage=false\n'
+ f'[tool.uv.sources]\nmember-dep = {{ path = {json.dumps(wheel.as_posix())} }}\n', encoding="utf-8")
+
+
def stage_host_python(python: Path) -> Path:
"""Place a runnable copy of the test host's interpreter at ``python`` (``<root>/bin/python…``).
diff --git a/tests/pm/test_member_selection.py b/tests/pm/test_member_selection.py
index 3092e714f53..4ef0b51312a 100644
--- a/tests/pm/test_member_selection.py
+++ b/tests/pm/test_member_selection.py
@@ -10,7 +10,7 @@ def test_scoped_members_respect_disabled_and_keep_other_profiles(tmp_path, monke
other = other_home / "plugins" / "same"
for member in (current, other):
member.mkdir(parents=True)
- (member / "pyproject.toml").write_text('[project]\nname="test"\nversion="1"\n')
+ (member / "pyproject.toml").write_text('[project]\nname="test"\nversion="1"\ndependencies=["requests>=2"]\n')
(home / "config.yaml").write_text('plugins:\n enabled: [group/plugin]\n disabled: []\n')
(other_home / "config.yaml").write_text('plugins:\n enabled: [same]\n')
assert set(enabled_member_dirs()) == {current, other}
diff --git a/tests/pm/test_plugin_survival_contract.py b/tests/pm/test_plugin_survival_contract.py
index 7851ff058ae..4abe1204ca9 100644
--- a/tests/pm/test_plugin_survival_contract.py
+++ b/tests/pm/test_plugin_survival_contract.py
@@ -37,6 +37,7 @@ import hermes_yaml as yaml
import pm.workspace as ws
from pm.plugin_inputs import Members
+from tests.pm import _fixtures
def _write_enabled(home: Path, enabled: list, provider: str | None = None) -> None:
@@ -281,12 +282,7 @@ def test_malformed_secondary_cannot_evict_recorded_member(admission_env, monkeyp
profile = home_a / "profiles" / "work"
profile.mkdir(parents=True)
_write_enabled(profile, ["profile-dep"])
- member = profile / "plugins" / "profile-dep"
- member.mkdir(parents=True)
- (member / "pyproject.toml").write_text(
- '[project]\nname="profile-dep"\nversion="1"\nrequires-python=">=3.11"\n'
- 'dependencies=[]\n[tool.uv]\npackage=false\n', encoding="utf-8",
- )
+ _fixtures.installing_member(profile / "plugins" / "profile-dep", "profile-dep", tmp_path / "wheels")
sync_venv(explicit=True)
recorded = Facts(runtime_facts_path(core), strict=True).get("venv")
selected = selected_venv(core)
@@ -295,12 +291,7 @@ def test_malformed_secondary_cannot_evict_recorded_member(admission_env, monkeyp
bad = profile / "config.yaml"
bad.write_text("plugins: [broken]\n", encoding="utf-8")
- candidate = home_a / "plugins" / "new-dep"
- candidate.mkdir(parents=True)
- (candidate / "pyproject.toml").write_text(
- '[project]\nname="new-dep"\nversion="1"\nrequires-python=">=3.11"\n'
- 'dependencies=[]\n[tool.uv]\npackage=false\n', encoding="utf-8",
- )
+ _fixtures.installing_member(home_a / "plugins" / "new-dep", "new-dep", tmp_path / "wheels")
_write_enabled(home_a, ["new-dep"])
assert venv_is_current(project_root=core) is False
assert str(bad) in caplog.text
@@ -332,6 +323,49 @@ def test_malformed_secondary_cannot_evict_recorded_member(admission_env, monkeyp
assert "profile-dep" in (Path(restored["resolved_lock"]).parent / "pyproject.toml").read_text()
[email protected](not _uv_available(), reason="uv not on PATH")
+def test_plugin_whose_pyproject_installs_nothing_keeps_the_environment(admission_env):
+ """``dependencies = []`` (the official agent-importers plugin) puts nothing in the environment:
+ enabling that plugin, and each later change to its files, keeps the selected generation instead
+ of locking and syncing a new one. A plugin with a real dependency still joins the workspace."""
+ import tomllib
+
+ from hermes_cli import plugins_admission as admission
+ from pm.environments import runtime_facts_path, selected_venv
+ from pm.install import sync_venv, venv_is_current
+ from pm.lock import Facts
+
+ tmp_path, home = admission_env
+ core = tmp_path / "core"
+ sync_venv(explicit=True)
+ selected = selected_venv(core)
+ recorded = Facts(runtime_facts_path(core), strict=True).get("venv")
+ plugin = home / "plugins" / "importers"
+ plugin.mkdir(parents=True)
+ (plugin / "plugin.yaml").write_text("name: importers\n", encoding="utf-8")
+ (plugin / "__init__.py").write_text("VERSION = 1\n", encoding="utf-8")
+ (plugin / "pyproject.toml").write_text(
+ '[project]\nname="importers"\nversion="1"\nrequires-python=">=3.11"\ndependencies=[]\n', encoding="utf-8")
+
+ admission.admit_plugin_set_change({"importers"}, set(), active_plugins_dir=home / "plugins")
+
+ assert yaml.safe_load((home / "config.yaml").read_text(encoding="utf-8"))["plugins"]["enabled"] == ["importers"]
+ assert selected_venv(core) == selected
+ assert Facts(runtime_facts_path(core), strict=True).get("venv") == recorded
+ (plugin / "__init__.py").write_text("VERSION = 2\n", encoding="utf-8") # what an update changes
+ assert venv_is_current(project_root=core) is True
+
+ real = home / "plugins" / "real"
+ _fixtures.installing_member(real, "real", tmp_path / "wheels")
+ (real / "plugin.yaml").write_text("name: real\n", encoding="utf-8")
+ admission.admit_plugin_set_change({"importers", "real"}, set(), active_plugins_dir=home / "plugins")
+ workspace = Path(Facts(runtime_facts_path(core), strict=True).get("venv")["resolved_lock"]).parent
+ members = tomllib.loads((workspace / "pyproject.toml").read_text(encoding="utf-8"))["tool"]["uv"]["workspace"]["members"]
+ assert [Path(member).name.split("-")[0] for member in members] == ["real"]
+ assert selected_venv(core) != selected
+ assert venv_is_current(project_root=core) is True
+
+
@pytest.mark.skipif(not _uv_available(), reason="uv not on PATH")
def test_update_sync_disables_plugin_excluded_by_requires_python(admission_env):
"""An update never fails because of a plugin: a member whose requires-python excludes the
@@ -345,12 +379,7 @@ def test_update_sync_disables_plugin_excluded_by_requires_python(admission_env):
tmp_path, home = admission_env
core = tmp_path / "core"
for name, requires in (("fits", ">=3.11"), ("too-old", f"<{sys.version_info[0]}.{sys.version_info[1]}")):
- plugin = home / "plugins" / name
- plugin.mkdir(parents=True)
- (plugin / "pyproject.toml").write_text(
- f'[project]\nname="{name}"\nversion="1"\nrequires-python="{requires}"\n'
- 'dependencies=[]\n[tool.uv]\npackage=false\n', encoding="utf-8",
- )
+ _fixtures.installing_member(home / "plugins" / name, name, tmp_path / "wheels", requires_python=requires)
(home / "config.yaml").write_text("# operator note\nplugins:\n enabled: [fits, too-old]\n", encoding="utf-8")
profile = home / "profiles" / "work"
_write_enabled(profile, [], provider="too-old")
@@ -402,12 +431,7 @@ def test_update_sync_survives_unreadable_secondary_profile(admission_env):
tmp_path, home = admission_env
core = tmp_path / "core"
- member = home / "plugins" / "primary-dep"
- member.mkdir(parents=True)
- (member / "pyproject.toml").write_text(
- '[project]\nname="primary-dep"\nversion="1"\nrequires-python=">=3.11"\n'
- 'dependencies=[]\n[tool.uv]\npackage=false\n', encoding="utf-8",
- )
+ _fixtures.installing_member(home / "plugins" / "primary-dep", "primary-dep", tmp_path / "wheels")
_write_enabled(home, ["primary-dep"])
broken = home / "profiles" / "work" / "config.yaml"
broken.parent.mkdir(parents=True)
@@ -441,12 +465,7 @@ def test_plugin_our_version_rejects_sits_out_without_being_disabled(admission_en
# A tagless checkout (CI's) has no parseable version, which makes requires_hermes permissive.
monkeypatch.setattr(plugins_manifest, "running_hermes_version", lambda: "1.0.0")
for name in ("fits", "needs-newer"):
- plugin = home / "plugins" / name
- plugin.mkdir(parents=True)
- (plugin / "pyproject.toml").write_text(
- f'[project]\nname="{name}"\nversion="1"\nrequires-python=">=3.11"\n'
- 'dependencies=[]\n[tool.uv]\npackage=false\n', encoding="utf-8",
- )
+ _fixtures.installing_member(home / "plugins" / name, name, tmp_path / "wheels")
manifest = home / "plugins" / "needs-newer" / "plugin.yaml"
manifest.write_text("name: needs-newer\nrequires_hermes: '>=999'\n", encoding="utf-8")
_write_enabled(home, ["fits", "needs-newer"])
diff --git a/tests/pm/test_plugins_state.py b/tests/pm/test_plugins_state.py
index cf5b7f263a0..420ca23e68a 100644
--- a/tests/pm/test_plugins_state.py
+++ b/tests/pm/test_plugins_state.py
@@ -166,7 +166,7 @@ def test_member_discovery_uses_real_enabled_config(homes):
from pm.workspace import enabled_member_dirs
home, _ = homes
manifests = {
- "modern/pyproject.toml": "[project]\n",
+ "modern/pyproject.toml": '[project]\ndependencies = ["requests>=2"]\n',
"legacy/plugin.yaml": 'name: legacy\npip_dependencies: ["requests>=2"]\n',
"plain/plugin.yaml": "name: plain\n",
"orphan/pyproject.toml": "[project]\n",
diff --git a/tests/pm/test_worker_publication.py b/tests/pm/test_worker_publication.py
index 8655f6fb61b..3b009518d09 100644
--- a/tests/pm/test_worker_publication.py
+++ b/tests/pm/test_worker_publication.py
@@ -13,7 +13,7 @@ import pytest
from pm.plugin_inputs import Candidates, Selection, StagedUpdate
from tests.pm.test_worker import client, isolated_python, _current_environment
-from tests.pm._fixtures import worker_toolchain
+from tests.pm._fixtures import installing_member, worker_toolchain
def test_worker_publishes_selection_even_when_dependencies_are_current(client, tmp_path, monkeypatch):
@@ -215,7 +215,7 @@ def test_worker_death_recovers_at_each_durable_publication_boundary(
before_tree = tree_digest(target)
if kind == "selection":
if rebuild:
- (target / "pyproject.toml").write_text(core.replace("death-proof", "example"))
+ installing_member(target, "example", tmp_path / "wheels")
arguments = {"plugins": Selection({"home": str(home), "enabled": ["example"], "disabled": []})}
payload = config
else:
@@ -223,7 +223,7 @@ def test_worker_death_recovers_at_each_durable_publication_boundary(
shutil.copytree(target, staged)
(staged / "code.py").write_text("new")
if rebuild:
- (staged / "pyproject.toml").write_text(core.replace("death-proof", "example"))
+ installing_member(staged, "example", tmp_path / "wheels")
arguments = {"plugins": StagedUpdate({
"target": str(target), "staged": str(staged), "target_digest": before_tree,
"old_metadata": {"example": {"revision": "old"}}, "new_metadata": {"example": {"revision": "new"}}})}
diff --git a/website/docs/developer-guide/plugins/index.md b/website/docs/developer-guide/plugins/index.md
index f2d6d1623a7..da03a6ca276 100644
--- a/website/docs/developer-guide/plugins/index.md
+++ b/website/docs/developer-guide/plugins/index.md
@@ -684,6 +684,9 @@ When both exist the `pyproject.toml` wins. What Hermes does with them:
- **`--yes-deps`** answers the dependency question up front, so a headless install (CI, SSH
automation, a container entrypoint) prepares the declared dependencies instead of being refused.
It is mutually exclusive with `--no-deps`.
+- **A `pyproject.toml` that installs nothing** (`dependencies = []`, no `[build-system]`, extras
+ or dependency groups) counts as no declaration: no dependency question, and enabling or updating
+ the plugin leaves the dependency environment as it is.
- **`python_runtime: external`** keeps a sidecar's dependencies out of the shared union.
Hermes does not install that Python runtime or modify its declaration.
- **Nothing to load is an error** — `hermes plugins validate` rejects `plugin.yaml` without