Import S-CANVAS source + iter=1~7 lint cleanup
S-CANVAS (Saman Corp.) — DXF + DEM + AI 기반 3D 조감도 생성 엔진. ~24k LOC Python (scanvas_maker.py 7072 LOC GUI + 구조물 파서/빌더 다수). 이 커밋은 7-iter cleanup이 적용된 상태로 import: - F821 8 + B023 6: 비동기 lambda + except/loop 변수 캡처 NameError (Py3.13에서 reproduce 확인된 진짜 버그) - RUF012 4 + RUF013 1: ClassVar / implicit Optional 명시화 - F811/B905/B904/F401/F841/W293/F541/UP/SIM/RUF/PLR 700+ cleanup/modernization 신규 파일: - ruff.toml: target=py313, Korean unicode/저자 스타일/도메인 복잡도 무력화 - requirements-py313.txt: pyproj>=3.7, scipy>=1.14, numpy>=2.0.2 (Py3.13 wheel) - .gitignore: gcp-key.json, 캐시, 백업, 생성 이미지 제외 검증: ruff 0 errors, py_compile 0 errors, import 33/33 OK on Py3.13.13. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
57
harness/prompt_registry.py
Normal file
57
harness/prompt_registry.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""프롬프트 레지스트리 - 버전 관리 및 재현 가능성 보장."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
class PromptRegistry:
|
||||
"""프롬프트 템플릿 버전을 관리하고 변경 이력을 추적한다."""
|
||||
|
||||
def __init__(self, templates_dir: Path):
|
||||
self.templates_dir = templates_dir
|
||||
|
||||
def list_versions(self) -> list[str]:
|
||||
"""사용 가능한 템플릿 버전 목록을 반환한다 (최신순)."""
|
||||
yamls = sorted(self.templates_dir.glob("prompt_v*.yaml"), reverse=True)
|
||||
return [p.stem for p in yamls]
|
||||
|
||||
def latest_version(self) -> str | None:
|
||||
versions = self.list_versions()
|
||||
return versions[0] if versions else None
|
||||
|
||||
def load_template(self, version: str) -> dict:
|
||||
path = self.templates_dir / f"{version}.yaml"
|
||||
if not path.exists():
|
||||
raise FileNotFoundError(f"템플릿 버전 {version}이 없습니다.")
|
||||
with open(path, encoding="utf-8") as f:
|
||||
return yaml.safe_load(f)
|
||||
|
||||
def compare(self, version_a: str, version_b: str) -> dict:
|
||||
"""두 버전의 차이점을 반환한다."""
|
||||
a = self.load_template(version_a)
|
||||
b = self.load_template(version_b)
|
||||
diff = {}
|
||||
all_keys = set(a) | set(b)
|
||||
for key in all_keys:
|
||||
va, vb = a.get(key), b.get(key)
|
||||
if va != vb:
|
||||
diff[key] = {"old": va, "new": vb}
|
||||
return diff
|
||||
|
||||
def save_new_version(self, new_version: str, template: dict) -> Path:
|
||||
"""새 버전 템플릿을 저장한다."""
|
||||
path = self.templates_dir / f"{new_version}.yaml"
|
||||
if path.exists():
|
||||
raise FileExistsError(f"버전 {new_version}이 이미 존재합니다.")
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
yaml.dump(template, f, allow_unicode=True, default_flow_style=False)
|
||||
return path
|
||||
|
||||
def get_version_for_hash(self, prompt_hash: str, db_session) -> str | None:
|
||||
"""프롬프트 해시로 사용된 버전을 역조회한다."""
|
||||
from harness.logger import JobRecord
|
||||
record = db_session.query(JobRecord).filter_by(prompt_hash=prompt_hash).first()
|
||||
return record.prompt_version if record else None
|
||||
Reference in New Issue
Block a user