Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/dstack/_internal/cli/commands/export.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
from typing import Any, Union

from rich.table import Table

Expand Down Expand Up @@ -148,7 +147,7 @@ def print_exports_table(exports: list[Export]):
)
importers = ", ".join([i.project_name for i in export.imports]) if export.imports else "-"

row: dict[Union[str, int], Any] = {
row = {
"NAME": export.name,
"FLEETS": fleets,
"IMPORTERS": importers,
Expand Down
3 changes: 1 addition & 2 deletions src/dstack/_internal/cli/commands/import_.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
from typing import Any, Union

from rich.table import Table

Expand Down Expand Up @@ -44,7 +43,7 @@ def print_imports_table(imports: list[Import]):
else "-"
)

row: dict[Union[str, int], Any] = {
row = {
"NAME": name,
"FLEETS": fleets,
}
Expand Down
6 changes: 3 additions & 3 deletions src/dstack/_internal/cli/commands/metrics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
import time
from typing import Any, Dict, List, Optional, Union
from typing import Any, List, Optional

from rich.live import Live
from rich.table import Table
Expand Down Expand Up @@ -79,7 +79,7 @@ def _get_metrics_table(run: Run, metrics: List[JobMetrics]) -> Table:
table.add_column("MEMORY")
table.add_column("GPU")

run_row: Dict[Union[str, int], Any] = {"NAME": run.name, "STATUS": run.status.value}
run_row = {"NAME": run.name, "STATUS": run.status.value}
if len(run._run.jobs) != 1:
add_row_from_dict(table, run_row)

Expand Down Expand Up @@ -117,7 +117,7 @@ def _get_metrics_table(run: Run, metrics: List[JobMetrics]) -> Table:
)
gpu_metrics += f" util={gpu_util_percent}%"

job_row: Dict[Union[str, int], Any] = {
job_row = {
"NAME": f" replica={job.job_spec.replica_num} job={job.job_spec.job_num}",
"STATUS": job.job_submissions[-1].status.value,
"CPU": cpu_usage or "-",
Expand Down
4 changes: 2 additions & 2 deletions src/dstack/_internal/cli/commands/project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
import sys
from typing import Any, Optional, Union
from typing import Optional

import questionary
from requests import HTTPError
Expand Down Expand Up @@ -191,7 +191,7 @@ def _list(self, args: argparse.Namespace):
for project_config in config_manager.list_project_configs():
project_name = project_config.name
is_default = project_name == default_project.name if default_project else False
row: dict[Union[str, int], Any] = {
row = {
"PROJECT": project_name,
"URL": project_config.url,
"DEFAULT": "✓" if is_default else "",
Expand Down
16 changes: 5 additions & 11 deletions src/dstack/_internal/cli/utils/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Dict, Optional, Union
from typing import Any, Optional

import requests
from rich.console import Console
Expand Down Expand Up @@ -110,17 +110,11 @@ def confirm_ask(prompt, **kwargs) -> bool:
raise SystemExit(1)


def add_row_from_dict(table: Table, data: Dict[Union[str, int], Any], **kwargs):
"""Maps dict keys to a table columns. `data` key is a column name or index. Missing keys are ignored."""
def add_row_from_dict(table: Table, data: dict[str, Any], **kwargs):
"""Maps dict keys to table columns. `data` key is the column name. Missing keys are ignored."""
row = []
for i, col in enumerate(table.columns):
# TODO(egor-s): clear header style
if col.header in data:
row.append(data[col.header])
elif i in data:
row.append(data[i])
else:
row.append("")
for col in table.columns:
row.append(data.get(str(col.header), ""))
table.add_row(*row, **kwargs)


Expand Down
6 changes: 3 additions & 3 deletions src/dstack/_internal/cli/utils/fleet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Union
from typing import Any, List, Optional

from rich.table import Table

Expand Down Expand Up @@ -75,7 +75,7 @@ def get_fleets_table(
if verbose and config.placement and config.placement.value == "cluster":
nodes = f"{nodes} (cluster)"

fleet_row: Dict[Union[str, int], Any] = {
fleet_row = {
"NAME": name,
"NODES": nodes,
"RESOURCES": resources,
Expand Down Expand Up @@ -116,7 +116,7 @@ def get_fleets_table(
)
instance_price = _format_price(instance.price)

instance_row: Dict[Union[str, int], Any] = {
instance_row = {
"NAME": f" instance={instance.instance_num}",
"NODES": "",
"RESOURCES": _format_instance_resources(instance),
Expand Down
6 changes: 3 additions & 3 deletions src/dstack/_internal/cli/utils/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import shutil
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional

from rich.markup import escape
from rich.table import Table
Expand Down Expand Up @@ -398,7 +398,7 @@ def get_runs_table(
group_name = group.name
group_name_to_index[group_name] = idx

run_row: Dict[Union[str, int], Any] = {
run_row = {
"NAME": _format_run_name(run, show_deployment_num),
"SUBMITTED": format_date(run.submitted_at),
"STATUS": _format_run_status(run),
Expand Down Expand Up @@ -431,7 +431,7 @@ def get_job_sort_key(job: Job) -> tuple:
if group_name_to_index:
group_index = group_name_to_index.get(job.job_spec.replica_group)

job_row: Dict[Union[str, int], Any] = {
job_row = {
"NAME": _format_job_name(
job,
latest_job_submission,
Expand Down
Loading