flexablelib 2.2.3__tar.gz → 2.2.4__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.2.3 → flexablelib-2.2.4}/CHANGELOG.md +42 -0
- {flexablelib-2.2.3/flexablelib.egg-info → flexablelib-2.2.4}/PKG-INFO +1 -1
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/merges.py +62 -3
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/readers.py +9 -1
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/table.py +188 -43
- {flexablelib-2.2.3 → flexablelib-2.2.4/flexablelib.egg-info}/PKG-INFO +1 -1
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib.egg-info/SOURCES.txt +3 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/package.json +1 -1
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_merges.py +3 -1
- flexablelib-2.2.4/tests/test_stress_matrix.py +47 -0
- flexablelib-2.2.4/tests/test_v224_fixes.py +235 -0
- flexablelib-2.2.4/tools/stress_matrix.py +602 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/LICENSE +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/MANIFEST.in +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/README.md +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/__init__.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/_speedups.c +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/_width_tables.h +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/cells.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/colors.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/columns.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/fast.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/options.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/py.typed +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/style_compositions.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/table_strings.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/text_width.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/utils.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib/writers.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib.egg-info/dependency_links.txt +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib.egg-info/requires.txt +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/flexablelib.egg-info/top_level.txt +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/pytest.ini +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/setup.cfg +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/setup.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/style_examples.md +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/conftest.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/helpers.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_cells.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_columns.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_excel.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_features.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_issues.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_merge_edge_matrix.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_readme_examples.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_style_line_widths.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_styles.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_text_width.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_two_pass_measurement.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_upstream_issues.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v2021_fixes.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v210_rows_copy.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v2110_fixes.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v211_fixes.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v213_features.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v214_features.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v215_features.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v216_features.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v217_features.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v218_features.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v219_coverage.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v219_fixes.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v220_exports.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v221_fixes.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v222_fixes.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tests/test_v223_fixes.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tools/benchmark.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tools/generate_width_tables.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tools/readme_gallery.py +0 -0
- {flexablelib-2.2.3 → flexablelib-2.2.4}/tools/text_to_png.py +0 -0
|
@@ -2,6 +2,48 @@
|
|
|
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.2.4] - 2026-11-07
|
|
6
|
+
|
|
7
|
+
Found by a new stress matrix (``tools/stress_matrix.py``): every style and
|
|
8
|
+
theme on a 30x50 table of mixed data (CJK, emoji, multi-line, ``None``),
|
|
9
|
+
each feature alone, a pairwise covering set of all feature options, and
|
|
10
|
+
"everything at once" combos, checking line widths, border junctions,
|
|
11
|
+
visible rows, export order and determinism. A reduced version runs in the
|
|
12
|
+
test suite (``tests/test_stress_matrix.py``).
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
- Fitting a table to the terminal (``max_width``) or capping one column
|
|
16
|
+
(``column_max_width``) left-aligned every other int column and the index,
|
|
17
|
+
even ones that were not shortened. Only a column that really loses
|
|
18
|
+
characters is turned into text now.
|
|
19
|
+
- ``add_divider`` / ``divide_every`` in a style without inter-row rules drew
|
|
20
|
+
a run of ASCII ``-`` across the column lines (``│ a │`` / ``-------``). The
|
|
21
|
+
divider now uses the style's glyphs (``├───┼───┤``, ``╞═══╪═══╡``,
|
|
22
|
+
``+---+``, ``|---|`` for markdown/pipes/orgtbl, edge to edge for
|
|
23
|
+
``*_ebody`` styles), skipping hidden columns; styles with no column lines
|
|
24
|
+
keep the dashed line.
|
|
25
|
+
- Merges in ``tilg_columns``, ``dots``, ``psql``/``presto`` and other
|
|
26
|
+
non-box styles got light box glyphs (``│ ├ ┴``) for their caps. ASCII
|
|
27
|
+
column lines now join with ``+`` and ``dots`` with ``:`` (dividers in
|
|
28
|
+
``dots`` too).
|
|
29
|
+
- ``expand_to_window`` with ``column_max_width`` pulled a column that was
|
|
30
|
+
already wider than its cap (numbers are never cut) back to the cap, so its
|
|
31
|
+
cells overflowed the rules and the frame broke (also on ``paginate`` pages).
|
|
32
|
+
- ``stream()``:
|
|
33
|
+
- with ``show_index`` and ``column_min_width`` or ``column_max_width``
|
|
34
|
+
raised ``IndexError``; with ``show_index`` alone nothing was frozen and
|
|
35
|
+
the lines grew as rows arrived. The index width is now reserved for a
|
|
36
|
+
sized input (``len(rows)``), including roman numerals.
|
|
37
|
+
- with ``zebra`` or cell backgrounds lost every row and printed the bottom
|
|
38
|
+
border after the header and after each row.
|
|
39
|
+
- with ``show_headers=False`` on an empty table raised ``ValueError``
|
|
40
|
+
(``column_max_width must be >= 1``), and with ``panel`` / ``shadow`` on a
|
|
41
|
+
borderless style closed the panel after the first row.
|
|
42
|
+
- ``title`` and ``caption`` were not centred on a table with no rows.
|
|
43
|
+
- ``Table.from_csv`` accepts CSV text, so ``from_csv(table.to_csv())``
|
|
44
|
+
round-trips like ``from_markdown`` and ``from_html`` already did. Paths
|
|
45
|
+
and open handles work as before.
|
|
46
|
+
|
|
5
47
|
## [2.2.3] - 2026-11-06
|
|
6
48
|
|
|
7
49
|
### Fixed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.4
|
|
4
4
|
Summary: Fast, dependency-free terminal tables for Python: 56 border styles, ANSI colors, cell merges, decimal alignment, width fitting, and CSV/Markdown/HTML/Excel/LaTeX I/O.
|
|
5
5
|
Home-page: https://github.com/Opus-Perpetuus/flexablelib
|
|
6
6
|
Author: Benjamin Ramirez
|
|
@@ -349,9 +349,13 @@ def _pick_junction(v_glyph: str, h_glyph: str, n: bool, s: bool, e: bool, w: boo
|
|
|
349
349
|
if v_glyph in '|+' or (h_glyph and h_glyph in '-=~'):
|
|
350
350
|
return h_glyph if h_glyph in '-=~' else '-'
|
|
351
351
|
return h_glyph or '─'
|
|
352
|
-
if v_glyph in '|+'
|
|
353
|
-
|
|
354
|
-
|
|
352
|
+
if v_glyph in '|+':
|
|
353
|
+
# ASCII column lines join with '+' whatever the dash ('-', '=', '~').
|
|
354
|
+
return _ASCII.get(key, '+')
|
|
355
|
+
if v_glyph and not ('\u2500' <= v_glyph <= '\u257f'):
|
|
356
|
+
# Other non-box column glyphs (``dots`` draws ':') are their own
|
|
357
|
+
# junction; a light box tee next to them is a foreign glyph.
|
|
358
|
+
return v_glyph
|
|
355
359
|
if v_glyph == '║' and h_glyph == '═':
|
|
356
360
|
return _DOUBLE.get(key, '║')
|
|
357
361
|
if v_glyph == '║':
|
|
@@ -383,6 +387,14 @@ def _synthesize_body_rule(composition):
|
|
|
383
387
|
h = end.middle
|
|
384
388
|
elif header is not None and header.middle:
|
|
385
389
|
h = header.middle
|
|
390
|
+
if not ('\u2500' <= v.middle <= '\u257f') and v.middle not in '|+':
|
|
391
|
+
# Non-box column glyphs (``dots`` draws ':') are their own junction.
|
|
392
|
+
return SeparatorLine(
|
|
393
|
+
left=v.left or None,
|
|
394
|
+
middle=h if h and not ('\u2500' <= h <= '\u257f') else '-',
|
|
395
|
+
intersection=v.middle,
|
|
396
|
+
right=v.right or None,
|
|
397
|
+
)
|
|
386
398
|
if v.middle in '|+':
|
|
387
399
|
return SeparatorLine(
|
|
388
400
|
left='+' if v.left else None,
|
|
@@ -412,6 +424,53 @@ def _synthesize_body_rule(composition):
|
|
|
412
424
|
)
|
|
413
425
|
|
|
414
426
|
|
|
427
|
+
_FRAME_TEES = {
|
|
428
|
+
# vertical glyph -> (left tee, right tee) for a light horizontal
|
|
429
|
+
'│': ('├', '┤'), '┊': ('├', '┤'), '┆': ('├', '┤'), '╎': ('├', '┤'),
|
|
430
|
+
'┃': ('┠', '┨'), '║': ('╟', '╢'), '|': ('+', '+'),
|
|
431
|
+
}
|
|
432
|
+
_FRAME_TEES_DOUBLE_H = {
|
|
433
|
+
'│': ('╞', '╡'), '║': ('╠', '╣'), '|': ('+', '+'),
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
def _frame_only_body_rule(composition):
|
|
438
|
+
"""Body rule for styles with outer verticals but no column lines.
|
|
439
|
+
|
|
440
|
+
``*_ebody`` / ``*_empty`` styles frame the body without separating its
|
|
441
|
+
columns, so the rule runs edge to edge and only meets the frame.
|
|
442
|
+
Returns None when the body has no outer verticals either.
|
|
443
|
+
"""
|
|
444
|
+
from .style_compositions import SeparatorLine
|
|
445
|
+
v = composition.vertical_table_body_lines
|
|
446
|
+
if v is None:
|
|
447
|
+
return None
|
|
448
|
+
left_v = _glyph(v.left or '')
|
|
449
|
+
right_v = _glyph(v.right or '')
|
|
450
|
+
if not (left_v.strip() or right_v.strip()):
|
|
451
|
+
return None
|
|
452
|
+
end = composition.table_end_line
|
|
453
|
+
h = _glyph(end.middle) if end is not None and end.middle else ''
|
|
454
|
+
if not h or h.isspace():
|
|
455
|
+
h = '-' if '|' in (left_v, right_v) else '─'
|
|
456
|
+
tees = _FRAME_TEES_DOUBLE_H if h == '═' else _FRAME_TEES
|
|
457
|
+
if '|' in (left_v, right_v) and h not in '-=~':
|
|
458
|
+
h = '-'
|
|
459
|
+
|
|
460
|
+
def tee(glyph, side):
|
|
461
|
+
if not glyph or glyph.isspace():
|
|
462
|
+
return None
|
|
463
|
+
pair = tees.get(glyph) or _FRAME_TEES.get(glyph)
|
|
464
|
+
return pair[side] if pair else glyph
|
|
465
|
+
|
|
466
|
+
return SeparatorLine(
|
|
467
|
+
left=tee(left_v, 0),
|
|
468
|
+
middle=h,
|
|
469
|
+
intersection=h,
|
|
470
|
+
right=tee(right_v, 1),
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
|
|
415
474
|
def _build_rule_line(layout, composition, column_widths, hidden, rule=None):
|
|
416
475
|
"""Assemble one full horizontal rule matching the column layout."""
|
|
417
476
|
rule = rule or _synthesize_body_rule(composition)
|
|
@@ -177,7 +177,11 @@ def from_csv(table_class, source, parse_numbers: bool = True,
|
|
|
177
177
|
lineterminator=None, skipinitialspace=None, strict=None,
|
|
178
178
|
**options):
|
|
179
179
|
"""
|
|
180
|
-
Build from a CSV file path,
|
|
180
|
+
Build from a CSV file path, an open text handle, or CSV text.
|
|
181
|
+
|
|
182
|
+
A string holding a line break that is not an existing file is read as
|
|
183
|
+
CSV text, so ``Table.from_csv(table.to_csv())`` round-trips the way
|
|
184
|
+
``from_markdown`` and ``from_html`` already did with their writers.
|
|
181
185
|
|
|
182
186
|
With ``has_header`` false, columns are named automatically.
|
|
183
187
|
|
|
@@ -192,6 +196,10 @@ def from_csv(table_class, source, parse_numbers: bool = True,
|
|
|
192
196
|
doublequote=doublequote, lineterminator=lineterminator,
|
|
193
197
|
skipinitialspace=skipinitialspace, strict=strict,
|
|
194
198
|
)
|
|
199
|
+
if isinstance(source, str) and ('\n' in source or '\r' in source):
|
|
200
|
+
import os
|
|
201
|
+
if not os.path.isfile(source):
|
|
202
|
+
source = _io.StringIO(source, newline='')
|
|
195
203
|
if hasattr(source, 'read'):
|
|
196
204
|
reader = _csv.reader(source, **reader_kwargs)
|
|
197
205
|
rows = [row for row in reader]
|
|
@@ -4047,6 +4047,19 @@ class Table(object):
|
|
|
4047
4047
|
|
|
4048
4048
|
return header_to_trim, col_to_trim
|
|
4049
4049
|
|
|
4050
|
+
def __column_exceeds(self, column_i, columns, new_width) -> bool:
|
|
4051
|
+
"""True when the header or any cell of the column is wider than
|
|
4052
|
+
``new_width`` on some line, i.e. trimming would change it."""
|
|
4053
|
+
headers = self.__headers_with_i if self.show_index else self.__headers
|
|
4054
|
+
cells = [headers[column_i]] + list(columns[column_i])
|
|
4055
|
+
for cell in cells:
|
|
4056
|
+
if cell is None:
|
|
4057
|
+
continue
|
|
4058
|
+
for line in str(cell).split('\n'):
|
|
4059
|
+
if visible_width(line) > new_width:
|
|
4060
|
+
return True
|
|
4061
|
+
return False
|
|
4062
|
+
|
|
4050
4063
|
def __wrap_or_trim_data(self,
|
|
4051
4064
|
column_i: int,
|
|
4052
4065
|
new_width: int,
|
|
@@ -4077,6 +4090,18 @@ class Table(object):
|
|
|
4077
4090
|
new_width=new_width,
|
|
4078
4091
|
)
|
|
4079
4092
|
else:
|
|
4093
|
+
# Only a column that really loses characters turns into text.
|
|
4094
|
+
# Every column passes through here, including the ones a fit
|
|
4095
|
+
# or a column_max_width elsewhere left at full width, and
|
|
4096
|
+
# resetting those flipped right-aligned ints and the index to
|
|
4097
|
+
# the left.
|
|
4098
|
+
if not self.__column_exceeds(column_i, columns, new_width):
|
|
4099
|
+
return self.__trim_column(
|
|
4100
|
+
column_i=column_i,
|
|
4101
|
+
columns=columns,
|
|
4102
|
+
new_width=new_width,
|
|
4103
|
+
index=True
|
|
4104
|
+
)
|
|
4080
4105
|
if index:
|
|
4081
4106
|
self.__column_alignments_with_i[
|
|
4082
4107
|
column_title
|
|
@@ -4420,7 +4445,10 @@ class Table(object):
|
|
|
4420
4445
|
)
|
|
4421
4446
|
new_width = widths[column_i] + extra
|
|
4422
4447
|
if hi is not None:
|
|
4423
|
-
|
|
4448
|
+
# Growing must never shrink: a column already past its cap
|
|
4449
|
+
# holds content that could not be cut (numbers), and pulling
|
|
4450
|
+
# it back to the cap leaves the cells wider than the rules.
|
|
4451
|
+
new_width = max(widths[column_i], min(new_width, int(hi)))
|
|
4424
4452
|
widths[column_i] = new_width
|
|
4425
4453
|
store[headers[column_i]] = new_width
|
|
4426
4454
|
|
|
@@ -4982,6 +5010,39 @@ class Table(object):
|
|
|
4982
5010
|
header_row = data_rows.header_row
|
|
4983
5011
|
body_rows = data_rows.body_rows
|
|
4984
5012
|
gap_separator = None
|
|
5013
|
+
# Dividers in a style with no inter-row rule are drawn with that
|
|
5014
|
+
# style's own glyphs (the same rule merges synthesise), so they join
|
|
5015
|
+
# the column lines instead of crossing them as a run of ASCII dashes.
|
|
5016
|
+
divider_rule = None
|
|
5017
|
+
if self.__dividers and separators.table_body_line is None:
|
|
5018
|
+
from .merges import _frame_only_body_rule, _synthesize_body_rule
|
|
5019
|
+
composition = self.__style_composition
|
|
5020
|
+
under_header = composition.inferior_header_line
|
|
5021
|
+
if (under_header is not None and under_header.left == '|'
|
|
5022
|
+
and under_header.right == '|'):
|
|
5023
|
+
# Markdown-like styles (markdown, pipes, orgtbl): a rule in
|
|
5024
|
+
# the shape of their header rule, without alignment colons.
|
|
5025
|
+
synthesized = SeparatorLine(
|
|
5026
|
+
left='|', middle='-',
|
|
5027
|
+
intersection=under_header.intersection or '|',
|
|
5028
|
+
right='|',
|
|
5029
|
+
)
|
|
5030
|
+
else:
|
|
5031
|
+
synthesized = (
|
|
5032
|
+
_synthesize_body_rule(composition)
|
|
5033
|
+
or _frame_only_body_rule(composition)
|
|
5034
|
+
)
|
|
5035
|
+
if synthesized is not None:
|
|
5036
|
+
divider_rule = _get_separators(
|
|
5037
|
+
self.__style_composition._replace(
|
|
5038
|
+
table_body_line=synthesized
|
|
5039
|
+
),
|
|
5040
|
+
column_widths_list,
|
|
5041
|
+
self.__empty_column_indexes,
|
|
5042
|
+
self.__show_empty_columns,
|
|
5043
|
+
column_alignments_list,
|
|
5044
|
+
user_hidden,
|
|
5045
|
+
).table_body_line
|
|
4985
5046
|
if colors_on:
|
|
4986
5047
|
separators, gap_separator = self.__colour_horizontal_rules(
|
|
4987
5048
|
separators,
|
|
@@ -5021,10 +5082,21 @@ class Table(object):
|
|
|
5021
5082
|
# line through the middle of a table with no rows.
|
|
5022
5083
|
body, body_line_map = self.__join_body_rows(
|
|
5023
5084
|
body_rows, body_line, separators.table_body_line,
|
|
5024
|
-
gap_separator=gap_separator,
|
|
5085
|
+
gap_separator=gap_separator, divider_rule=divider_rule,
|
|
5086
|
+
)
|
|
5087
|
+
# Centre title and caption on the lines actually drawn: the computed
|
|
5088
|
+
# width came out short for a table with no rows yet (an empty stream
|
|
5089
|
+
# or query), which pushed both to the left.
|
|
5090
|
+
drawn_width = max(
|
|
5091
|
+
(visible_width(line)
|
|
5092
|
+
for part in (superior_row, body, end_line) if part
|
|
5093
|
+
for line in part.split('\n')),
|
|
5094
|
+
default=None,
|
|
5025
5095
|
)
|
|
5026
|
-
title_line = self.__title_line(column_widths_list, table_with_i
|
|
5027
|
-
|
|
5096
|
+
title_line = self.__title_line(column_widths_list, table_with_i,
|
|
5097
|
+
drawn_width)
|
|
5098
|
+
caption_line = self.__caption_line(column_widths_list, table_with_i,
|
|
5099
|
+
drawn_width)
|
|
5028
5100
|
|
|
5029
5101
|
# Where the body starts depends on which of the parts before it were
|
|
5030
5102
|
# drawn at all: a title, a top rule, a header. Counting them off the
|
|
@@ -5065,7 +5137,7 @@ class Table(object):
|
|
|
5065
5137
|
return self.__apply_table_align(table_string)
|
|
5066
5138
|
|
|
5067
5139
|
def __join_body_rows(self, body_rows, body_line, separator_line,
|
|
5068
|
-
gap_separator=None):
|
|
5140
|
+
gap_separator=None, divider_rule=None):
|
|
5069
5141
|
"""
|
|
5070
5142
|
Join body rows, inserting extra divider rules where requested.
|
|
5071
5143
|
|
|
@@ -5093,8 +5165,9 @@ class Table(object):
|
|
|
5093
5165
|
cursor = 0
|
|
5094
5166
|
|
|
5095
5167
|
# A style with no inter-row rule still gets the dividers ``add_divider``
|
|
5096
|
-
# asked for
|
|
5097
|
-
#
|
|
5168
|
+
# asked for: ``divider_rule`` in the style's glyphs when it has column
|
|
5169
|
+
# lines to join, otherwise a dashed line. A style that rules between
|
|
5170
|
+
# every row already shows them.
|
|
5098
5171
|
explicit_dividers = (
|
|
5099
5172
|
self.__dividers if (self.__dividers and separator_line is None)
|
|
5100
5173
|
else set()
|
|
@@ -5104,10 +5177,14 @@ class Table(object):
|
|
|
5104
5177
|
# Measure one physical line: a wrapped first row holds several,
|
|
5105
5178
|
# and measuring the whole string drew a rule as wide as all of
|
|
5106
5179
|
# them put together.
|
|
5107
|
-
|
|
5180
|
+
row_width = max(
|
|
5108
5181
|
max(visible_width(line) for line in body_rows[0].split('\n')),
|
|
5109
5182
|
1,
|
|
5110
5183
|
)
|
|
5184
|
+
if divider_rule and visible_width(divider_rule) == row_width:
|
|
5185
|
+
rule = divider_rule
|
|
5186
|
+
else:
|
|
5187
|
+
rule = '-' * row_width
|
|
5111
5188
|
|
|
5112
5189
|
separator_lines = body_line.count('\n') if separator_line is not None else 0
|
|
5113
5190
|
|
|
@@ -5130,11 +5207,11 @@ class Table(object):
|
|
|
5130
5207
|
|
|
5131
5208
|
return '\n'.join(pieces), line_map
|
|
5132
5209
|
|
|
5133
|
-
def __title_line(self, column_widths_list, table_with_i):
|
|
5210
|
+
def __title_line(self, column_widths_list, table_with_i, drawn_width=None):
|
|
5134
5211
|
"""Centre the title over the full table width, if any."""
|
|
5135
5212
|
if not self.__title:
|
|
5136
5213
|
return None
|
|
5137
|
-
table_width = self.__get_string_table_width()
|
|
5214
|
+
table_width = drawn_width or self.__get_string_table_width()
|
|
5138
5215
|
title = self.__title
|
|
5139
5216
|
title_width = visible_width(title)
|
|
5140
5217
|
if title_width >= table_width:
|
|
@@ -5269,11 +5346,11 @@ class Table(object):
|
|
|
5269
5346
|
return chr(10).join(out)
|
|
5270
5347
|
|
|
5271
5348
|
|
|
5272
|
-
def __caption_line(self, column_widths_list, table_with_i):
|
|
5349
|
+
def __caption_line(self, column_widths_list, table_with_i, drawn_width=None):
|
|
5273
5350
|
"""Centre the caption under the full table width, if any."""
|
|
5274
5351
|
if not self.__caption:
|
|
5275
5352
|
return None
|
|
5276
|
-
table_width = self.__get_string_table_width()
|
|
5353
|
+
table_width = drawn_width or self.__get_string_table_width()
|
|
5277
5354
|
caption = self.__caption
|
|
5278
5355
|
caption_width = visible_width(caption)
|
|
5279
5356
|
if caption_width >= table_width:
|
|
@@ -6012,7 +6089,9 @@ class Table(object):
|
|
|
6012
6089
|
``overflow`` (truncate/wrap).
|
|
6013
6090
|
|
|
6014
6091
|
Requires headers (or existing columns) so widths can be measured
|
|
6015
|
-
before the first streamed row.
|
|
6092
|
+
before the first streamed row. With ``show_index`` the index column
|
|
6093
|
+
is sized for every row when ``rows`` has a length (a list, say); a
|
|
6094
|
+
plain generator sizes it from the rows already in the table.
|
|
6016
6095
|
|
|
6017
6096
|
Lines look as ``compose()`` would draw them: formats, alignment,
|
|
6018
6097
|
colours, ``row_filter``, dividers and merges carry over. ``sort_by``
|
|
@@ -6043,7 +6122,17 @@ class Table(object):
|
|
|
6043
6122
|
# Measure natural widths, then pin min=max so later rows cannot
|
|
6044
6123
|
# widen the table (beautifultable stream contract).
|
|
6045
6124
|
work.compose()
|
|
6046
|
-
|
|
6125
|
+
# By header, not the positional list: with show_index the data-only
|
|
6126
|
+
# list is left empty (the index layout fills the *_with_i one), and
|
|
6127
|
+
# the floors below indexed it by data column -- IndexError.
|
|
6128
|
+
width_map = (
|
|
6129
|
+
work.__column_widths_with_i if work.show_index
|
|
6130
|
+
else work.__column_widths
|
|
6131
|
+
)
|
|
6132
|
+
# An empty table with show_headers off measures 0; a cap of 0 is
|
|
6133
|
+
# invalid (ValueError), and a column needs at least one cell.
|
|
6134
|
+
widths = [max(1, int(width_map.get(header, 0) or 0))
|
|
6135
|
+
for header in work.headers]
|
|
6047
6136
|
# Honour caller floors already set on self.
|
|
6048
6137
|
if self.__column_min_width is not None:
|
|
6049
6138
|
for i, header in enumerate(work.headers):
|
|
@@ -6059,13 +6148,44 @@ class Table(object):
|
|
|
6059
6148
|
)
|
|
6060
6149
|
if ceil is not None:
|
|
6061
6150
|
widths[i] = min(widths[i], int(ceil))
|
|
6062
|
-
|
|
6063
|
-
work.
|
|
6151
|
+
bounds = list(widths)
|
|
6152
|
+
if work.show_index:
|
|
6153
|
+
# The index column grows as rows arrive (9 -> 10 -> 100), so
|
|
6154
|
+
# reserve the widest label when the number of rows is known.
|
|
6155
|
+
# Unpinned it widened the lines after the first nine rows.
|
|
6156
|
+
index_width = max(1, int(width_map.get(work.__index_title, 0) or 0))
|
|
6157
|
+
try:
|
|
6158
|
+
total = work.__real_row_count + len(rows)
|
|
6159
|
+
except TypeError:
|
|
6160
|
+
total = None
|
|
6161
|
+
if total:
|
|
6162
|
+
labels = [work.index_start + work.index_step * k
|
|
6163
|
+
for k in (0, total - 1)]
|
|
6164
|
+
if work.roman_index:
|
|
6165
|
+
labels = [work.index_start + work.index_step * k
|
|
6166
|
+
for k in range(total)]
|
|
6167
|
+
labels = [to_roman(label) for label in labels]
|
|
6168
|
+
index_width = max(
|
|
6169
|
+
[index_width] + [visible_width(str(label))
|
|
6170
|
+
for label in labels]
|
|
6171
|
+
)
|
|
6172
|
+
bounds = dict(zip(work.headers, widths))
|
|
6173
|
+
bounds[work.__index_title] = index_width
|
|
6174
|
+
work.column_min_width = bounds
|
|
6175
|
+
work.column_max_width = bounds
|
|
6064
6176
|
|
|
6065
|
-
n_close = self.
|
|
6177
|
+
n_close, closing = self.__stream_closing_lines(bounds)
|
|
6066
6178
|
before = work.compose().splitlines()
|
|
6067
|
-
|
|
6068
|
-
|
|
6179
|
+
# The open part of the empty table is yielded first, but only when
|
|
6180
|
+
# it ends in the same closing lines as a table with rows. A style or
|
|
6181
|
+
# setting that draws nothing for an empty body (no headers, no
|
|
6182
|
+
# frame) renders '' -- and its closing lines must not be assumed.
|
|
6183
|
+
tail = [strip_ansi(line) for line in before[len(before) - n_close:]]
|
|
6184
|
+
if n_close and (len(before) < n_close or tail != closing):
|
|
6185
|
+
yielded = 0
|
|
6186
|
+
else:
|
|
6187
|
+
yielded = len(before) - n_close
|
|
6188
|
+
for line in before[:yielded]:
|
|
6069
6189
|
yield line
|
|
6070
6190
|
|
|
6071
6191
|
streamed = []
|
|
@@ -6074,41 +6194,66 @@ class Table(object):
|
|
|
6074
6194
|
streamed.append(row)
|
|
6075
6195
|
work.add_row(row)
|
|
6076
6196
|
after = work.compose().splitlines()
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
for line in open_after[open_before_len:]:
|
|
6197
|
+
open_end = max(0, len(after) - n_close)
|
|
6198
|
+
for line in after[yielded:open_end]:
|
|
6080
6199
|
yield line
|
|
6200
|
+
yielded = max(yielded, open_end)
|
|
6081
6201
|
before = after
|
|
6082
6202
|
|
|
6083
|
-
for line in
|
|
6203
|
+
for line in before[yielded:]:
|
|
6084
6204
|
yield line
|
|
6085
6205
|
|
|
6086
6206
|
if append and streamed:
|
|
6087
6207
|
for row in streamed:
|
|
6088
6208
|
self.add_row(row)
|
|
6089
6209
|
|
|
6090
|
-
def
|
|
6091
|
-
"""
|
|
6092
|
-
|
|
6093
|
-
(bottom border
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
one
|
|
6097
|
-
|
|
6098
|
-
empty
|
|
6099
|
-
|
|
6100
|
-
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6106
|
-
|
|
6107
|
-
|
|
6210
|
+
def __stream_closing_lines(self, widths):
|
|
6211
|
+
"""
|
|
6212
|
+
``(n, lines)``: the trailing lines a one-row and a two-row table
|
|
6213
|
+
share (bottom border, caption, panel and shadow), compared without
|
|
6214
|
+
colour. They are deferred until the stream ends.
|
|
6215
|
+
|
|
6216
|
+
Measured on tables that have rows: an empty one can render nothing
|
|
6217
|
+
at all, and zebra or cell backgrounds paint the rule under the last
|
|
6218
|
+
row, so comparing against the empty table (as this did) deferred
|
|
6219
|
+
either every line or none -- the bottom border then came out after
|
|
6220
|
+
the header and again after every row.
|
|
6221
|
+
"""
|
|
6222
|
+
def remap(table):
|
|
6223
|
+
# Dict bounds name the index column by its title object, which
|
|
6224
|
+
# is per table: translate it to this clone's own.
|
|
6225
|
+
if not isinstance(widths, dict):
|
|
6226
|
+
return list(widths)
|
|
6227
|
+
out = {}
|
|
6228
|
+
for key, value in widths.items():
|
|
6229
|
+
if isinstance(key, IndexColumnTitle):
|
|
6230
|
+
key = table.__index_title
|
|
6231
|
+
out[key] = value
|
|
6232
|
+
return out
|
|
6233
|
+
|
|
6234
|
+
renders = []
|
|
6235
|
+
for count in (1, 2):
|
|
6236
|
+
probe = self.__display_clone(include_rows=False)
|
|
6237
|
+
if not probe.headers:
|
|
6238
|
+
return 0, []
|
|
6239
|
+
probe.column_min_width = remap(probe)
|
|
6240
|
+
probe.column_max_width = remap(probe)
|
|
6241
|
+
# Callables written for the caller's data may not accept the
|
|
6242
|
+
# placeholder; they do not change the frame being measured.
|
|
6243
|
+
probe.row_filter = None
|
|
6244
|
+
probe.color_rule = None
|
|
6245
|
+
probe.custom_format = None
|
|
6246
|
+
for _ in range(count):
|
|
6247
|
+
probe.add_row(['x' for _ in probe.headers])
|
|
6248
|
+
renders.append(
|
|
6249
|
+
[strip_ansi(line) for line in probe.compose().splitlines()]
|
|
6250
|
+
)
|
|
6251
|
+
one, two = renders
|
|
6108
6252
|
n = 0
|
|
6109
|
-
while
|
|
6253
|
+
while (n < len(one) - 1 and n < len(two)
|
|
6254
|
+
and one[-(n + 1)] == two[-(n + 1)]):
|
|
6110
6255
|
n += 1
|
|
6111
|
-
return n
|
|
6256
|
+
return n, one[len(one) - n:]
|
|
6112
6257
|
|
|
6113
6258
|
# Display settings a derived table (stream, paginate) takes from its
|
|
6114
6259
|
# parent. Each is global or keyed by column, so it means the same thing
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.4
|
|
4
4
|
Summary: Fast, dependency-free terminal tables for Python: 56 border styles, ANSI colors, cell merges, decimal alignment, width fitting, and CSV/Markdown/HTML/Excel/LaTeX I/O.
|
|
5
5
|
Home-page: https://github.com/Opus-Perpetuus/flexablelib
|
|
6
6
|
Author: Benjamin Ramirez
|
|
@@ -39,6 +39,7 @@ tests/test_issues.py
|
|
|
39
39
|
tests/test_merge_edge_matrix.py
|
|
40
40
|
tests/test_merges.py
|
|
41
41
|
tests/test_readme_examples.py
|
|
42
|
+
tests/test_stress_matrix.py
|
|
42
43
|
tests/test_style_line_widths.py
|
|
43
44
|
tests/test_styles.py
|
|
44
45
|
tests/test_text_width.py
|
|
@@ -60,7 +61,9 @@ tests/test_v220_exports.py
|
|
|
60
61
|
tests/test_v221_fixes.py
|
|
61
62
|
tests/test_v222_fixes.py
|
|
62
63
|
tests/test_v223_fixes.py
|
|
64
|
+
tests/test_v224_fixes.py
|
|
63
65
|
tools/benchmark.py
|
|
64
66
|
tools/generate_width_tables.py
|
|
65
67
|
tools/readme_gallery.py
|
|
68
|
+
tools/stress_matrix.py
|
|
66
69
|
tools/text_to_png.py
|
|
@@ -416,8 +416,10 @@ def test_a_divider_above_a_merge_does_not_shift_it():
|
|
|
416
416
|
table.merge_cells(1, 0, last_row=2, value='Down')
|
|
417
417
|
|
|
418
418
|
lines = str(table).splitlines()
|
|
419
|
+
# Since 2.2.4 the divider is drawn in the style's glyphs (+---+---+);
|
|
420
|
+
# skip the top frame, which looks the same.
|
|
419
421
|
divider_index = next(i for i, line in enumerate(lines)
|
|
420
|
-
if set(line) == {'-'})
|
|
422
|
+
if i > 0 and set(line) == {'+', '-'})
|
|
421
423
|
|
|
422
424
|
assert 'Down' in lines[divider_index + 2]
|
|
423
425
|
assert 'Norte' in lines[divider_index - 1]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Reduced 30x50 style x feature matrix (full run: python tools/stress_matrix.py).
|
|
2
|
+
|
|
3
|
+
Every style renders the 30-column x 50-row mixed table (CJK, emoji,
|
|
4
|
+
multi-line, None, an empty row and column) once plain, then a pairwise
|
|
5
|
+
covering set of the feature options is spread across the styles, plus the
|
|
6
|
+
'everything at once' combos on a few styles. Each render is checked for:
|
|
7
|
+
no exception, equal line widths, connected box junctions (relative to the
|
|
8
|
+
style's own design), visible rows matching row_filter / sort_by,
|
|
9
|
+
to_records() order matching the render, and determinism.
|
|
10
|
+
"""
|
|
11
|
+
import os
|
|
12
|
+
import sys
|
|
13
|
+
|
|
14
|
+
import pytest
|
|
15
|
+
|
|
16
|
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'tools'))
|
|
17
|
+
import stress_matrix as matrix # noqa: E402
|
|
18
|
+
|
|
19
|
+
PAIRWISE = matrix.pairwise(matrix.factor_labels(), seed=3)
|
|
20
|
+
CASES = (
|
|
21
|
+
[(style, {}) for style in matrix.STYLES]
|
|
22
|
+
+ [('theme:' + theme, {}) for theme in matrix.THEMES]
|
|
23
|
+
+ [(matrix.STYLES[i * 7 % len(matrix.STYLES)],
|
|
24
|
+
{k: v for k, v in case.items() if v != 'off'})
|
|
25
|
+
for i, case in enumerate(PAIRWISE)]
|
|
26
|
+
+ [(style, dict(combo, mode=mode))
|
|
27
|
+
for style in ('rounded', 'grid', 'plain')
|
|
28
|
+
for combo in matrix.EVERYTHING
|
|
29
|
+
for mode in ('compose', 'paginate')]
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _id(case):
|
|
34
|
+
style, config = case
|
|
35
|
+
return style + ':' + ','.join('%s=%s' % kv for kv in sorted(config.items()))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@pytest.mark.parametrize('case', CASES, ids=[_id(c) for c in CASES])
|
|
39
|
+
def test_render_invariants(case):
|
|
40
|
+
style, config = case
|
|
41
|
+
assert matrix.run_case(style, config) == []
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@pytest.mark.parametrize('style', ['rounded', 'grid', 'markdown'])
|
|
45
|
+
@pytest.mark.parametrize('combo', range(len(matrix.EVERYTHING)))
|
|
46
|
+
def test_exports_round_trip(style, combo):
|
|
47
|
+
assert matrix.check_exports(style, matrix.EVERYTHING[combo]) == []
|