Skip to content

Commit 8552aa4

Browse files
committed
ruff n ruff
1 parent a49a935 commit 8552aa4

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

src/ai_migrate/progress.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import asyncio
2-
import io
32
import sys
43
import itertools
54
from enum import StrEnum
6-
from typing import Dict, Literal
5+
from typing import Dict
76
import shutil
87

98

@@ -22,7 +21,7 @@ def __init__(self, line_limit):
2221

2322
def write(self, s: str):
2423
self.lines.extend(s.removesuffix("\n").splitlines())
25-
self.lines = self.lines[-self.line_limit:]
24+
self.lines = self.lines[-self.line_limit :]
2625

2726
def flush(self):
2827
pass
@@ -60,15 +59,23 @@ def render(self) -> str:
6059

6160
name_part = f"{self.name}: "
6261
padding = terminal_width - len(name_part) - len(right_part)
63-
logs = [
64-
f" {line}"[:terminal_width] for line in self.logger.getvalue().splitlines()
65-
] if self.status == Status.RUNNING else []
66-
return f"\r{name_part}{' ' * max(0, padding)}{right_part}" + (f"\n{"\n".join(logs)}" if logs else "")
62+
logs = (
63+
[
64+
f" {line}"[:terminal_width]
65+
for line in self.logger.getvalue().splitlines()
66+
]
67+
if self.status == Status.RUNNING
68+
else []
69+
)
70+
return f"\r{name_part}{' ' * max(0, padding)}{right_part}" + (
71+
f"\n{'\n'.join(logs)}" if logs else ""
72+
)
6773

6874
def get_logger(self, header: str):
6975
self.logger.header = header
7076
return self.logger
7177

78+
7279
class StatusManager:
7380
def __init__(self):
7481
self.bars: Dict[str, StatusBar] = {}
@@ -101,7 +108,10 @@ async def render(self):
101108

102109
self._last_render_lines = 0
103110
bars = list(self.bars.values())
104-
bars = itertools.groupby(sorted(bars, key=lambda bar: (bar.status, bar.name)), key=lambda bar: bar.status)
111+
bars = itertools.groupby(
112+
sorted(bars, key=lambda bar: (bar.status, bar.name)),
113+
key=lambda bar: bar.status,
114+
)
105115
for status, bars in bars:
106116
bars = [*bars]
107117
if status == Status.WAITING:
@@ -113,7 +123,6 @@ async def render(self):
113123
print(rendered)
114124
self._last_render_lines += len(rendered.splitlines())
115125

116-
117126
async def mark_with_status(self, name: str, status: Status):
118127
async with self.lock:
119128
if name in self.bars:
@@ -137,4 +146,3 @@ async def stop(self):
137146

138147
def get_logger(self, name: str, header: str = ""):
139148
return self.bars[name].get_logger(header=header)
140-

src/ai_migrate/projects.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def flush(self):
8787
for f in self.files:
8888
f.flush()
8989

90+
9091
async def run(
9192
project_dir: str,
9293
logs_dir: str | Path,
@@ -145,7 +146,10 @@ async def process_one_fileset(index, files: FileGroup, task_name: str):
145146
log_file.parent.mkdir(parents=True, exist_ok=True)
146147
log_buffer = open(log_file, "w")
147148

148-
logger = Tee(status_manager.get_logger(task_name, header=f"==> {log_file} <=="), log_buffer)
149+
logger = Tee(
150+
status_manager.get_logger(task_name, header=f"==> {log_file} <=="),
151+
log_buffer,
152+
)
149153

150154
try:
151155
await run_migration(

0 commit comments

Comments
 (0)