scaffold-module
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesescaffold-module
搭建模块
Generate new modules following pplx-sdk's layered architecture and conventions.
按照pplx-sdk的分层架构和约定生成新模块。
When to use
使用场景
Use this skill when creating a new transport backend, domain service, or shared utility for the SDK.
当你需要为SDK创建新的传输后端、领域服务或共享工具时,使用此技能。
Instructions
操作步骤
- Identify the target layer (core, shared, transport, domain, or client).
- Create the source file with proper imports, type annotations, and docstrings.
- Create the test file in .
tests/test_<module>.py - Update exports in the target package.
__init__.py - Verify with and
pytest tests/test_<module>.py -v.mypy pplx_sdk/
- 确定目标层级(core、shared、transport、domain或client)。
- 创建源文件,包含正确的导入、类型注解和文档字符串。
- 创建测试文件,路径为。
tests/test_<module>.py - **更新**中的目标包导出内容。
__init__.py - 验证:运行和
pytest tests/test_<module>.py -v。mypy pplx_sdk/
Layer Rules
层级规则
| Layer | Directory | May Import From | Purpose |
|---|---|---|---|
| Core | | Nothing | Protocols, types, exceptions |
| Shared | | | Auth, logging, retry utilities |
| Transport | | | HTTP/SSE backends |
| Domain | | | Business logic services |
| Client | | All layers | High-level API |
| 层级 | 目录 | 可导入来源 | 用途 |
|---|---|---|---|
| Core | | 无 | 协议、类型、异常定义 |
| Shared | | | 认证、日志、重试工具 |
| Transport | | | HTTP/SSE后端 |
| Domain | | | 业务逻辑服务 |
| Client | | 所有层级 | 高级API |
Source File Template
源文件模板
python
"""Module description."""
from __future__ import annotations
from typing import Any, Dict, Optional
from pplx_sdk.core.exceptions import TransportError
class NewComponent:
"""Component description.
Example:
>>> component = NewComponent(base_url="https://api.example.com")
>>> result = component.execute()
"""
def __init__(
self,
base_url: str,
auth_token: Optional[str] = None,
timeout: float = 30.0,
) -> None:
"""Initialize component.
Args:
base_url: Base URL for API requests
auth_token: Authentication token
timeout: Request timeout in seconds
"""
self.base_url = base_url
self.auth_token = auth_token
self.timeout = timeoutpython
"""Module description."""
from __future__ import annotations
from typing import Any, Dict, Optional
from pplx_sdk.core.exceptions import TransportError
class NewComponent:
"""Component description.
Example:
>>> component = NewComponent(base_url="https://api.example.com")
>>> result = component.execute()
"""
def __init__(
self,
base_url: str,
auth_token: Optional[str] = None,
timeout: float = 30.0,
) -> None:
"""Initialize component.
Args:
base_url: Base URL for API requests
auth_token: Authentication token
timeout: Request timeout in seconds
"""
self.base_url = base_url
self.auth_token = auth_token
self.timeout = timeoutTest File Template
测试文件模板
python
"""Tests for new_component module."""
import pytest
from pplx_sdk.core.exceptions import TransportError
def test_new_component_initialization():
component = NewComponent(base_url="https://api.test.com")
assert component.base_url == "https://api.test.com"
assert component.timeout == 30.0
def test_new_component_error_handling():
component = NewComponent(base_url="https://invalid.test")
with pytest.raises(TransportError):
component.execute()python
"""Tests for new_component module."""
import pytest
from pplx_sdk.core.exceptions import TransportError
def test_new_component_initialization():
component = NewComponent(base_url="https://api.test.com")
assert component.base_url == "https://api.test.com"
assert component.timeout == 30.0
def test_new_component_error_handling():
component = NewComponent(base_url="https://invalid.test")
with pytest.raises(TransportError):
component.execute()Checklist
检查清单
- at top
from __future__ import annotations - Complete type annotations on all functions
- Google-style docstrings on public APIs
- Custom exceptions from
pplx_sdk.core.exceptions - Tests with Arrange-Act-Assert pattern
- exports updated
__init__.py
- 文件顶部包含
from __future__ import annotations - 所有函数都有完整的类型注解
- 公开API使用Google风格的文档字符串
- 从引入自定义异常
pplx_sdk.core.exceptions - 测试采用Arrange-Act-Assert模式
- 更新了的导出内容
__init__.py