Skip to content

Commit

Permalink
make the linters happy
Browse files Browse the repository at this point in the history
  • Loading branch information
masci committed Aug 30, 2024
1 parent 8f2829d commit 3946341
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/banks/registries/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from banks.registry import TemplateNotFoundError

# Constants
default_version = "0"
default_index_name = "index.json"
default_meta_path = "meta"
DEFAULT_VERSION = "0"
DEFAULT_INDEX_NAME = "index.json"
DEFAULT_META_PATH = "meta"


class PromptFile(BaseModel):
Expand All @@ -32,12 +32,12 @@ def __init__(self, directory_path: Path, *, force_reindex: bool = False):
raise ValueError(msg)

self._path = directory_path
self._index_path = self._path / default_index_name
self._index_path = self._path / DEFAULT_INDEX_NAME
if not self._index_path.exists() or force_reindex:
self._scan()
else:
self._load()
self._meta_path = self._path / default_meta_path
self._meta_path = self._path / DEFAULT_META_PATH

def _load(self):
self._index = PromptFileIndex.model_validate_json(self._index_path.read_text())
Expand All @@ -50,14 +50,14 @@ def _scan(self):
self._index_path.write_text(self._index.model_dump_json())

def get(self, *, name: str, version: str | None = None) -> "Prompt":
version = version or default_version
version = version or DEFAULT_VERSION
for pf in self._index.files:
if pf.name == name and pf.version == version and pf.path.exists():
return Prompt(pf.path.read_text())
raise TemplateNotFoundError

def set(self, *, name: str, prompt: Prompt, version: str | None = None, overwrite: bool = False):
version = version or default_version
version = version or DEFAULT_VERSION
for pf in self._index.files:
if pf.name == name and pf.version == version and overwrite:
pf.path.write_text(prompt.raw)
Expand All @@ -68,15 +68,15 @@ def set(self, *, name: str, prompt: Prompt, version: str | None = None, overwrit
self._index.files.append(pf)

def get_meta(self, *, name: str, version: str | None = None) -> dict:
version = version or default_version
version = version or DEFAULT_VERSION
meta_path = self._meta_path / f"{name}.{version}.json"
if not meta_path.exists():
msg = f"Meta directory or file for prompt {name}:{version}.jinja not found."
raise FileNotFoundError(msg)
return json.loads(open(meta_path).read())
return json.loads(open(meta_path, encoding="utf-8").read())

def set_meta(self, *, meta: dict, name: str, version: str | None = None, overwrite: bool = False):
version = version or default_version
version = version or DEFAULT_VERSION
if not self._meta_path.exists():
self._meta_path.mkdir()
if Path(self._path / f"{name}.{version}.jinja") not in [pf.path for pf in self._index.files]:
Expand Down

0 comments on commit 3946341

Please sign in to comment.