Skip to content
Apothem
예제

하니스 어댑터 작성하기

새 Apothem 하니스 어댑터를 처음부터 작성하는 단계별 가이드.

이 가이드는 HarnessAdapter 프로토콜을 사용하여 Apothem 하니스 어댑터를 처음부터 만드는 과정을 안내합니다.

사전 요구 사항

1단계: 어댑터 패키지 만들기

mkdir apothem-myadapter
cd apothem-myadapter
# pyproject.toml
[project]
name = "apothem-myadapter"
version = "X.Y.Z"
requires-python = ">=3.10"
dependencies = ["apothem>=X.Y.Z"]  # pin the floor to the apothem release you target

[project.entry-points."apothem.harnesses"]
my-harness = "apothem_myadapter.adapter:MyHarnessAdapter"

2단계: 어댑터 구현하기

# src/apothem_myadapter/adapter.py
from pathlib import Path
from typing import Any

from apothem.harnesses import HarnessAdapter


class MyHarnessAdapter(HarnessAdapter):
    """Implements the HarnessAdapter protocol for "My Harness".

    First-party adapters in the apothem tree usually delegate to the
    ``make_user_scope_adapter`` / ``make_project_scope_adapter`` factories in
    ``apothem.harnesses._shared.wrapper_factories`` and declare their install
    rules in ``src/apothem/lib/propagation-manifest.yaml``. Implementing the
    protocol directly, as shown here, is the clearest way to read its surface.
    """

    @property
    def name(self) -> str:
        return "my-harness"

    @property
    def output_path(self) -> Path:
        # The single native config file this adapter owns on disk.
        return Path.home() / ".myharness" / "config.md"

    def install(self, profile: dict[str, Any]) -> object:
        # ``profile`` is the loaded shared-profile dict (rules, skills, hooks...).
        self.output_path.parent.mkdir(parents=True, exist_ok=True)
        self.output_path.write_text(self._render(profile), encoding="utf-8")
        return self.output_path

    def update(self, profile: dict[str, Any]) -> object:
        return self.install(profile)  # idempotent re-materialization

    def uninstall(self) -> None:
        self.output_path.unlink(missing_ok=True)

    def is_installed(self) -> bool:
        return self.output_path.is_file()

    def verify(self) -> bool:
        return self.output_path.is_file() and self.output_path.stat().st_size > 0

    def _render(self, profile: dict[str, Any]) -> str:
        # Translate the profile into the harness's native format.
        rules = profile.get("rules", [])
        return "\n\n".join(str(rule) for rule in rules)

3단계: 설치하고 테스트하기

pip install -e .
apothem install --harness my-harness
apothem verify --harness my-harness

4단계: pyproject.toml 문서에 추가하기

하니스 페이지 템플릿을 따라 site/content/docs/harnesses/my-harness.mdx에 하니스를 문서화하세요.

5단계: 포함을 위해 제출하기

다음을 포함하여 Apothem 저장소에 풀 리퀘스트를 엽니다:

  • 어댑터 패키지(또는 그에 대한 링크)
  • 문서 페이지
  • tests/packaging/test_myadapter_install.py에 있는 검증 테스트

On this page