Skip to content

Commit

Permalink
Adopt the black/ruff preview styles for more concise formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Apr 13, 2024
1 parent eaeca0d commit f029fbb
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 78 deletions.
10 changes: 4 additions & 6 deletions aiomonitor/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ def __init__(
self._persistent = persistent

def get_trace_id(self) -> str:
h = hash(
(
id(self),
self.get_name(),
)
)
h = hash((
id(self),
self.get_name(),
))
b = struct.pack("P", h)
return base64.b32encode(b).rstrip(b"=").decode()

Expand Down
78 changes: 32 additions & 46 deletions aiomonitor/termui/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,19 @@ def _get_current_stderr() -> TextIO:

def print_ok(msg: str) -> None:
print_formatted_text(
FormattedText(
[
("ansibrightgreen", "✓ "),
("", msg),
]
)
FormattedText([
("ansibrightgreen", "✓ "),
("", msg),
])
)


def print_fail(msg: str) -> None:
print_formatted_text(
FormattedText(
[
("ansibrightred", "✗ "),
("", msg),
]
)
FormattedText([
("ansibrightred", "✗ "),
("", msg),
])
)


Expand Down Expand Up @@ -117,11 +113,9 @@ async def interact(self: Monitor, connection: TelnetConnection) -> None:
try:
user_input = (
await prompt_session.prompt_async(
FormattedText(
[
(style_prompt, self.prompt),
]
)
FormattedText([
(style_prompt, self.prompt),
])
)
).strip()
except KeyboardInterrupt:
Expand Down Expand Up @@ -422,16 +416,14 @@ def do_ps(
table_data: List[Tuple[str, str, str, str, str, str]] = [headers]
tasks = self.format_running_task_list(filter_, persistent)
for task in tasks:
table_data.append(
(
task.task_id,
task.state,
task.name,
task.coro,
task.created_location,
task.since,
)
)
table_data.append((
task.task_id,
task.state,
task.name,
task.coro,
task.created_location,
task.since,
))
table = AsciiTable(table_data)
table.inner_row_border = False
table.inner_column_border = False
Expand Down Expand Up @@ -469,15 +461,13 @@ def do_ps_terminated(
table_data: List[Tuple[str, str, str, str, str]] = [headers]
tasks = self.format_terminated_task_list(filter_, persistent)
for task in tasks:
table_data.append(
(
task.task_id,
task.name,
task.coro,
task.started_since,
task.terminated_since,
)
)
table_data.append((
task.task_id,
task.name,
task.coro,
task.started_since,
task.terminated_since,
))
table = AsciiTable(table_data)
table.inner_row_border = False
table.inner_column_border = False
Expand Down Expand Up @@ -509,11 +499,9 @@ def do_where(ctx: click.Context, taskid: str) -> None:
if item_type == "header":
stdout.write("\n")
print_formatted_text(
FormattedText(
[
("ansiwhite", item_text),
]
)
FormattedText([
("ansiwhite", item_text),
])
)
else:
stdout.write(textwrap.indent(item_text.strip("\n"), " "))
Expand All @@ -537,11 +525,9 @@ def do_where_terminated(ctx: click.Context, trace_id: str) -> None:
if item_type == "header":
stdout.write("\n")
print_formatted_text(
FormattedText(
[
("ansiwhite", item_text),
]
)
FormattedText([
("ansiwhite", item_text),
])
)
else:
stdout.write(textwrap.indent(item_text.strip("\n"), " "))
Expand Down
32 changes: 13 additions & 19 deletions aiomonitor/webui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ class TaskTypeParams(APIParams):

@classmethod
def get_checker(cls):
return t.Dict(
{
t.Key("task_type", default=TaskTypes.RUNNING): t.Enum(
TaskTypes.RUNNING,
TaskTypes.TERMINATED,
),
}
)
return t.Dict({
t.Key("task_type", default=TaskTypes.RUNNING): t.Enum(
TaskTypes.RUNNING,
TaskTypes.TERMINATED,
),
})


@dataclasses.dataclass
Expand All @@ -55,11 +53,9 @@ class TaskIdParams(APIParams):

@classmethod
def get_checker(cls) -> t.Trafaret:
return t.Dict(
{
t.Key("task_id"): t.String,
}
)
return t.Dict({
t.Key("task_id"): t.String,
})


@dataclasses.dataclass
Expand All @@ -69,12 +65,10 @@ class ListFilterParams(APIParams):

@classmethod
def get_checker(cls) -> t.Trafaret:
return t.Dict(
{
t.Key("filter", default=""): t.String(allow_blank=True),
t.Key("persistent", default=False): t.ToBool,
}
)
return t.Dict({
t.Key("filter", default=""): t.String(allow_blank=True),
t.Key("persistent", default=False): t.ToBool,
})


@dataclasses.dataclass
Expand Down
12 changes: 5 additions & 7 deletions examples/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ def do_hello(ctx: click.Context) -> None:
from prompt_toolkit.formatted_text import FormattedText

print_formatted_text(
FormattedText(
[
("ansibrightblue", "Hello, "),
("ansibrightyellow", "world, "),
("ansibrightmagenta", "with color!"),
]
)
FormattedText([
("ansibrightblue", "Hello, "),
("ansibrightyellow", "world, "),
("ansibrightmagenta", "with color!"),
])
)

# or:
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ ignore = ["E203", "E731", "E501", "Q000"]
known-first-party = ["aiomonitor"]
split-on-trailing-comma = true

[tool.ruff.format]
preview = true

[tool.mypy]
ignore_missing_imports = true

Expand Down

0 comments on commit f029fbb

Please sign in to comment.