Skip to content

Commit 8433836

Browse files
Kasper Jungeclaude
authored andcommitted
refactor: make format_duration a public function since it's used cross-module
The function was prefixed with _ (marking it private) but imported by cli.py and both test files. Removing the underscore makes the API boundary honest. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 172c461 commit 8433836

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

src/ralphify/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from ralphify._frontmatter import CHECK_MARKER, CONTEXT_MARKER, INSTRUCTION_MARKER, PROMPT_MARKER
2020
from ralphify.checks import discover_checks
2121
from ralphify.contexts import discover_contexts
22-
from ralphify.engine import RunConfig, RunState, _format_duration, run_loop
22+
from ralphify.engine import RunConfig, RunState, format_duration, run_loop
2323
from ralphify.instructions import discover_instructions
2424
from ralphify.prompts import discover_prompts, is_prompt_name, resolve_prompt_name
2525
from ralphify.detector import detect_project
@@ -296,7 +296,7 @@ def emit(self, event: Event) -> None:
296296

297297
def _on_run_started(self, d: dict) -> None:
298298
if d.get("timeout"):
299-
self._rprint(f"[dim]Timeout: {_format_duration(d['timeout'])} per iteration[/dim]")
299+
self._rprint(f"[dim]Timeout: {format_duration(d['timeout'])} per iteration[/dim]")
300300
if d.get("checks"):
301301
self._rprint(f"[dim]Checks: {d['checks']} enabled[/dim]")
302302
if d.get("contexts"):

src/ralphify/engine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def consume_reload_request(self) -> bool:
121121
return False
122122

123123

124-
def _format_duration(seconds: float) -> str:
124+
def format_duration(seconds: float) -> str:
125125
"""Format duration in human-readable form."""
126126
if seconds < 60:
127127
return f"{seconds:.1f}s"
@@ -270,7 +270,7 @@ def _execute_agent(
270270
log_file = _write_log(log_path_dir, iteration, e.stdout, e.stderr)
271271

272272
elapsed = time.monotonic() - start
273-
duration = _format_duration(elapsed)
273+
duration = format_duration(elapsed)
274274

275275
if returncode is None:
276276
event_type = EventType.ITERATION_TIMED_OUT

tests/test_cli.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ralphify.contexts import Context, ContextResult
1111
from ralphify.cli import app, CONFIG_FILENAME
1212
from ralphify._templates import RALPH_TOML_TEMPLATE, PROMPT_TEMPLATE
13-
from ralphify.engine import _format_duration
13+
from ralphify.engine import format_duration
1414

1515
runner = CliRunner()
1616

@@ -531,18 +531,18 @@ def test_timeout_shows_in_header(self, mock_run, tmp_path, monkeypatch):
531531

532532
class TestFormatDuration:
533533
def test_seconds(self):
534-
assert _format_duration(5.3) == "5.3s"
535-
assert _format_duration(0.1) == "0.1s"
536-
assert _format_duration(59.9) == "59.9s"
534+
assert format_duration(5.3) == "5.3s"
535+
assert format_duration(0.1) == "0.1s"
536+
assert format_duration(59.9) == "59.9s"
537537

538538
def test_minutes(self):
539-
assert _format_duration(60) == "1m 0s"
540-
assert _format_duration(90.5) == "1m 30s"
541-
assert _format_duration(3599) == "59m 59s"
539+
assert format_duration(60) == "1m 0s"
540+
assert format_duration(90.5) == "1m 30s"
541+
assert format_duration(3599) == "59m 59s"
542542

543543
def test_hours(self):
544-
assert _format_duration(3600) == "1h 0m"
545-
assert _format_duration(5400) == "1h 30m"
544+
assert format_duration(3600) == "1h 0m"
545+
assert format_duration(5400) == "1h 30m"
546546

547547

548548
def _setup_check(tmp_path, name="ruff-lint", command="ruff check .", enabled=True,

tests/test_engine.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from unittest.mock import patch
88

99
from ralphify._events import EventType, NullEmitter, QueueEmitter
10-
from ralphify.engine import RunConfig, RunState, RunStatus, _format_duration, run_loop
10+
from ralphify.engine import RunConfig, RunState, RunStatus, format_duration, run_loop
1111

1212
_MOCK_SUBPROCESS = "ralphify.engine.subprocess.run"
1313

@@ -282,15 +282,15 @@ def stop_later():
282282

283283
class TestFormatDuration:
284284
def test_seconds(self):
285-
assert _format_duration(5.3) == "5.3s"
286-
assert _format_duration(0.1) == "0.1s"
287-
assert _format_duration(59.9) == "59.9s"
285+
assert format_duration(5.3) == "5.3s"
286+
assert format_duration(0.1) == "0.1s"
287+
assert format_duration(59.9) == "59.9s"
288288

289289
def test_minutes(self):
290-
assert _format_duration(60) == "1m 0s"
291-
assert _format_duration(90.5) == "1m 30s"
292-
assert _format_duration(3599) == "59m 59s"
290+
assert format_duration(60) == "1m 0s"
291+
assert format_duration(90.5) == "1m 30s"
292+
assert format_duration(3599) == "59m 59s"
293293

294294
def test_hours(self):
295-
assert _format_duration(3600) == "1h 0m"
296-
assert _format_duration(5400) == "1h 30m"
295+
assert format_duration(3600) == "1h 0m"
296+
assert format_duration(5400) == "1h 30m"

0 commit comments

Comments
 (0)