From 2fa5229695a30522d3d7c2ce4b9117e549d686b4 Mon Sep 17 00:00:00 2001 From: claude Date: Mon, 8 Jun 2026 06:06:51 +0000 Subject: [PATCH] refactor: AgentProvider.dockerfile always returns Path, never None The convention is that every provider declares a Dockerfile location; callers that care whether the file actually exists check .is_file(). Drops all `is not None` guards on the property result. --- bot_bottle/agent_provider.py | 13 +++++-------- bot_bottle/backend/docker/capability_apply.py | 2 +- bot_bottle/backend/docker/prepare.py | 13 +++++-------- bot_bottle/backend/smolmachines/prepare.py | 11 ++++------- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/bot_bottle/agent_provider.py b/bot_bottle/agent_provider.py index 25dda1a..594085b 100644 --- a/bot_bottle/agent_provider.py +++ b/bot_bottle/agent_provider.py @@ -128,16 +128,13 @@ class AgentProvider(ABC): template.""" @property - def dockerfile(self) -> Path | None: - """Path to the provider's Dockerfile, or None if no Dockerfile - is declared. + def dockerfile(self) -> Path: + """Path to the provider's Dockerfile. - Default: looks for a `Dockerfile` file next to this provider's + Default: the `Dockerfile` file next to this provider's `agent_provider.py` module. Override to point at a non-standard - path, or return None to signal that no Dockerfile exists (the - provider relies on a pre-built image).""" - path = Path(inspect.getfile(type(self))).parent / "Dockerfile" - return path if path.is_file() else None + path.""" + return Path(inspect.getfile(type(self))).parent / "Dockerfile" @abstractmethod def provision_plan( diff --git a/bot_bottle/backend/docker/capability_apply.py b/bot_bottle/backend/docker/capability_apply.py index 2a7dfb4..5831882 100644 --- a/bot_bottle/backend/docker/capability_apply.py +++ b/bot_bottle/backend/docker/capability_apply.py @@ -95,7 +95,7 @@ def fetch_current_dockerfile(slug: str) -> str: if override is not None: return override repo_dockerfile = get_provider("claude").dockerfile - if repo_dockerfile is not None and repo_dockerfile.is_file(): + if repo_dockerfile.is_file(): return repo_dockerfile.read_text() raise CapabilityApplyError( f"no per-bottle Dockerfile for {slug} and no provider Dockerfile at " diff --git a/bot_bottle/backend/docker/prepare.py b/bot_bottle/backend/docker/prepare.py index cb220e7..1aa7929 100644 --- a/bot_bottle/backend/docker/prepare.py +++ b/bot_bottle/backend/docker/prepare.py @@ -102,14 +102,11 @@ def resolve_plan( dockerfile_path = _resolve_manifest_dockerfile(provider.dockerfile, spec) else: p_dockerfile = provider_obj.dockerfile - if p_dockerfile is not None: - if provider.template in PROVIDER_TEMPLATES: - image_default = provider_runtime.image - else: - image_default = f"bot-bottle-{provider.template}:{slug}" - dockerfile_path = str(p_dockerfile) - else: + if provider.template in PROVIDER_TEMPLATES: image_default = provider_runtime.image + else: + image_default = f"bot-bottle-{provider.template}:{slug}" + dockerfile_path = str(p_dockerfile) image = image_default derived_image = "" runtime_image = image @@ -217,7 +214,7 @@ def resolve_plan( ) dockerfile_content = ( supervise_dockerfile_path.read_text(encoding="utf-8") - if supervise_dockerfile_path is not None and supervise_dockerfile_path.is_file() + if supervise_dockerfile_path.is_file() else "" ) supervise_dir = supervise_state_dir(slug) diff --git a/bot_bottle/backend/smolmachines/prepare.py b/bot_bottle/backend/smolmachines/prepare.py index 132ff91..d53f425 100644 --- a/bot_bottle/backend/smolmachines/prepare.py +++ b/bot_bottle/backend/smolmachines/prepare.py @@ -122,14 +122,11 @@ def resolve_plan( image_default = f"bot-bottle-{provider.template}:{slug}" else: p_dockerfile = provider_obj.dockerfile - if p_dockerfile is not None: - agent_dockerfile_path = str(p_dockerfile) - if provider.template in PROVIDER_TEMPLATES: - image_default = provider_runtime.image - else: - image_default = f"bot-bottle-{provider.template}:{slug}" - else: + agent_dockerfile_path = str(p_dockerfile) + if provider.template in PROVIDER_TEMPLATES: image_default = provider_runtime.image + else: + image_default = f"bot-bottle-{provider.template}:{slug}" agent_image_ref = image_default agent_provision = agent_provision_plan( template=provider.template,