flexablelib 2.0.12__tar.gz → 2.0.14__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flexablelib-2.0.12 → flexablelib-2.0.14}/CHANGELOG.md +36 -0
- {flexablelib-2.0.12/flexablelib.egg-info → flexablelib-2.0.14}/PKG-INFO +1 -1
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/cells.py +58 -58
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/colors.py +6 -1
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/readers.py +81 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/table.py +594 -8
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/writers.py +131 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14/flexablelib.egg-info}/PKG-INFO +1 -1
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib.egg-info/SOURCES.txt +2 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/package.json +1 -1
- flexablelib-2.0.14/tests/test_v213_features.py +97 -0
- flexablelib-2.0.14/tests/test_v214_features.py +105 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/LICENSE +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/MANIFEST.in +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/README.md +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/__init__.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/_speedups.c +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/_width_tables.h +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/columns.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/fast.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/merges.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/options.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/style_compositions.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/table_strings.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/text_width.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib/utils.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib.egg-info/dependency_links.txt +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib.egg-info/requires.txt +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/flexablelib.egg-info/top_level.txt +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/setup.cfg +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/setup.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/tests/test_cells.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/tests/test_columns.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/tests/test_excel.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/tests/test_features.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/tests/test_issues.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/tests/test_merge_edge_matrix.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/tests/test_merges.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/tests/test_readme_examples.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/tests/test_styles.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/tests/test_text_width.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/tests/test_two_pass_measurement.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/tests/test_upstream_issues.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/tools/benchmark.py +0 -0
- {flexablelib-2.0.12 → flexablelib-2.0.14}/tools/generate_width_tables.py +0 -0
|
@@ -2,6 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [2.0.14] - 2026-10-28
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- ``Table.valign`` / ``col_valign`` / ``cell_valign``: vertical cell alignment
|
|
9
|
+
``t`` / ``m`` / ``b`` inside multi-line rows (texttable-style).
|
|
10
|
+
- ``Table.panel`` + ``Table.shadow``: outer frame (rounded/sharp/ascii/double/heavy)
|
|
11
|
+
and optional drop-shadow (tabled Panel / Spectre style).
|
|
12
|
+
- Export writers: ``to_rst()``, ``to_asciidoc()``, ``to_latex()``.
|
|
13
|
+
- ``Table.transpose()`` / ``rotate()``: swap rows and columns for display.
|
|
14
|
+
- ``Table.paginate(page_length=...)``: list of composed page strings with
|
|
15
|
+
headers repeated (PrettyTable / go-pretty).
|
|
16
|
+
- Nested subtables: a cell whose value is a ``Table`` is composed into a
|
|
17
|
+
multiline cell (minimal useful nesting).
|
|
18
|
+
|
|
19
|
+
### Notes
|
|
20
|
+
- Column percent-width constraints (F10) remain covered by existing
|
|
21
|
+
``column_min_width`` / ``column_max_width``; no API change.
|
|
22
|
+
- Streaming / incremental print (F13) deferred.
|
|
23
|
+
|
|
24
|
+
## [2.0.13] - 2026-10-28
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
- Research inventory of 89 terminal/pretty-print table libraries across languages
|
|
28
|
+
(see delivery demos / research notes); feature backlog mined into this release.
|
|
29
|
+
- ``Table.zebra`` / ``row_stripe``: alternating body-row colours
|
|
30
|
+
(``None``, odd-only spec, or ``(even, odd)``).
|
|
31
|
+
- ``Table.caption``: centred text below the table (``title`` stays above).
|
|
32
|
+
- ``Table.footer_rows`` + ``Table.footer_color``: style a trailing totals band.
|
|
33
|
+
- ``Table.cell_colors``: per-cell ``{(row, col): spec}`` highlights.
|
|
34
|
+
- ``Table.cell_padding``: override style cell margin; ``show_margin=False`` now
|
|
35
|
+
forces margin 0 (was stored but unused).
|
|
36
|
+
- ``Table.overflow``: ``'wrap'`` / ``'truncate'`` / ``'ellipsis'`` (keeps
|
|
37
|
+
``auto_wrap`` in sync).
|
|
38
|
+
- ``Table.from_markdown``: import GFM pipe tables (alignment row → col_alignment).
|
|
39
|
+
- Colour specs may be background-only: ``on #rrggbb`` / ``on white``.
|
|
40
|
+
|
|
5
41
|
## [2.0.12] - 2026-10-28
|
|
6
42
|
|
|
7
43
|
### Removed
|
|
@@ -408,81 +408,81 @@ def __zip_sub_rows(row: Union[list, tuple]) -> tuple:
|
|
|
408
408
|
only_sub_row = row[0]
|
|
409
409
|
return only_sub_row
|
|
410
410
|
|
|
411
|
-
|
|
412
|
-
|
|
411
|
+
|
|
412
|
+
def _normalize_valign(code) -> str:
|
|
413
|
+
"""Map caller codes to ``t`` / ``m`` / ``b`` (default top)."""
|
|
414
|
+
if code is None:
|
|
415
|
+
return 't'
|
|
416
|
+
key = str(code).strip().lower()
|
|
417
|
+
if key in ('t', 'top'):
|
|
418
|
+
return 't'
|
|
419
|
+
if key in ('m', 'middle', 'c', 'center', 'centre'):
|
|
420
|
+
return 'm'
|
|
421
|
+
if key in ('b', 'bottom'):
|
|
422
|
+
return 'b'
|
|
423
|
+
raise ValueError(
|
|
424
|
+
"valign must be one of 't'/'m'/'b' (or top/middle/bottom), got {!r}"
|
|
425
|
+
.format(code)
|
|
426
|
+
)
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
def _wrap_rows(headers: Union[list, tuple],
|
|
430
|
+
data: Union[List[Union[list, tuple]], Tuple[Union[list, tuple]]],
|
|
431
|
+
header_valigns=None,
|
|
432
|
+
row_valigns=None,
|
|
413
433
|
) -> Tuple[list, list]:
|
|
414
434
|
"""
|
|
415
435
|
Wraps the rows and headers of the table if
|
|
416
|
-
any new line characters are present
|
|
417
|
-
|
|
418
|
-
_wrap_rows(headers=['a', 'b\\nc'], data=[['a', 'b\\nc'], ['c', 'd']])
|
|
419
|
-
|
|
420
|
-
Results in:
|
|
436
|
+
any new line characters are present.
|
|
421
437
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
438
|
+
``header_valigns`` / ``row_valigns`` optionally shift short cells inside
|
|
439
|
+
the tallest cell of that row (``t`` / ``m`` / ``b``). ``row_valigns`` is
|
|
440
|
+
a sequence parallel to ``data``; each entry is a sequence of codes, one
|
|
441
|
+
per cell (or ``None`` for top).
|
|
426
442
|
"""
|
|
427
|
-
# If no headers are provided, return None.
|
|
428
443
|
wrapped_headers = None
|
|
429
|
-
|
|
444
|
+
|
|
430
445
|
there_are_headers = headers is not None and is_some_instance(headers, list, tuple)
|
|
431
446
|
if there_are_headers:
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
447
|
+
wrapped_headers = __wrap_single_row(headers, header_valigns)
|
|
448
|
+
|
|
449
|
+
if row_valigns is None:
|
|
450
|
+
wrapped_data = [__wrap_single_row(row) for row in data]
|
|
451
|
+
else:
|
|
452
|
+
wrapped_data = []
|
|
453
|
+
for row_i, row in enumerate(data):
|
|
454
|
+
valigns = row_valigns[row_i] if row_i < len(row_valigns) else None
|
|
455
|
+
wrapped_data.append(__wrap_single_row(row, valigns))
|
|
438
456
|
|
|
439
457
|
return wrapped_headers, wrapped_data
|
|
440
458
|
|
|
441
459
|
|
|
442
|
-
def __wrap_single_row(row: Union[list, tuple]) -> list:
|
|
460
|
+
def __wrap_single_row(row: Union[list, tuple], valigns=None) -> list:
|
|
443
461
|
"""
|
|
444
|
-
|
|
445
|
-
The splitted cell generates a new sub-row, and every other
|
|
446
|
-
cell that doesn't have a new line character will be adjusted::
|
|
462
|
+
Split cells on newlines and pad short cells vertically.
|
|
447
463
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
Results in:
|
|
451
|
-
|
|
452
|
-
>>> [['a', 'b'], ['', 'c']]
|
|
453
|
-
>>> ^
|
|
454
|
-
>>> # Blank space to adjust the cell.
|
|
464
|
+
Default valign is top (blank lines under the content). Pass ``valigns``
|
|
465
|
+
as a parallel list of ``t`` / ``m`` / ``b`` to middle- or bottom-align.
|
|
455
466
|
"""
|
|
456
|
-
# Split in lines if any new line characters are present.
|
|
457
467
|
splitted_cells = list(map(__wrap_cell, row))
|
|
458
|
-
|
|
459
|
-
# Get the quantity of sub-rows calculating the max length of
|
|
460
|
-
# all of the splitted (or not) cells.
|
|
461
468
|
quantity_of_sub_rows = max([len(x) for x in splitted_cells])
|
|
462
|
-
|
|
463
|
-
# Create blank sub-rows each one having the same quantity of
|
|
464
|
-
# cells as the original row.
|
|
465
|
-
sub_rows = [['' for x in range(len(row))]
|
|
469
|
+
sub_rows = [['' for x in range(len(row))]
|
|
466
470
|
for _ in range(quantity_of_sub_rows)]
|
|
467
|
-
|
|
468
|
-
# Fill the sub-rows with the splitted cells.
|
|
469
|
-
#
|
|
470
|
-
# [['a'], ['b', 'c']] <-- splitted_cells
|
|
471
|
-
# ^ ^ ^
|
|
472
|
-
# sbr0 sbr0 sbr1
|
|
473
|
-
# <cell0> <--cell1-->
|
|
474
|
-
#
|
|
475
|
-
# [['a', 'b'], ['', 'c']] <-- sub_rows (being filled)
|
|
476
|
-
# ^ ^ ^ ^
|
|
477
|
-
# [0][0] [0][1] ^ [1][1] <-- sub_rows[sub_row][cell]
|
|
478
|
-
# [0][0] [1][0] ^ [1][1] <-- splitted_cells[cell][sub-row]
|
|
479
|
-
# ^
|
|
480
|
-
# There's no second sub-row in the first cell,
|
|
481
|
-
# so it's just left empty
|
|
482
|
-
#
|
|
471
|
+
|
|
483
472
|
for cell in range(len(splitted_cells)):
|
|
484
|
-
|
|
485
|
-
|
|
473
|
+
parts = splitted_cells[cell]
|
|
474
|
+
height = len(parts)
|
|
475
|
+
code = 't'
|
|
476
|
+
if valigns is not None and cell < len(valigns) and valigns[cell] is not None:
|
|
477
|
+
code = _normalize_valign(valigns[cell])
|
|
478
|
+
if code == 'b':
|
|
479
|
+
start = quantity_of_sub_rows - height
|
|
480
|
+
elif code == 'm':
|
|
481
|
+
start = (quantity_of_sub_rows - height) // 2
|
|
482
|
+
else:
|
|
483
|
+
start = 0
|
|
484
|
+
for sub_row in range(height):
|
|
485
|
+
sub_rows[start + sub_row][cell] = parts[sub_row]
|
|
486
486
|
|
|
487
487
|
return sub_rows
|
|
488
488
|
|
|
@@ -492,8 +492,8 @@ def __wrap_cell(cell: Any) -> Union[List[str], Any]:
|
|
|
492
492
|
Split in lines a cell if it has a new line character::
|
|
493
493
|
|
|
494
494
|
'a' -> ['a']
|
|
495
|
-
'a
|
|
496
|
-
'a
|
|
495
|
+
'a\nb' -> ['a', 'b']
|
|
496
|
+
'a\tb' -> ['a b']
|
|
497
497
|
'' -> ['']
|
|
498
498
|
123 -> [123]
|
|
499
499
|
None -> [None]
|
|
@@ -116,7 +116,12 @@ def parse_spec(spec: Union[str, int, None]) -> str:
|
|
|
116
116
|
|
|
117
117
|
parameters = []
|
|
118
118
|
# 'on' separates foreground from background: 'bold red on white'.
|
|
119
|
-
|
|
119
|
+
# A bare 'on <bg>' (Rich-style background-only) is also accepted.
|
|
120
|
+
lowered = spec.lower().strip()
|
|
121
|
+
if lowered.startswith('on '):
|
|
122
|
+
foreground_part, background_part = '', lowered[3:]
|
|
123
|
+
else:
|
|
124
|
+
foreground_part, _, background_part = lowered.partition(' on ')
|
|
120
125
|
|
|
121
126
|
for token in foreground_part.split():
|
|
122
127
|
if token in ATTRIBUTES:
|
|
@@ -399,3 +399,84 @@ def from_excel(table_class, path, sheet=None, has_header: bool = True,
|
|
|
399
399
|
# Overlaps or single cells from odd sheets: skip rather than fail.
|
|
400
400
|
continue
|
|
401
401
|
return table
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
def from_markdown(table_class, source, parse_numbers: bool = True, **options):
|
|
405
|
+
"""
|
|
406
|
+
Parse a GitHub-flavoured Markdown pipe table into a Table.
|
|
407
|
+
|
|
408
|
+
Accepts a string, a path, or a readable. The separator row
|
|
409
|
+
(``| --- | :---: | ---: |``) sets ``col_alignment`` when present and is
|
|
410
|
+
not stored as data. Round-trips with ``Table.to_markdown()``.
|
|
411
|
+
"""
|
|
412
|
+
import os
|
|
413
|
+
if hasattr(source, 'read'):
|
|
414
|
+
text = source.read()
|
|
415
|
+
if isinstance(text, bytes):
|
|
416
|
+
text = text.decode('utf-8')
|
|
417
|
+
elif isinstance(source, (str, bytes, os.PathLike)) and not (
|
|
418
|
+
isinstance(source, str) and '\n' in source
|
|
419
|
+
) and os.path.isfile(str(source)):
|
|
420
|
+
with open(source, encoding='utf-8') as fh:
|
|
421
|
+
text = fh.read()
|
|
422
|
+
else:
|
|
423
|
+
text = source.decode('utf-8') if isinstance(source, bytes) else str(source)
|
|
424
|
+
|
|
425
|
+
lines = [ln.strip() for ln in text.splitlines() if ln.strip()]
|
|
426
|
+
rows_raw = []
|
|
427
|
+
for ln in lines:
|
|
428
|
+
if '|' not in ln:
|
|
429
|
+
continue
|
|
430
|
+
body = ln[1:] if ln.startswith('|') else ln
|
|
431
|
+
if body.endswith('|'):
|
|
432
|
+
body = body[:-1]
|
|
433
|
+
rows_raw.append([c.strip() for c in body.split('|')])
|
|
434
|
+
|
|
435
|
+
if not rows_raw:
|
|
436
|
+
return _new_table(table_class, [], [], parse_numbers, **options)
|
|
437
|
+
|
|
438
|
+
def _is_sep_row(cells):
|
|
439
|
+
if not cells:
|
|
440
|
+
return False
|
|
441
|
+
for token in cells:
|
|
442
|
+
token = token.strip()
|
|
443
|
+
if not token or '-' not in token:
|
|
444
|
+
return False
|
|
445
|
+
if token.replace(':', '').replace('-', '').strip():
|
|
446
|
+
return False
|
|
447
|
+
return True
|
|
448
|
+
|
|
449
|
+
headers = rows_raw[0]
|
|
450
|
+
align_from_sep = None
|
|
451
|
+
data_start = 1
|
|
452
|
+
if len(rows_raw) > 1 and _is_sep_row(rows_raw[1]):
|
|
453
|
+
align_from_sep = []
|
|
454
|
+
for cell in rows_raw[1]:
|
|
455
|
+
token = cell.strip()
|
|
456
|
+
left = token.startswith(':')
|
|
457
|
+
right = token.endswith(':')
|
|
458
|
+
if left and right:
|
|
459
|
+
align_from_sep.append('c')
|
|
460
|
+
elif right:
|
|
461
|
+
align_from_sep.append('r')
|
|
462
|
+
else:
|
|
463
|
+
align_from_sep.append('l')
|
|
464
|
+
data_start = 2
|
|
465
|
+
|
|
466
|
+
width = len(headers)
|
|
467
|
+
normalized = []
|
|
468
|
+
for row in rows_raw[data_start:]:
|
|
469
|
+
row = list(row)
|
|
470
|
+
if len(row) < width:
|
|
471
|
+
row = row + [''] * (width - len(row))
|
|
472
|
+
elif len(row) > width:
|
|
473
|
+
row = row[:width]
|
|
474
|
+
normalized.append(row)
|
|
475
|
+
|
|
476
|
+
table = _new_table(table_class, headers, normalized, parse_numbers, **options)
|
|
477
|
+
if align_from_sep is not None:
|
|
478
|
+
try:
|
|
479
|
+
table.col_alignment = align_from_sep
|
|
480
|
+
except Exception:
|
|
481
|
+
pass
|
|
482
|
+
return table
|