Files
simple-nanoshare/cli/nanoshare_client/table.py
T
daniel156161 73fdeacbfe
Build and Push Docker Container / build-and-push (push) Successful in 2m25s
feat!: adopt Python 3.14 and 3.15 language features
- Require Python 3.15 for the server and Python 3.14 for the CLI.
- Match the server requirement to quart_common's Python 3.15 features.
- Replace future annotations with native deferred evaluation.
- Defer CLI command dependencies and QR imports on Python 3.15.
- Enable argparse suggestions for mistyped CLI commands.
- Remove the obsolete tomllib import fallback.
- Update my_helpers and quart_common submodule references.
- Lock test dependencies and exclude them from Docker installations.
- Add regression coverage for lazy imports and deferred annotations.
- Document runtime requirements and standalone CLI validation.
- Validate 276 tests on Python 3.15 and 18 CLI tests on Python 3.14.

BREAKING CHANGE: The server now requires Python 3.15+ and the standalone CLI requires Python 3.14+.
2026-10-26 14:47:29 +01:00

25 lines
896 B
Python

from collections.abc import Iterable
def _display_width(value: str) -> int:
return len(value)
def _cell(value: object) -> str:
return '' if value is None else str(value)
def format_table(headers: list[str], rows: Iterable[Iterable[object]]) -> str:
string_rows = [[_cell(value) for value in row] for row in rows]
widths = [_display_width(header) for header in headers]
for row in string_rows:
for index, value in enumerate(row):
if index < len(widths):
widths[index] = max(widths[index], _display_width(value))
def render_row(values: list[str]) -> str:
padded = [value.ljust(widths[index]) for index, value in enumerate(values)]
return ' '.join(padded).rstrip()
separator = ' '.join('-' * width for width in widths).rstrip()
lines = [render_row(headers), separator]
lines.extend(render_row(row) for row in string_rows)
return '\n'.join(lines)