MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / format_table

Function format_table

vmm/src/vmm-cli.py:1252–1275  ·  view source on GitHub ↗

Format rows and headers into a table string.

(rows, headers)

Source from the content-addressed store, hash-verified

1250
1251
1252def format_table(rows, headers):
1253 """Format rows and headers into a table string."""
1254 if not rows:
1255 return ""
1256
1257 # Calculate column widths
1258 widths = [len(h) for h in headers]
1259 for row in rows:
1260 for i, cell in enumerate(row):
1261 widths[i] = max(widths[i], len(str(cell)))
1262
1263 # Create format string
1264 row_format = "│ " + " │ ".join(f"{{:<{w}}}" for w in widths) + " │"
1265 separator = "├─" + "─┼─".join("─" * w for w in widths) + "─┤"
1266 top_border = "┌─" + "─┬─".join("─" * w for w in widths) + "─┐"
1267 bottom_border = "└─" + "─┴─".join("─" * w for w in widths) + "─┘"
1268
1269 # Build table
1270 table = [top_border, row_format.format(*headers), separator]
1271 for row in rows:
1272 table.append(row_format.format(*[str(cell) for cell in row]))
1273 table.append(bottom_border)
1274
1275 return "\n".join(table)
1276
1277
1278def parse_env_file(file_path: str) -> Dict[str, str]:

Callers 3

list_vmsMethod · 0.85
list_imagesMethod · 0.85
list_gpusMethod · 0.85

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected