उदाहरण
हार्नेस अडैप्टर लिखना
नया Apothem हार्नेस अडैप्टर शुरू से लिखने के लिए चरण-दर-चरण गाइड।
यह गाइड HarnessAdapter प्रोटोकॉल का उपयोग करते हुए, एक Apothem हार्नेस अडैप्टर
को शुरू से बनाने की प्रक्रिया समझाती है।
पूर्वापेक्षाएँ
- Python 3.10+
- ज्ञात कॉन्फ़िगरेशन प्रारूप वाला एक लक्ष्य हार्नेस
- हार्नेस अडैप्टर अमूर्तन की समझ
चरण 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पर एक सत्यापन परीक्षण