Skip to content

Commit 88e541e

Browse files
authored
refactor: rename feedback classes (#91)
To avoid confusion with prompt user feedback.
1 parent 31740cf commit 88e541e

File tree

5 files changed

+49
-51
lines changed

5 files changed

+49
-51
lines changed

src/git_draft/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .common import (
1515
PROGRAM,
1616
Config,
17-
Feedback,
17+
Progress,
1818
UnreachableError,
1919
ensure_state_home,
2020
)
@@ -167,9 +167,9 @@ async def run() -> None: # noqa: PLR0912 PLR0915
167167
datefmt="%m-%d %H:%M",
168168
)
169169

170-
feedback = Feedback.dynamic() if sys.stdin.isatty() else Feedback.static()
170+
progress = Progress.dynamic() if sys.stdin.isatty() else Progress.static()
171171
repo = Repo.enclosing(Path(opts.root) if opts.root else Path.cwd())
172-
drafter = Drafter.create(repo, Store.persistent(), feedback)
172+
drafter = Drafter.create(repo, Store.persistent(), progress)
173173
match getattr(opts, "command", "new"):
174174
case "new":
175175
bot_config = None

src/git_draft/common.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -144,32 +144,32 @@ def _tagged(text: str, /, **kwargs) -> str:
144144
return f"{text} [{', '.join(tags)}]" if tags else text
145145

146146

147-
class Feedback:
148-
"""User feedback interface"""
147+
class Progress:
148+
"""Progress feedback interface"""
149149

150150
def report(self, text: str, **tags) -> None: # pragma: no cover
151151
raise NotImplementedError()
152152

153153
def spinner(
154154
self, text: str, **tags
155155
) -> contextlib.AbstractContextManager[
156-
FeedbackSpinner
156+
ProgressSpinner
157157
]: # pragma: no cover
158158
raise NotImplementedError()
159159

160160
@staticmethod
161-
def dynamic() -> Feedback:
162-
"""Feedback suitable for interactive terminals"""
163-
return _DynamicFeedback()
161+
def dynamic() -> Progress:
162+
"""Progress suitable for interactive terminals"""
163+
return _DynamicProgress()
164164

165165
@staticmethod
166-
def static() -> Feedback:
167-
"""Feedback suitable for pipes, etc."""
168-
return _StaticFeedback()
166+
def static() -> Progress:
167+
"""Progress suitable for pipes, etc."""
168+
return _StaticProgress()
169169

170170

171-
class FeedbackSpinner:
172-
"""Operation feedback tracker"""
171+
class ProgressSpinner:
172+
"""Operation progress tracker"""
173173

174174
@contextlib.contextmanager
175175
def hidden(self) -> Iterator[None]:
@@ -179,9 +179,9 @@ def update(self, text: str, **tags) -> None: # pragma: no cover
179179
raise NotImplementedError()
180180

181181

182-
class _DynamicFeedback(Feedback):
182+
class _DynamicProgress(Progress):
183183
def __init__(self) -> None:
184-
self._spinner: _DynamicFeedbackSpinner | None = None
184+
self._spinner: _DynamicProgressSpinner | None = None
185185

186186
def report(self, text: str, **tags) -> None:
187187
message = f"☞ {_tagged(text, **tags)}"
@@ -191,10 +191,10 @@ def report(self, text: str, **tags) -> None:
191191
print(message) # noqa
192192

193193
@contextlib.contextmanager
194-
def spinner(self, text: str, **tags) -> Iterator[FeedbackSpinner]:
194+
def spinner(self, text: str, **tags) -> Iterator[ProgressSpinner]:
195195
assert not self._spinner
196196
with yaspin.yaspin(text=_tagged(text, **tags)) as spinner:
197-
self._spinner = _DynamicFeedbackSpinner(spinner)
197+
self._spinner = _DynamicProgressSpinner(spinner)
198198
try:
199199
yield self._spinner
200200
except Exception:
@@ -206,7 +206,7 @@ def spinner(self, text: str, **tags) -> Iterator[FeedbackSpinner]:
206206
self._spinner = None
207207

208208

209-
class _DynamicFeedbackSpinner(FeedbackSpinner):
209+
class _DynamicProgressSpinner(ProgressSpinner):
210210
def __init__(self, yaspin: yaspin.core.Yaspin) -> None:
211211
self.yaspin = yaspin
212212

@@ -219,19 +219,19 @@ def update(self, text: str, **tags) -> None:
219219
self.yaspin.text = _tagged(text, **tags)
220220

221221

222-
class _StaticFeedback(Feedback):
222+
class _StaticProgress(Progress):
223223
def report(self, text: str, **tags) -> None:
224224
print(_tagged(text, **tags)) # noqa
225225

226226
@contextlib.contextmanager
227-
def spinner(self, text: str, **tags) -> Iterator[FeedbackSpinner]:
227+
def spinner(self, text: str, **tags) -> Iterator[ProgressSpinner]:
228228
self.report(text, **tags)
229-
yield _StaticFeedbackSpinner(self)
229+
yield _StaticProgressSpinner(self)
230230

231231

232-
class _StaticFeedbackSpinner(FeedbackSpinner):
233-
def __init__(self, feedback: _StaticFeedback) -> None:
234-
self._feedback = feedback
232+
class _StaticProgressSpinner(ProgressSpinner):
233+
def __init__(self, progress: _StaticProgress) -> None:
234+
self._progress = progress
235235

236236
def update(self, text: str, **tags) -> None:
237-
self._feedback.report(text, **tags)
237+
self._progress.report(text, **tags)

src/git_draft/drafter.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from typing import Literal
1515

1616
from .bots import Action, Bot, Goal
17-
from .common import Feedback, JSONObject, qualified_class_name, reindent
17+
from .common import JSONObject, Progress, qualified_class_name, reindent
1818
from .git import SHA, Repo
1919
from .prompt import TemplatedPrompt
2020
from .store import Store, sql
@@ -89,16 +89,16 @@ def _active_folio(repo: Repo) -> Folio | None:
8989
class Drafter:
9090
"""Draft state orchestrator"""
9191

92-
def __init__(self, store: Store, repo: Repo, feedback: Feedback) -> None:
92+
def __init__(self, store: Store, repo: Repo, progress: Progress) -> None:
9393
self._store = store
9494
self._repo = repo
95-
self._feedback = feedback
95+
self._progress = progress
9696

9797
@classmethod
98-
def create(cls, repo: Repo, store: Store, feedback: Feedback) -> Drafter:
98+
def create(cls, repo: Repo, store: Store, progress: Progress) -> Drafter:
9999
with store.cursor() as cursor:
100100
cursor.executescript(sql("create-tables"))
101-
return cls(store, repo, feedback)
101+
return cls(store, repo, progress)
102102

103103
async def generate_draft(
104104
self,
@@ -107,7 +107,7 @@ async def generate_draft(
107107
merge_strategy: DraftMergeStrategy | None = None,
108108
prompt_transform: Callable[[str], str] | None = None,
109109
) -> Draft:
110-
with self._feedback.spinner("Preparing prompt...") as spinner:
110+
with self._progress.spinner("Preparing prompt...") as spinner:
111111
# Handle prompt templating and editing. We do this first in case
112112
# this fails, to avoid creating unnecessary branches.
113113
toolbox, dirty = RepoToolbox.for_working_dir(self._repo)
@@ -141,8 +141,8 @@ async def generate_draft(
141141
)
142142

143143
# Run the bot to generate the change.
144-
operation_recorder = _OperationRecorder(self._feedback)
145-
with self._feedback.spinner("Running bot...") as spinner:
144+
operation_recorder = _OperationRecorder(self._progress)
145+
with self._progress.spinner("Running bot...") as spinner:
146146
change = await self._generate_change(
147147
bot,
148148
Goal(prompt_contents),
@@ -151,7 +151,7 @@ async def generate_draft(
151151
),
152152
)
153153
if change.action.question:
154-
self._feedback.report("Requested feedback.")
154+
self._progress.report("Requested progress.")
155155
spinner.update(
156156
"Completed bot run.",
157157
runtime=round(change.walltime.total_seconds(), 1),
@@ -167,7 +167,7 @@ async def generate_draft(
167167
walltime=change.walltime,
168168
token_count=change.action.token_count,
169169
)
170-
with self._feedback.spinner("Creating draft commit...") as spinner:
170+
with self._progress.spinner("Creating draft commit...") as spinner:
171171
if dirty:
172172
parent_commit_rev = self._commit_tree(
173173
toolbox.tree_sha(), "HEAD", "sync(prompt)"
@@ -214,7 +214,7 @@ async def generate_draft(
214214
_logger.info("Created new draft in folio %s.", folio.id)
215215

216216
if merge_strategy:
217-
with self._feedback.spinner("Merging changes...") as spinner:
217+
with self._progress.spinner("Merging changes...") as spinner:
218218
if parent_commit_rev != "HEAD":
219219
# If there was a sync(prompt) commit, we move forward to
220220
# it. This will avoid conflicts with earlier changes.
@@ -260,7 +260,7 @@ def quit_folio(self) -> None:
260260
if check_call.code:
261261
raise RuntimeError("Origin branch diverged, please rebase first")
262262

263-
with self._feedback.spinner("Switching branch...") as spinner:
263+
with self._progress.spinner("Switching branch...") as spinner:
264264
# Create a reference to the current state for later analysis.
265265
self._sync_head("finalize")
266266
self._repo.git("update-ref", _draft_ref(folio.id, "@"), "HEAD")
@@ -287,7 +287,7 @@ def quit_folio(self) -> None:
287287
_logger.info("Quit %s.", folio)
288288

289289
def _create_folio(self) -> Folio:
290-
with self._feedback.spinner("Creating draft branch...") as spinner:
290+
with self._progress.spinner("Creating draft branch...") as spinner:
291291
origin_branch = self._repo.active_branch()
292292
if origin_branch is None:
293293
raise RuntimeError("No currently active branch")
@@ -436,33 +436,33 @@ class _OperationRecorder(ToolVisitor):
436436
analysis.
437437
"""
438438

439-
def __init__(self, feedback: Feedback) -> None:
439+
def __init__(self, progress: Progress) -> None:
440440
self.operations = list[_Operation]()
441-
self._feedback = feedback
441+
self._progress = progress
442442

443443
def on_list_files(
444444
self, paths: Sequence[PurePosixPath], reason: str | None
445445
) -> None:
446446
count = len(paths)
447-
self._feedback.report("Listed available files.", count=count)
447+
self._progress.report("Listed available files.", count=count)
448448
self._record(reason, "list_files", count=count)
449449

450450
def on_read_file(
451451
self, path: PurePosixPath, contents: str | None, reason: str | None
452452
) -> None:
453453
size = -1 if contents is None else len(contents)
454-
self._feedback.report(f"Read {path}.", length=size)
454+
self._progress.report(f"Read {path}.", length=size)
455455
self._record(reason, "read_file", path=str(path), size=size)
456456

457457
def on_write_file(
458458
self, path: PurePosixPath, contents: str, reason: str | None
459459
) -> None:
460460
size = len(contents)
461-
self._feedback.report(f"Wrote {path}.", length=size)
461+
self._progress.report(f"Wrote {path}.", length=size)
462462
self._record(reason, "write_file", path=str(path), size=size)
463463

464464
def on_delete_file(self, path: PurePosixPath, reason: str | None) -> None:
465-
self._feedback.report(f"Deleted {path}.")
465+
self._progress.report(f"Deleted {path}.")
466466
self._record(reason, "delete_file", path=str(path))
467467

468468
def on_rename_file(
@@ -471,7 +471,7 @@ def on_rename_file(
471471
dst_path: PurePosixPath,
472472
reason: str | None,
473473
) -> None:
474-
self._feedback.report(f"Renamed {src_path} to {dst_path}.")
474+
self._progress.report(f"Renamed {src_path} to {dst_path}.")
475475
self._record(
476476
reason,
477477
"rename_file",

src/git_draft/prompt.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@ def _load_prompt(
187187
assert env.loader, "No loader in environment"
188188
template = env.loader.load(env, str(rel_path))
189189
context: _Context = dict(
190-
program=name,
191-
prompt=_load_layouts(),
192-
toolbox=toolbox
190+
program=name, prompt=_load_layouts(), toolbox=toolbox
193191
)
194192
try:
195193
module = template.make_module(vars=cast(dict, context))

tests/git_draft/drafter_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66

77
from git_draft.bots import Action, Bot, Goal, Toolbox
8-
from git_draft.common import Feedback
8+
from git_draft.common import Progress
99
import git_draft.drafter as sut
1010
from git_draft.git import SHA, GitError, Repo
1111
from git_draft.store import Store
@@ -46,7 +46,7 @@ def setup(self, repo: Repo, repo_fs: RepoFS) -> None:
4646
self._repo = repo
4747
self._fs = repo_fs
4848
self._drafter = sut.Drafter.create(
49-
repo, Store.in_memory(), Feedback.static()
49+
repo, Store.in_memory(), Progress.static()
5050
)
5151

5252
def _commits(self, ref: str | None = None) -> Sequence[SHA]:

0 commit comments

Comments
 (0)