flexablelib 2.2.0__tar.gz → 2.2.2__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.
Files changed (66) hide show
  1. {flexablelib-2.2.0 → flexablelib-2.2.2}/CHANGELOG.md +43 -0
  2. {flexablelib-2.2.0/flexablelib.egg-info → flexablelib-2.2.2}/PKG-INFO +1 -1
  3. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/merges.py +68 -5
  4. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/table.py +72 -7
  5. {flexablelib-2.2.0 → flexablelib-2.2.2/flexablelib.egg-info}/PKG-INFO +1 -1
  6. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib.egg-info/SOURCES.txt +2 -0
  7. {flexablelib-2.2.0 → flexablelib-2.2.2}/package.json +1 -1
  8. flexablelib-2.2.2/tests/test_v221_fixes.py +125 -0
  9. flexablelib-2.2.2/tests/test_v222_fixes.py +72 -0
  10. {flexablelib-2.2.0 → flexablelib-2.2.2}/LICENSE +0 -0
  11. {flexablelib-2.2.0 → flexablelib-2.2.2}/MANIFEST.in +0 -0
  12. {flexablelib-2.2.0 → flexablelib-2.2.2}/README.md +0 -0
  13. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/__init__.py +0 -0
  14. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/_speedups.c +0 -0
  15. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/_width_tables.h +0 -0
  16. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/cells.py +0 -0
  17. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/colors.py +0 -0
  18. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/columns.py +0 -0
  19. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/fast.py +0 -0
  20. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/options.py +0 -0
  21. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/py.typed +0 -0
  22. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/readers.py +0 -0
  23. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/style_compositions.py +0 -0
  24. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/table_strings.py +0 -0
  25. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/text_width.py +0 -0
  26. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/utils.py +0 -0
  27. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib/writers.py +0 -0
  28. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib.egg-info/dependency_links.txt +0 -0
  29. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib.egg-info/requires.txt +0 -0
  30. {flexablelib-2.2.0 → flexablelib-2.2.2}/flexablelib.egg-info/top_level.txt +0 -0
  31. {flexablelib-2.2.0 → flexablelib-2.2.2}/pytest.ini +0 -0
  32. {flexablelib-2.2.0 → flexablelib-2.2.2}/setup.cfg +0 -0
  33. {flexablelib-2.2.0 → flexablelib-2.2.2}/setup.py +0 -0
  34. {flexablelib-2.2.0 → flexablelib-2.2.2}/style_examples.md +0 -0
  35. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/conftest.py +0 -0
  36. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/helpers.py +0 -0
  37. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_cells.py +0 -0
  38. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_columns.py +0 -0
  39. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_excel.py +0 -0
  40. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_features.py +0 -0
  41. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_issues.py +0 -0
  42. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_merge_edge_matrix.py +0 -0
  43. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_merges.py +0 -0
  44. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_readme_examples.py +0 -0
  45. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_style_line_widths.py +0 -0
  46. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_styles.py +0 -0
  47. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_text_width.py +0 -0
  48. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_two_pass_measurement.py +0 -0
  49. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_upstream_issues.py +0 -0
  50. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_v2021_fixes.py +0 -0
  51. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_v210_rows_copy.py +0 -0
  52. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_v2110_fixes.py +0 -0
  53. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_v211_fixes.py +0 -0
  54. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_v213_features.py +0 -0
  55. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_v214_features.py +0 -0
  56. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_v215_features.py +0 -0
  57. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_v216_features.py +0 -0
  58. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_v217_features.py +0 -0
  59. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_v218_features.py +0 -0
  60. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_v219_coverage.py +0 -0
  61. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_v219_fixes.py +0 -0
  62. {flexablelib-2.2.0 → flexablelib-2.2.2}/tests/test_v220_exports.py +0 -0
  63. {flexablelib-2.2.0 → flexablelib-2.2.2}/tools/benchmark.py +0 -0
  64. {flexablelib-2.2.0 → flexablelib-2.2.2}/tools/generate_width_tables.py +0 -0
  65. {flexablelib-2.2.0 → flexablelib-2.2.2}/tools/readme_gallery.py +0 -0
  66. {flexablelib-2.2.0 → flexablelib-2.2.2}/tools/text_to_png.py +0 -0
@@ -2,6 +2,49 @@
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.2] - 2026-11-05
6
+
7
+ ### Fixed
8
+ - ``zebra = True`` (and ``row_stripe = True``) raised ``ColourError: unknown
9
+ colour: 'true'`` when ``use_colors`` was on. ``True`` now enables a default
10
+ odd-row ``reverse`` stripe; ``False`` clears it. Other non-spec values raise
11
+ ``TypeError`` at assignment time instead of blowing up later in ``compose()``.
12
+ - ``parse_str_numbers = True`` before ``add_column`` / ``add_row`` left digit
13
+ strings unparsed, contrary to the documented "order does not matter". New
14
+ cells are parsed on the way in, matching ``set_cell`` and the re-parse that
15
+ already ran when the flag was turned on after the data was there.
16
+
17
+ ## [2.2.1] - 2026-11-04
18
+
19
+ ### Fixed
20
+ - A merge on the first or last drawn row -- often where ``sort_by`` or
21
+ ``row_filter`` puts it -- rewrote the whole border next to it: the top
22
+ border under a ``title`` (with ``show_headers=False``) came out as an inner
23
+ rule (``├───┴───┼───┤``), the bottom border above a ``caption`` lost its
24
+ corners, ``markdown``/``orgtbl`` header separators turned into ``+---+``,
25
+ and ``*_eheader`` header separators kept a junction over the merged span.
26
+ Only the junctions over the merge change now, and each keeps the arms the
27
+ lines around it really have.
28
+ - A merge covering a column in ``hide_columns`` (or a hidden empty column)
29
+ that is left with a single drawn column printed ``.``: the column was sized
30
+ without the merge text. It now shrinks to that column and the column fits
31
+ the text, as the exports already did.
32
+
33
+ ### CI
34
+ - Wheels: one path to PyPI. Only the ``vX.Y.Z`` tag push builds and
35
+ publishes; publishing the GitHub release no longer starts a second, duplicate
36
+ build that competed for the macOS runner. Publishing waits for all 28 wheels
37
+ (Linux manylinux + musllinux, Windows, macOS arm64; CPython 3.8-3.14) and
38
+ the sdist, checks the count and that the tag matches ``package.json``, and
39
+ is safe to re-run. One run per ref (``concurrency``).
40
+ - The real reason the macOS job never started: GitHub's hosted macOS arm64
41
+ runners are short of capacity, and a job no runner picks up is cancelled
42
+ after ~15 minutes. A new ``wheels-retry`` workflow re-runs the failed or
43
+ cancelled jobs of a tag run (up to three more attempts), so publishing
44
+ finishes on its own.
45
+ - Actions moved off Node 20: ``checkout@v5``, ``setup-python@v6``,
46
+ ``upload-artifact@v6``, ``download-artifact@v7``.
47
+
5
48
  ## [2.2.0] - 2026-11-04
6
49
 
7
50
  ### Changed (breaking)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib
3
- Version: 2.2.0
3
+ Version: 2.2.2
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
@@ -509,8 +509,44 @@ def _looks_like_rule(line: str, h_glyph: str = None) -> bool:
509
509
  )
510
510
 
511
511
 
512
+ # Glyphs that carry a vertical arm out of their bottom / top edge.
513
+ _VERTICALS = set('|¦:│┃║┊┋┆┇╎╏')
514
+ _NO_DOWN = set('┴└┘╰╯╨╩╧╙╜╚╝╘╛┸┷┻┖┚┗┛')
515
+ _NO_UP = set('┬┌┐╭╮╥╦╤╓╖╔╗╒╕┰┯┳┎┒┏┓')
516
+
517
+
518
+ # Light verticals meeting a heavy dash ('╍', '━'): keep the rule's weight.
519
+ _HEAVY_H = set('╍━┅┉')
520
+ _LIGHT_TO_HEAVY_H = {
521
+ '┼': '┿', '├': '┝', '┤': '┥', '┬': '┯', '┴': '┷',
522
+ '┌': '┍', '┐': '┑', '└': '┕', '┘': '┙',
523
+ }
524
+
525
+
526
+ def _has_arm(line, x, down):
527
+ """
528
+ True when the glyph at ``x`` in a neighbouring line reaches this rule.
529
+
530
+ ``down`` asks about the line above (does its glyph continue downwards);
531
+ otherwise about the line below. Text, spaces and dashes do not reach it,
532
+ which is what tells a top border under a title, or a bottom border over
533
+ a caption, that it has no arm on that side.
534
+ """
535
+ if line is None:
536
+ return False
537
+ g = _glyph(_char_at(line, x))
538
+ if not g or g.isspace() or g in _H_CHARS:
539
+ return False
540
+ if g in _VERTICALS or g == '+':
541
+ return True
542
+ if g in _JUNCTIONS:
543
+ return g not in (_NO_DOWN if down else _NO_UP)
544
+ return False
545
+
546
+
512
547
  def _repair_rule_junctions(line, layout, composition, h_glyph, missing_south=None, missing_north=None,
513
- no_south=False, no_north=False):
548
+ no_south=False, no_north=False, above=False, below=False,
549
+ only=None):
514
550
  """
515
551
  Rebuild every junction on a horizontal rule from the arms that remain.
516
552
 
@@ -519,6 +555,16 @@ def _repair_rule_junctions(line, layout, composition, h_glyph, missing_south=Non
519
555
 
520
556
  ``no_south`` / ``no_north`` force every junction to drop that arm — used for
521
557
  the table's outer end/start rules, which never continue past the border.
558
+
559
+ ``above`` / ``below``, when not False, are the lines next to this rule (None
560
+ past either end of the table). An arm is then kept only where that line
561
+ really reaches the rule, so a top border under a title, a bottom border
562
+ over a caption, or a header separator under a header drawn without
563
+ column rules keep their own shape. A junction drawn as a plain vertical
564
+ (markdown's ``|---|``) stays as it is unless it becomes a pure dash.
565
+
566
+ ``only``, when given, limits the rewrite to those x positions; every other
567
+ junction keeps the style's own glyph (corners such as ``O`` or ``╔``).
522
568
  """
523
569
  missing_south = missing_south or set()
524
570
  missing_north = missing_north or set()
@@ -531,6 +577,8 @@ def _repair_rule_junctions(line, layout, composition, h_glyph, missing_south=Non
531
577
  for x, v_glyph in _junction_positions(layout, composition):
532
578
  if visible_width(rewritten) <= x:
533
579
  continue
580
+ if only is not None and x not in only:
581
+ continue
534
582
  here = _char_at(rewritten, x)
535
583
  # Interior of a multi-column vertical blank: junction was wiped to space.
536
584
  if _glyph(here) in ('', ' '):
@@ -541,10 +589,23 @@ def _repair_rule_junctions(line, layout, composition, h_glyph, missing_south=Non
541
589
  east = _is_h(right)
542
590
  north = (not no_north) and (x not in missing_north)
543
591
  south = (not no_south) and (x not in missing_south)
592
+ if above is not False:
593
+ north = north and _has_arm(above, x, down=True)
594
+ if below is not False:
595
+ south = south and _has_arm(below, x, down=False)
544
596
  glyph = _pick_junction(
545
597
  v_glyph, h_glyph, north, south, east, west,
546
598
  round_corners=round_corners,
547
599
  )
600
+ if h_glyph in _HEAVY_H and glyph in _LIGHT_TO_HEAVY_H:
601
+ glyph = _LIGHT_TO_HEAVY_H[glyph]
602
+ if (above is not False and _glyph(here) in _VERTICALS
603
+ and (north or south)):
604
+ glyph = here
605
+ if only is not None and south and not north and _glyph(here) in _NO_UP:
606
+ glyph = here # already has no arm upwards, e.g. a header box top
607
+ if only is not None and north and not south and _glyph(here) in _NO_DOWN:
608
+ glyph = here # already closed below, e.g. ╚═══╩═══╝
548
609
  rewritten = _repaint(rewritten, x, x + 1, glyph)
549
610
  return rewritten
550
611
 
@@ -769,8 +830,10 @@ def apply(lines, row_line_map, regions, column_widths, composition,
769
830
  line, layout, composition, line_h,
770
831
  missing_south=missing_south_by_line.get(line_index),
771
832
  missing_north=missing_north_by_line.get(line_index),
772
- no_south=(line_index >= len(lines) - 1),
773
- no_north=(line_index == 0),
833
+ above=lines[line_index - 1] if line_index > 0 else None,
834
+ below=lines[line_index + 1] if line_index + 1 < len(lines) else None,
835
+ only=(missing_south_by_line.get(line_index, set())
836
+ | missing_north_by_line.get(line_index, set())),
774
837
  )
775
838
 
776
839
  # --- Pass 4: synthetic caps for column-only styles ----------------------
@@ -798,8 +861,8 @@ def apply(lines, row_line_map, regions, column_widths, composition,
798
861
  line, layout, composition, line_h,
799
862
  missing_south=plan['s'] or None,
800
863
  missing_north=plan['n'] or None,
801
- no_south=(existing >= len(lines) - 1),
802
- no_north=(existing == 0),
864
+ above=lines[existing - 1] if existing > 0 else None,
865
+ below=lines[existing + 1] if existing + 1 < len(lines) else None,
803
866
  )
804
867
  continue
805
868
 
@@ -1455,7 +1455,8 @@ class Table(object):
1455
1455
  """
1456
1456
  Alternating body-row colours (Rich ``row_styles`` / zebra striping).
1457
1457
 
1458
- Accepts ``None`` (off), a single colour spec applied to odd rows
1458
+ Accepts ``None`` / ``False`` (off), ``True`` (default striping:
1459
+ odd rows in ``reverse``), a single colour spec applied to odd rows
1459
1460
  (1, 3, …), or a two-item sequence ``(even_spec, odd_spec)``. Empty
1460
1461
  / falsy specs leave that parity uncoloured. Alias: :attr:`row_stripe`.
1461
1462
  """
@@ -1945,11 +1946,21 @@ class Table(object):
1945
1946
 
1946
1947
  @zebra.setter
1947
1948
  def zebra(self, value):
1949
+ if value is True:
1950
+ # Common "just turn it on" request; reverse works on every terminal.
1951
+ value = ('', 'reverse')
1952
+ elif value is False:
1953
+ value = None
1954
+ elif value is not None and not isinstance(value, (str, list, tuple)):
1955
+ raise TypeError(
1956
+ 'zebra must be None, False, True, a colour spec, or a '
1957
+ f'(even_spec, odd_spec) pair, got {type(value).__name__}'
1958
+ )
1948
1959
  self.__zebra = value
1949
1960
 
1950
1961
  @row_stripe.setter
1951
1962
  def row_stripe(self, value):
1952
- self.__zebra = value
1963
+ self.zebra = value
1953
1964
 
1954
1965
  @footer_rows.setter
1955
1966
  def footer_rows(self, value):
@@ -2621,6 +2632,19 @@ class Table(object):
2621
2632
  if isinstance(cell, str):
2622
2633
  row[index] = parse_value(cell, True)
2623
2634
 
2635
+ def __coerce_incoming_value(self, value):
2636
+ """Parse a newly added cell when ``parse_str_numbers`` is on."""
2637
+ if self.__parse_str_numbers and isinstance(value, str):
2638
+ from .readers import parse_value
2639
+ return parse_value(value, True)
2640
+ return value
2641
+
2642
+ def __coerce_incoming_sequence(self, data):
2643
+ """Copy ``data`` with ``__coerce_incoming_value`` applied to each cell."""
2644
+ if data is None or not self.__parse_str_numbers:
2645
+ return data
2646
+ return [self.__coerce_incoming_value(cell) for cell in data]
2647
+
2624
2648
  @property
2625
2649
  def missing(self):
2626
2650
  """
@@ -3142,6 +3166,7 @@ class Table(object):
3142
3166
  # top, which is right for a column that row had just created and
3143
3167
  # wrong for this one, and its values came out shifted down by one.
3144
3168
  is_new_column = checked_header not in self.__headers
3169
+ data = self.__coerce_incoming_sequence(data)
3145
3170
  if is_new_column:
3146
3171
  self.__add_header(checked_header)
3147
3172
  self.__add_column_data(
@@ -3358,6 +3383,7 @@ class Table(object):
3358
3383
  ... | size 5 | 39865 |
3359
3384
  ... +----------+------------+
3360
3385
  """
3386
+ data = self.__coerce_incoming_sequence(data)
3361
3387
  self.__columns_with_i[self.__index_title].append(self.__index_counter)
3362
3388
  added_to_column_count = self.__add_row_data(data)
3363
3389
  add_headers = True if added_to_column_count is not None else False
@@ -3406,9 +3432,7 @@ class Table(object):
3406
3432
  f'{column_count} columns'
3407
3433
  )
3408
3434
  column_i = column % column_count
3409
- if self.__parse_str_numbers and isinstance(value, str):
3410
- from .readers import parse_value
3411
- value = parse_value(value, True)
3435
+ value = self.__coerce_incoming_value(value)
3412
3436
  header = self.__headers[column_i]
3413
3437
  # Both orientations hold the same data and both are read while
3414
3438
  # rendering, so all four stores change together.
@@ -3617,7 +3641,7 @@ class Table(object):
3617
3641
  )
3618
3642
  self.__get_column_widths(semi=False)
3619
3643
  # Raise floors from column_min_width and re-assert max budgets.
3620
- self.__clamp_column_widths()
3644
+ self.__clamp_column_widths(merge_floors=True)
3621
3645
  table_width = self.__get_string_table_width()
3622
3646
  # Grow first when asked, then shrink if still over budget.
3623
3647
  if self.__expand_to_window:
@@ -4164,13 +4188,51 @@ class Table(object):
4164
4188
  return None
4165
4189
  return int(bounds)
4166
4190
 
4167
- def __clamp_column_widths(self):
4191
+ def __collapsed_merge_floors(self):
4192
+ """
4193
+ Width each drawn column needs for merges left with only that column.
4194
+
4195
+ A merge across several columns, with all but one of them in
4196
+ ``hide_columns`` (or hidden as empty), shrinks to the column still
4197
+ drawn -- the same thing the exports do. Its text then has that one
4198
+ column to itself, so the column has to fit it, as it would an
4199
+ ordinary cell; sized by its own content alone it printed ``.``.
4200
+ Merges still spanning two or more drawn columns are untouched: a merge
4201
+ never widens the table.
4202
+ """
4203
+ if not self.__merged_regions:
4204
+ return {}
4205
+ offset = 1 if self.__show_index else 0
4206
+ hidden = set(self.__effective_hidden_columns(self.__show_index))
4207
+ if not hidden:
4208
+ return {}
4209
+ floors = {}
4210
+ for region in self.__merged_regions:
4211
+ if region.value is None:
4212
+ continue
4213
+ columns = range(region.first_column + offset,
4214
+ region.last_column + offset + 1)
4215
+ drawn = [c for c in columns if c not in hidden]
4216
+ if len(drawn) != 1 or len(drawn) == len(columns):
4217
+ continue
4218
+ needed = max(
4219
+ visible_width(strip_ansi(part))
4220
+ for part in str(region.value).split('\n')
4221
+ )
4222
+ floors[drawn[0]] = max(floors.get(drawn[0], 0), needed)
4223
+ return floors
4224
+
4225
+ def __clamp_column_widths(self, merge_floors=False):
4168
4226
  """
4169
4227
  Enforce column_min_width / column_max_width on the measured widths.
4170
4228
 
4171
4229
  Only the width numbers are changed here. Content that still exceeds a
4172
4230
  max is reduced by :meth:`__enforce_column_max_widths`, which walks the
4173
4231
  same wrap/trim path as a terminal fit.
4232
+
4233
+ ``merge_floors`` also widens a column holding a merge that hiding left
4234
+ with that one column (:meth:`__collapsed_merge_floors`). Only the
4235
+ first clamp does it, so a terminal fit can still narrow it afterwards.
4174
4236
  """
4175
4237
  if self.__show_index:
4176
4238
  headers = list(self.__headers_with_i)
@@ -4184,6 +4246,7 @@ class Table(object):
4184
4246
  if not widths:
4185
4247
  return
4186
4248
 
4249
+ collapsed = self.__collapsed_merge_floors() if merge_floors else {}
4187
4250
  for column_i, header in enumerate(headers):
4188
4251
  # Index column (position 0 with show_index) is not user-facing.
4189
4252
  user_i = None if (self.__show_index and column_i == 0) else (
@@ -4203,6 +4266,8 @@ class Table(object):
4203
4266
  # clamping the number anyway drew a frame narrower than the text.
4204
4267
  content = widths[column_i]
4205
4268
  width = content
4269
+ if merge_floors and column_i in collapsed:
4270
+ width = max(width, collapsed[column_i])
4206
4271
  if lo is not None:
4207
4272
  width = max(width, int(lo))
4208
4273
  if hi is not None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib
3
- Version: 2.2.0
3
+ Version: 2.2.2
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
@@ -57,6 +57,8 @@ tests/test_v218_features.py
57
57
  tests/test_v219_coverage.py
58
58
  tests/test_v219_fixes.py
59
59
  tests/test_v220_exports.py
60
+ tests/test_v221_fixes.py
61
+ tests/test_v222_fixes.py
60
62
  tools/benchmark.py
61
63
  tools/generate_width_tables.py
62
64
  tools/readme_gallery.py
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flexablelib",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "private": true,
5
5
  "description": "Flexible console and HTML tables for Python: styles, merges, colors, widths, decimal alignment.",
6
6
  "repository": {
@@ -0,0 +1,125 @@
1
+ """2.2.1 regressions: merges on the first/last drawn row, and merges that
2
+ hiding leaves with a single column."""
3
+ import re
4
+
5
+ import pytest
6
+
7
+ from flexablelib import Table
8
+ from flexablelib.style_compositions import __style_compositions as catalogue
9
+ from flexablelib.text_width import visible_width
10
+
11
+ ROWS = [['a', 3, 'x'], ['b', 1, 'y'], ['c', 2, 'z'], ['d', 4, 'w']]
12
+
13
+
14
+ def make(rows=ROWS, **options):
15
+ table = Table(rows=[list(r) for r in rows], headers=['N', 'V', 'T'])
16
+ table.use_colors = False
17
+ for key, value in options.items():
18
+ setattr(table, key, value)
19
+ return table
20
+
21
+
22
+ # -- merge on the first visible row (after row_filter / sort_by) ------------
23
+
24
+ ORDERINGS = [
25
+ ('sort_by', lambda t: setattr(t, 'sort_by', 'V')),
26
+ ('sort_reverse', lambda t: (setattr(t, 'sort_by', 'V'),
27
+ setattr(t, 'sort_reverse', True))),
28
+ ('row_filter', lambda t: setattr(t, 'row_filter', lambda r: r[0] != 'a')),
29
+ ]
30
+
31
+
32
+ @pytest.mark.parametrize('name,order', ORDERINGS)
33
+ def test_top_border_under_title_survives_first_row_merge(name, order):
34
+ table = make(style_name='rounded', show_headers=False, title='T')
35
+ table.merge_cells(0, 0, last_column=1, value='M')
36
+ order(table)
37
+ lines = table.compose().split('\n')
38
+ assert lines[1] == '╭───────┬───╮', lines
39
+ assert lines[-1].startswith('╰')
40
+
41
+
42
+ @pytest.mark.parametrize('name,order', ORDERINGS)
43
+ def test_bottom_border_over_caption_survives_last_row_merge(name, order):
44
+ table = make(style_name='modern', caption='cap')
45
+ order(table)
46
+ last = 3 if name != 'row_filter' else 2
47
+ table.merge_cells(last, 0, last_column=1, value='M')
48
+ lines = table.compose().split('\n')
49
+ assert lines[-2] == '└───────┴───┘', lines
50
+
51
+
52
+ def test_eheader_separator_drops_junction_over_first_row_merge():
53
+ table = make(sort_by='V') # default grid_eheader
54
+ table.merge_cells(0, 0, last_column=1, value='M')
55
+ lines = table.compose().split('\n')
56
+ assert lines[2] == '+=======+===+'
57
+
58
+
59
+ def test_markdown_header_separator_kept_over_first_row_merge():
60
+ table = make(style_name='markdown', row_filter=lambda r: r[0] != 'a')
61
+ table.merge_cells(0, 0, last_column=1, value='M')
62
+ assert table.compose().split('\n')[1] == '|---|---|---|'
63
+
64
+
65
+ @pytest.mark.parametrize('style', catalogue._fields)
66
+ @pytest.mark.parametrize('options', [
67
+ {'show_headers': False, 'title': 'Title'},
68
+ {'caption': 'caption'},
69
+ {'sort_by': 'V', 'title': 'Title', 'caption': 'caption'},
70
+ ])
71
+ def test_outer_borders_unchanged_by_edge_merges(style, options):
72
+ """A merge on the first or last drawn row never rewrites the frame."""
73
+ def frame(lines):
74
+ head = 1 if options.get('title') else 0
75
+ tail = 1 if options.get('caption') else 0
76
+ return lines[head:len(lines) - tail]
77
+
78
+ plain = frame(make(style_name=style, **options).compose().split('\n'))
79
+ for first in (0, 3):
80
+ table = make(style_name=style, **options)
81
+ table.merge_cells(first, 0, last_column=1, value='M')
82
+ lines = frame(table.compose().split('\n'))
83
+ assert len({visible_width(line) for line in lines}) == 1, lines
84
+ # The top and bottom lines keep their outer corners.
85
+ for got, want in ((lines[0], plain[0]), (lines[-1], plain[-1])):
86
+ if re.search(r'\w', want):
87
+ continue # frameless style: this is a row, not a border
88
+ assert (got[:1], got[-1:]) == (want[:1], want[-1:]), (
89
+ style, options, first, '\n'.join(lines))
90
+
91
+
92
+ # -- merge covering a hidden column ----------------------------------------
93
+
94
+ @pytest.mark.parametrize('hidden', [['T'], ['V'], [2]])
95
+ def test_merge_over_hidden_column_shows_its_text(hidden):
96
+ table = make(hide_columns=hidden)
97
+ table.merge_cells(0, 1, last_column=2, value='Merged')
98
+ out = table.compose()
99
+ assert 'Merged' in out
100
+ assert '| . |' not in out
101
+ assert len({visible_width(line) for line in out.split('\n')}) == 1
102
+
103
+
104
+ def test_merge_over_hidden_column_matches_export():
105
+ table = make(hide_columns=['T'], style_name='ascii')
106
+ table.merge_cells(0, 1, last_column=2, value='Merged')
107
+ (region,) = table._export_view().merges
108
+ assert (region.first_column, region.last_column) == (1, 1)
109
+ row = table.compose().split('\n')[3]
110
+ assert re.fullmatch(r'\| a \| +Merged +\|', row), row
111
+
112
+
113
+ def test_merge_over_hidden_column_with_index_and_rows():
114
+ table = make(hide_columns=['V'], show_index=True, style_name='rounded')
115
+ table.merge_cells(1, 1, last_row=2, last_column=2, value='Total')
116
+ out = table.compose()
117
+ assert 'Total' in out
118
+ assert len({visible_width(line) for line in out.split('\n')}) == 1
119
+
120
+
121
+ def test_merge_still_spanning_two_columns_does_not_widen():
122
+ table = make(hide_columns=['N'])
123
+ table.merge_cells(0, 0, last_column=2, value='Much longer text')
124
+ widths = {visible_width(line) for line in table.compose().split('\n')}
125
+ assert widths == {9}
@@ -0,0 +1,72 @@
1
+ """2.2.2 regressions: zebra=True and parse_str_numbers on add_column/add_row."""
2
+ import re
3
+
4
+ import pytest
5
+
6
+ from flexablelib import Table
7
+
8
+
9
+ ANSI = re.compile(r'\x1b\[[0-9;]*m')
10
+
11
+
12
+ def bare(text: str) -> str:
13
+ return ANSI.sub('', text)
14
+
15
+
16
+ def test_zebra_true_turns_on_default_striping():
17
+ table = Table(rows=[[1], [2], [3]], headers=['n'])
18
+ table.use_colors = True
19
+ table.zebra = True
20
+ assert table.zebra == ('', 'reverse')
21
+ coloured = table.compose()
22
+ assert '\x1b[' in coloured
23
+ assert '1' in bare(coloured) and '2' in bare(coloured)
24
+
25
+
26
+ def test_zebra_false_clears_striping():
27
+ table = Table(rows=[[1], [2]], headers=['n'])
28
+ table.zebra = True
29
+ table.zebra = False
30
+ assert table.zebra is None
31
+
32
+
33
+ def test_row_stripe_true_matches_zebra():
34
+ table = Table(rows=[[1], [2]], headers=['n'])
35
+ table.row_stripe = True
36
+ assert table.zebra == ('', 'reverse')
37
+ assert table.row_stripe == ('', 'reverse')
38
+
39
+
40
+ def test_zebra_rejects_non_colour_objects():
41
+ table = Table()
42
+ with pytest.raises(TypeError, match='zebra must be'):
43
+ table.zebra = 3
44
+
45
+
46
+ def test_parse_str_numbers_before_add_column():
47
+ """Docs: order of the flag and the data must not matter."""
48
+ table = Table()
49
+ table.parse_str_numbers = True
50
+ table.add_column('n', ['10', '20', '3.5', 'x'])
51
+ assert table.rows == [[10], [20], [3.5], ['x']]
52
+ # Numeric column stays right-aligned once typed.
53
+ assert ' 10' in bare(table.compose()) or '| 10' in bare(table.compose())
54
+
55
+
56
+ def test_parse_str_numbers_before_add_row():
57
+ table = Table()
58
+ table.parse_str_numbers = True
59
+ table.add_column('a')
60
+ table.add_column('b')
61
+ # Replace empty placeholders by adding typed rows via a fresh table.
62
+ table = Table()
63
+ table.parse_str_numbers = True
64
+ table.add_row(['1', '2.5'])
65
+ table.add_row(['3', 'x'])
66
+ assert table.rows == [[1, 2.5], [3, 'x']]
67
+
68
+
69
+ def test_parse_str_numbers_off_keeps_digit_strings():
70
+ table = Table()
71
+ table.add_column('code', ['007', '1.50'])
72
+ assert table.rows == [['007'], ['1.50']]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes