Skip to content

Commit 66e1e0d

Browse files
committed
chore: clean up docstrings and remove module-level comments
1 parent 067f717 commit 66e1e0d

5 files changed

Lines changed: 14 additions & 227 deletions

File tree

graver/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
"""graver — Git-like version control for LLM prompts.
22
3-
Save, diff, and roll back prompt versions with a simple Python API.
4-
All data is stored as plain text files under a ``.graver/`` directory.
5-
63
Example::
74
85
from graver import Prompt

graver/cli.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""Command-line interface for graver."""
2-
31
import argparse
42
import sys
53

graver/core.py

Lines changed: 13 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,27 @@
1-
"""Public-facing API for graver."""
2-
31
from pathlib import Path
42

53
from graver.exceptions import PromptNotFoundError
64
from graver.storage import Storage
75

86

97
class Prompt:
10-
"""Git-like version control for a single named prompt.
11-
12-
Args:
13-
name: Unique identifier for this prompt.
14-
base_dir: Root directory for all prompt storage. Defaults to ".graver".
15-
"""
8+
"""Git-like version control for a single named prompt."""
169

1710
def __init__(self, name: str, base_dir: str = ".graver") -> None:
1811
self.name = name
1912
self._storage = Storage(base_dir=base_dir)
2013

2114
@staticmethod
2215
def list_all(base_dir: str = ".graver") -> list[str]:
23-
"""Return the names of all saved prompts in the given base directory.
24-
25-
Args:
26-
base_dir: Root directory for all prompt storage.
27-
28-
Returns:
29-
A sorted list of prompt name strings.
30-
"""
16+
"""Return the names of all saved prompts in the given base directory."""
3117
return Storage(base_dir=base_dir).list_prompts()
3218

3319
def save(self, content: str) -> str:
34-
"""Save a new version of this prompt.
35-
36-
Args:
37-
content: The prompt text to persist.
38-
39-
Returns:
40-
The version string for the saved version (e.g. "v1").
41-
"""
20+
"""Save a new version and return its version string (e.g. "v1")."""
4221
return self._storage.save(self.name, content)
4322

4423
def save_from_file(self, filepath: str) -> str:
45-
"""Read prompt content from a file and save it as a new version.
46-
47-
Args:
48-
filepath: Path to the file whose contents will be saved.
49-
50-
Returns:
51-
The version string for the saved version (e.g. "v1").
52-
53-
Raises:
54-
PromptNotFoundError: If the specified file does not exist.
55-
"""
24+
"""Read content from a file and save it as a new version."""
5625
path = Path(filepath)
5726
if not path.exists():
5827
raise PromptNotFoundError(
@@ -62,50 +31,23 @@ def save_from_file(self, filepath: str) -> str:
6231
return self.save(content)
6332

6433
def get(self, version: str | None = None) -> str:
65-
"""Retrieve a version of this prompt.
66-
67-
Args:
68-
version: Version string to retrieve (e.g. "v2"). If None,
69-
returns the latest saved version.
70-
71-
Returns:
72-
The prompt text for the requested version.
73-
"""
34+
"""Return the prompt text for the given version, or the latest if None."""
7435
return self._storage.get(self.name, version)
7536

7637
def log(self) -> list[dict]:
77-
"""Return the full version history of this prompt.
78-
79-
Returns:
80-
A list of dicts ordered from oldest to newest. Each dict
81-
contains "version" (str), "timestamp" (str), and "is_main" (bool).
82-
"""
38+
"""Return the full version history, oldest to newest, with is_main flag."""
8339
main = self._storage.get_main(self.name)
8440
history = self._storage.history(self.name)
8541
for entry in history:
8642
entry["is_main"] = entry["version"] == main
8743
return history
8844

8945
def set_main(self, version: str) -> None:
90-
"""Mark a specific version as the main (canonical) version.
91-
92-
Args:
93-
version: Version string to mark as main (e.g. "v2").
94-
95-
Raises:
96-
VersionNotFoundError: If the version does not exist.
97-
"""
46+
"""Pin a version as the canonical main."""
9847
self._storage.set_main(self.name, version)
9948

10049
def get_main(self) -> str:
101-
"""Return the content of the main version.
102-
103-
Returns:
104-
The prompt text of the main version.
105-
106-
Raises:
107-
PromptNotFoundError: If no main version has been set.
108-
"""
50+
"""Return the content of the pinned main version."""
10951
version = self._storage.get_main(self.name)
11052
if version is None:
11153
raise PromptNotFoundError(
@@ -114,56 +56,19 @@ def get_main(self) -> str:
11456
return self._storage.get(self.name, version)
11557

11658
def delete_prompt(self) -> None:
117-
"""Delete this prompt and all its versions.
118-
119-
Removes all version files, history, and the main pointer.
120-
121-
Raises:
122-
PromptNotFoundError: If the prompt does not exist.
123-
StorageError: If the directory removal fails.
124-
"""
59+
"""Delete this prompt and all its versions."""
12560
self._storage.delete_prompt(self.name)
12661

12762
def delete_version(self, version: str) -> None:
128-
"""Delete a specific version of this prompt.
129-
130-
Removes the version file and its history entry. If the deleted version
131-
was marked as main, the main pointer is also cleared.
132-
133-
Args:
134-
version: Version string to delete (e.g. "v2").
135-
136-
Raises:
137-
VersionNotFoundError: If the version does not exist.
138-
StorageError: If the file delete operation fails.
139-
"""
63+
"""Delete a specific version; clears the main pointer if it was main."""
14064
self._storage.delete_version(self.name, version)
14165

14266
def diff(self, v1: str, v2: str) -> dict:
143-
"""Compute a line-by-line diff between two versions.
144-
145-
Args:
146-
v1: The base version string (e.g. "v1").
147-
v2: The target version string (e.g. "v2").
148-
149-
Returns:
150-
A dict with keys "added", "removed", and "unchanged", each
151-
containing a list of strings representing the changed lines.
152-
"""
67+
"""Return raw line-by-line diff between two versions."""
15368
return self._storage.diff(self.name, v1, v2)
15469

15570
def changes(self, v1: str | None = None, v2: str | None = None) -> str:
156-
"""Return a formatted change report between two versions.
157-
158-
If no versions are specified, compares the last two saved versions.
159-
160-
Args:
161-
v1: Base version (e.g. "v1"). If None, uses second-to-last.
162-
v2: Target version (e.g. "v2"). If None, uses latest.
163-
164-
Returns:
165-
A formatted string showing added and removed lines.
166-
"""
71+
"""Return a formatted change report; defaults to the last two versions."""
16772
history = self._storage.history(self.name)
16873
if len(history) < 2:
16974
return "Need at least 2 versions to compare."
@@ -190,14 +95,7 @@ def changes(self, v1: str | None = None, v2: str | None = None) -> str:
19095
return "\n".join(lines)
19196

19297
def show(self, version: str | None = None) -> str:
193-
"""Return a version's full content with a formatted header.
194-
195-
Args:
196-
version: Version to display (e.g. "v2"). If None, shows latest.
197-
198-
Returns:
199-
A formatted string with header and prompt content.
200-
"""
98+
"""Return a version's content with a formatted header."""
20199
history = self._storage.history(self.name)
202100
content = self._storage.get(self.name, version)
203101

graver/exceptions.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
"""Custom exceptions for the graver library."""
2-
3-
41
class GraverError(Exception):
52
"""Base class for all graver errors."""
63

graver/storage.py

Lines changed: 1 addition & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""File-system storage backend for graver."""
2-
31
import difflib
42
import json
53
from datetime import datetime
@@ -13,11 +11,7 @@
1311

1412

1513
class Storage:
16-
"""Handles all file system operations for graver.
17-
18-
Args:
19-
base_dir: Root directory for all prompt storage.
20-
"""
14+
"""File-system backend; stores each prompt version as a plain-text file."""
2115

2216
def __init__(self, base_dir: str = ".graver") -> None:
2317
self._base = Path(base_dir).resolve()
@@ -50,18 +44,6 @@ def _latest_version_num(self, prompt_dir: Path) -> int:
5044
return max(int(f.stem[1:]) for f in files)
5145

5246
def save(self, name: str, content: str) -> str:
53-
"""Save a new version of a prompt.
54-
55-
Args:
56-
name: Prompt identifier.
57-
content: The prompt text to persist.
58-
59-
Returns:
60-
The version string for the saved version (e.g. "v1").
61-
62-
Raises:
63-
StorageError: If any file write operation fails.
64-
"""
6547
prompt_dir = self._prompt_dir(name)
6648
prompt_dir.mkdir(parents=True, exist_ok=True)
6749

@@ -95,19 +77,6 @@ def save(self, name: str, content: str) -> str:
9577
return version
9678

9779
def get(self, name: str, version: str | None = None) -> str:
98-
"""Retrieve the content of a prompt version.
99-
100-
Args:
101-
name: Prompt identifier.
102-
version: Version string to retrieve. If None, returns the latest.
103-
104-
Returns:
105-
The prompt text for the requested version.
106-
107-
Raises:
108-
PromptNotFoundError: If the prompt directory does not exist.
109-
VersionNotFoundError: If the requested version file does not exist.
110-
"""
11180
prompt_dir = self._prompt_dir(name)
11281
if not prompt_dir.exists():
11382
raise PromptNotFoundError(
@@ -126,17 +95,6 @@ def get(self, name: str, version: str | None = None) -> str:
12695
return target.read_text(encoding="utf-8")
12796

12897
def history(self, name: str) -> list[dict]:
129-
"""Return the version history for a prompt.
130-
131-
Args:
132-
name: Prompt identifier.
133-
134-
Returns:
135-
A list of dicts with keys "version" and "timestamp".
136-
137-
Raises:
138-
PromptNotFoundError: If the prompt directory does not exist.
139-
"""
14098
prompt_dir = self._prompt_dir(name)
14199
if not prompt_dir.exists():
142100
raise PromptNotFoundError(
@@ -150,19 +108,6 @@ def history(self, name: str) -> list[dict]:
150108
return json.loads(history_path.read_text(encoding="utf-8"))
151109

152110
def diff(self, name: str, v1: str, v2: str) -> dict:
153-
"""Compute a line-by-line diff between two versions.
154-
155-
Args:
156-
name: Prompt identifier.
157-
v1: The base version string (e.g. "v1").
158-
v2: The target version string (e.g. "v2").
159-
160-
Returns:
161-
A dict with keys "added", "removed", and "unchanged".
162-
163-
Raises:
164-
VersionNotFoundError: If either version does not exist.
165-
"""
166111
lines1 = self.get(name, v1).splitlines(keepends=True)
167112
lines2 = self.get(name, v2).splitlines(keepends=True)
168113

@@ -179,16 +124,6 @@ def diff(self, name: str, v1: str, v2: str) -> dict:
179124
return {"added": added, "removed": removed, "unchanged": unchanged}
180125

181126
def set_main(self, name: str, version: str) -> None:
182-
"""Mark a specific version as the main (canonical) version.
183-
184-
Args:
185-
name: Prompt identifier.
186-
version: Version string to mark as main (e.g. "v2").
187-
188-
Raises:
189-
VersionNotFoundError: If the version does not exist.
190-
StorageError: If the file write fails.
191-
"""
192127
if not self._version_file(name, version).exists():
193128
raise VersionNotFoundError(
194129
f"Version '{version}' not found for prompt '{name}'."
@@ -202,19 +137,6 @@ def set_main(self, name: str, version: str) -> None:
202137
raise StorageError(f"Failed to write main for '{name}': {exc}") from exc
203138

204139
def delete_version(self, name: str, version: str) -> None:
205-
"""Delete a specific version of a prompt.
206-
207-
Removes the version file and its entry from history. If the deleted
208-
version was marked as main, the main pointer is also cleared.
209-
210-
Args:
211-
name: Prompt identifier.
212-
version: Version string to delete (e.g. "v2").
213-
214-
Raises:
215-
VersionNotFoundError: If the version does not exist.
216-
StorageError: If the file delete operation fails.
217-
"""
218140
version_path = self._version_file(name, version)
219141
if not version_path.exists():
220142
raise VersionNotFoundError(
@@ -243,18 +165,6 @@ def delete_version(self, name: str, version: str) -> None:
243165
self._main_file(name).unlink(missing_ok=True)
244166

245167
def delete_prompt(self, name: str) -> None:
246-
"""Delete a prompt and all its versions.
247-
248-
Removes the entire prompt directory including all version files,
249-
history, and the main pointer.
250-
251-
Args:
252-
name: Prompt identifier.
253-
254-
Raises:
255-
PromptNotFoundError: If the prompt does not exist.
256-
StorageError: If the directory removal fails.
257-
"""
258168
prompt_dir = self._prompt_dir(name)
259169
if not prompt_dir.exists():
260170
raise PromptNotFoundError(f"Prompt '{name}' not found.")
@@ -266,22 +176,9 @@ def delete_prompt(self, name: str) -> None:
266176
raise StorageError(f"Failed to delete prompt '{name}': {exc}") from exc
267177

268178
def list_prompts(self) -> list[str]:
269-
"""Return the names of all saved prompts.
270-
271-
Returns:
272-
A sorted list of prompt name strings.
273-
"""
274179
return sorted(d.name for d in self._base.iterdir() if d.is_dir())
275180

276181
def get_main(self, name: str) -> str | None:
277-
"""Return the version string marked as main, or None if not set.
278-
279-
Args:
280-
name: Prompt identifier.
281-
282-
Returns:
283-
The main version string (e.g. "v2"), or None if not set.
284-
"""
285182
main_path = self._main_file(name)
286183
if not main_path.exists():
287184
return None

0 commit comments

Comments
 (0)