Skip to content

Commit

Permalink
πŸ”€ Replace timing class
Browse files Browse the repository at this point in the history
  • Loading branch information
spapanik committed May 14, 2024
1 parent 50e533a commit 111d1e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
18 changes: 3 additions & 15 deletions src/yamk/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from typing import Any, Literal, cast

from pyutilkit.term import SGRCodes, SGRString
from pyutilkit.timing import Timing

from yamk.functions import functions

Expand Down Expand Up @@ -347,22 +348,9 @@ def _clean_head(unmerged: list[list[Node]], head: Node) -> list[list[Node]]:
class CommandReport:
command: str
retries: int
timing_ns: int
timing: Timing
success: bool

def _formatted_timing(self) -> str:
if self.timing_ns < 1000:
return f"{self.timing_ns} ns"
timing: float = self.timing_ns
timing /= 1000
if timing < 1000:
return f"{timing:.1f} Β΅s"
timing /= 1000
if timing < 1000:
return f"{timing:.1f} ms"
timing /= 1000
return f"{timing:.2f} s"

def print(self, cols: int) -> None:
if not self.success:
indicator = "πŸ”΄"
Expand All @@ -373,7 +361,7 @@ def print(self, cols: int) -> None:
else:
indicator = "🟒"
sgr_code = SGRCodes.GREEN
timing = self._formatted_timing()
timing = str(self.timing)
padding = " " * (cols - len(self.command) - len(timing) - 7)
print(
indicator,
Expand Down
8 changes: 6 additions & 2 deletions src/yamk/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from dj_settings import ConfigParser
from pyutilkit.term import SGRCodes, SGRString
from pyutilkit.timing import Timing

from yamk import lib
from yamk.__version__ import __version__
Expand Down Expand Up @@ -94,7 +95,10 @@ def _run_command(self, command: str) -> int:
status = result.returncode
if status == 0:
report = lib.CommandReport(
command=command, timing_ns=total, retries=i, success=True
command=command,
timing=Timing(nanoseconds=total),
retries=i,
success=True,
)
self.reports.append(report)
return status
Expand All @@ -105,7 +109,7 @@ def _run_command(self, command: str) -> int:
sleep(a)

report = lib.CommandReport(
command=command, timing_ns=total, retries=i, success=False
command=command, timing=Timing(nanoseconds=total), retries=i, success=False
)
self.reports.append(report)
return status
Expand Down

0 comments on commit 111d1e2

Please sign in to comment.