flexablelib 2.0.14__tar.gz → 2.0.15__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 (46) hide show
  1. {flexablelib-2.0.14 → flexablelib-2.0.15}/CHANGELOG.md +18 -1
  2. {flexablelib-2.0.14/flexablelib.egg-info → flexablelib-2.0.15}/PKG-INFO +1 -1
  3. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/columns.py +12 -6
  4. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/table.py +322 -29
  5. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/table_strings.py +14 -7
  6. {flexablelib-2.0.14 → flexablelib-2.0.15/flexablelib.egg-info}/PKG-INFO +1 -1
  7. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib.egg-info/SOURCES.txt +1 -0
  8. {flexablelib-2.0.14 → flexablelib-2.0.15}/package.json +1 -1
  9. flexablelib-2.0.15/tests/test_v215_features.py +101 -0
  10. {flexablelib-2.0.14 → flexablelib-2.0.15}/LICENSE +0 -0
  11. {flexablelib-2.0.14 → flexablelib-2.0.15}/MANIFEST.in +0 -0
  12. {flexablelib-2.0.14 → flexablelib-2.0.15}/README.md +0 -0
  13. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/__init__.py +0 -0
  14. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/_speedups.c +0 -0
  15. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/_width_tables.h +0 -0
  16. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/cells.py +0 -0
  17. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/colors.py +0 -0
  18. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/fast.py +0 -0
  19. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/merges.py +0 -0
  20. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/options.py +0 -0
  21. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/readers.py +0 -0
  22. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/style_compositions.py +0 -0
  23. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/text_width.py +0 -0
  24. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/utils.py +0 -0
  25. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib/writers.py +0 -0
  26. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib.egg-info/dependency_links.txt +0 -0
  27. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib.egg-info/requires.txt +0 -0
  28. {flexablelib-2.0.14 → flexablelib-2.0.15}/flexablelib.egg-info/top_level.txt +0 -0
  29. {flexablelib-2.0.14 → flexablelib-2.0.15}/setup.cfg +0 -0
  30. {flexablelib-2.0.14 → flexablelib-2.0.15}/setup.py +0 -0
  31. {flexablelib-2.0.14 → flexablelib-2.0.15}/tests/test_cells.py +0 -0
  32. {flexablelib-2.0.14 → flexablelib-2.0.15}/tests/test_columns.py +0 -0
  33. {flexablelib-2.0.14 → flexablelib-2.0.15}/tests/test_excel.py +0 -0
  34. {flexablelib-2.0.14 → flexablelib-2.0.15}/tests/test_features.py +0 -0
  35. {flexablelib-2.0.14 → flexablelib-2.0.15}/tests/test_issues.py +0 -0
  36. {flexablelib-2.0.14 → flexablelib-2.0.15}/tests/test_merge_edge_matrix.py +0 -0
  37. {flexablelib-2.0.14 → flexablelib-2.0.15}/tests/test_merges.py +0 -0
  38. {flexablelib-2.0.14 → flexablelib-2.0.15}/tests/test_readme_examples.py +0 -0
  39. {flexablelib-2.0.14 → flexablelib-2.0.15}/tests/test_styles.py +0 -0
  40. {flexablelib-2.0.14 → flexablelib-2.0.15}/tests/test_text_width.py +0 -0
  41. {flexablelib-2.0.14 → flexablelib-2.0.15}/tests/test_two_pass_measurement.py +0 -0
  42. {flexablelib-2.0.14 → flexablelib-2.0.15}/tests/test_upstream_issues.py +0 -0
  43. {flexablelib-2.0.14 → flexablelib-2.0.15}/tests/test_v213_features.py +0 -0
  44. {flexablelib-2.0.14 → flexablelib-2.0.15}/tests/test_v214_features.py +0 -0
  45. {flexablelib-2.0.14 → flexablelib-2.0.15}/tools/benchmark.py +0 -0
  46. {flexablelib-2.0.14 → flexablelib-2.0.15}/tools/generate_width_tables.py +0 -0
@@ -2,6 +2,23 @@
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.15] - 2026-10-28
6
+
7
+ ### Added
8
+ - ``Table.stream(rows, append=False)``: beautifultable-style incremental
9
+ print — yields composed lines as rows arrive with widths frozen from
10
+ headers / seed rows / ``column_min_width`` (F13).
11
+ - ``Table.hide_columns``: omit columns by name or index at display time
12
+ (go-pretty / prettytable suppress); stored data unchanged.
13
+ - ``Table.apply_theme(name)`` + ``Table.THEMES``: named style+colour
14
+ bundles (``plain``, ``dark``, ``midnight``, ``matrix``, ``report``,
15
+ ``markdown``, ``ocean``).
16
+ - ``sort_by`` accepts a callable ``key(row)`` in addition to header/index.
17
+
18
+ ### Notes
19
+ - Streaming pins column widths; set ``column_min_width`` when later rows
20
+ are wider than the seed content.
21
+
5
22
  ## [2.0.14] - 2026-10-28
6
23
 
7
24
  ### Added
@@ -19,7 +36,7 @@ All notable changes to this project will be documented in this file. See [standa
19
36
  ### Notes
20
37
  - Column percent-width constraints (F10) remain covered by existing
21
38
  ``column_min_width`` / ``column_max_width``; no API change.
22
- - Streaming / incremental print (F13) deferred.
39
+ - Streaming / incremental print (F13) shipped in 2.0.15.
23
40
 
24
41
  ## [2.0.13] - 2026-10-28
25
42
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib
3
- Version: 2.0.14
3
+ Version: 2.0.15
4
4
  Summary: Flexible console and HTML tables for Python
5
5
  Home-page: https://github.com/Opus-Perpetuus/flexablelib
6
6
  Download-URL:
@@ -789,19 +789,22 @@ def _align_columns(style_composition: TableComposition,
789
789
  col_widths: List[int],
790
790
  empty_columns_i: List[int],
791
791
  show_empty: bool,
792
- float_cols_sizes: dict
792
+ float_cols_sizes: dict,
793
+ hidden_columns_i=()
793
794
  ) -> Generator[str, None, None]:
794
795
  """
795
796
  Aligns the columns and adds margin to the cells.
796
797
  """
797
798
  # The margin that the selected style has.
798
799
  margin = style_composition.margin
800
+ hidden = set(hidden_columns_i or ())
799
801
 
800
802
  for column_i, column in enumerate(columns):
801
803
 
802
804
  # Align only the columns that are shown.
803
- if (not show_empty and column_i not in empty_columns_i
804
- ) or show_empty:
805
+ if column_i not in hidden and (
806
+ show_empty or column_i not in empty_columns_i
807
+ ):
805
808
 
806
809
  # Get the header of the column.
807
810
  header = headers[column_i]
@@ -859,13 +862,15 @@ def _align_headers(style_composition: TableComposition,
859
862
  col_widths: List[int],
860
863
  empty_columns_i: List[int],
861
864
  show_empty: bool,
862
- float_cols_sizes: dict):
865
+ float_cols_sizes: dict,
866
+ hidden_columns_i=()):
863
867
  """
864
868
  Will align the headers using the provided column alignments.
865
869
  """
866
870
 
867
871
  # The margin that the selected style has.
868
872
  margin = style_composition.margin
873
+ hidden = set(hidden_columns_i or ())
869
874
 
870
875
  for column_i, column in enumerate(headers):
871
876
  # Get the alignment of the current column.
@@ -887,8 +892,9 @@ def _align_headers(style_composition: TableComposition,
887
892
  float_column_sizes = None
888
893
 
889
894
  # Only align the headers if its column is shown.
890
- if (not show_empty and column_i not in empty_columns_i
891
- ) or show_empty:
895
+ if column_i not in hidden and (
896
+ show_empty or column_i not in empty_columns_i
897
+ ):
892
898
  yield from __align_one_header(
893
899
  column,
894
900
  col_width,
@@ -828,6 +828,8 @@ class Table(object):
828
828
  self.__shadow = False
829
829
  # Row indexes after which a horizontal rule is forced.
830
830
  self.__dividers = set()
831
+ # Columns hidden by name or index (go-pretty / prettytable suppress).
832
+ self.__hide_columns = ()
831
833
  # Sort / filter applied to the display copy, not to stored data.
832
834
  self.__sort_by = None
833
835
  self.__sort_reverse = False
@@ -1506,7 +1508,8 @@ class Table(object):
1506
1508
  @property
1507
1509
  def sort_by(self):
1508
1510
  """
1509
- Column header or 0-based index used to order rows at render time.
1511
+ Column header, 0-based index, or callable ``key(row)`` used to order
1512
+ rows at render time.
1510
1513
  """
1511
1514
  return self.__sort_by
1512
1515
 
@@ -1984,6 +1987,25 @@ class Table(object):
1984
1987
  def show_empty_columns(self, value: bool):
1985
1988
  self.__show_empty_columns = value
1986
1989
 
1990
+ @property
1991
+ def hide_columns(self):
1992
+ """
1993
+ Column names or indexes to omit from display (go-pretty suppress).
1994
+
1995
+ Accepts ``None``, a single name/index, or an iterable of them.
1996
+ Stored data is unchanged; only compose/export chrome hides them.
1997
+ """
1998
+ return self.__hide_columns
1999
+
2000
+ @hide_columns.setter
2001
+ def hide_columns(self, value):
2002
+ if value is None:
2003
+ self.__hide_columns = ()
2004
+ return
2005
+ if isinstance(value, (str, bytes)) or not hasattr(value, '__iter__'):
2006
+ value = (value,)
2007
+ self.__hide_columns = tuple(value)
2008
+
1987
2009
  # end +-----------------------------+ SETTERS +-----------------------------+ end
1988
2010
  # +-----------------------------------------------------------------------------+
1989
2011
 
@@ -2038,6 +2060,45 @@ class Table(object):
2038
2060
  empty_rows.append(i)
2039
2061
  return empty_rows
2040
2062
 
2063
+ def __user_hidden_column_indexes(self, table_with_i=False):
2064
+ """
2065
+ Resolve ``hide_columns`` keys to drawn column indexes.
2066
+
2067
+ Names match headers; ints are 0-based user column indexes (index
2068
+ column excluded). When ``table_with_i`` the drawn index column is
2069
+ offset by one, matching ``__empty_column_indexes``.
2070
+ """
2071
+ keys = self.__hide_columns or ()
2072
+ if not keys:
2073
+ return ()
2074
+ headers = list(self.__headers)
2075
+ resolved = []
2076
+ for key in keys:
2077
+ if isinstance(key, int):
2078
+ user_i = key
2079
+ else:
2080
+ try:
2081
+ user_i = headers.index(key)
2082
+ except ValueError:
2083
+ raise ValueError(
2084
+ 'hide_columns key {0!r} is not in the table headers'
2085
+ .format(key)
2086
+ )
2087
+ if user_i < 0 or user_i >= len(headers):
2088
+ raise ValueError(
2089
+ 'hide_columns index {0!r} out of range'.format(key)
2090
+ )
2091
+ drawn = user_i + 1 if table_with_i else user_i
2092
+ resolved.append(drawn)
2093
+ return tuple(resolved)
2094
+
2095
+ def __effective_hidden_columns(self, table_with_i=False):
2096
+ """Empty-column hides plus user ``hide_columns``, as drawn indexes."""
2097
+ hidden = set(self.__user_hidden_column_indexes(table_with_i))
2098
+ if not self.__show_empty_columns:
2099
+ hidden.update(self.__empty_column_indexes)
2100
+ return tuple(sorted(hidden))
2101
+
2041
2102
  @property
2042
2103
  def __empty_column_indexes(self) -> list:
2043
2104
  """
@@ -3791,23 +3852,33 @@ class Table(object):
3791
3852
 
3792
3853
  if self.__sort_by is not None and indices:
3793
3854
  key = self.__sort_by
3794
- if isinstance(key, int):
3795
- column_i = key
3855
+ if callable(key) and not isinstance(key, (str, bytes)):
3856
+ def sort_key(row_i, _key=key):
3857
+ row = list(self.__rows[row_i])
3858
+ # Replace ValuePlacer with missing_value for the key fn.
3859
+ cleaned = [
3860
+ self.__missing_value if isinstance(c, ValuePlacer) else c
3861
+ for c in row
3862
+ ]
3863
+ return _key(cleaned)
3796
3864
  else:
3797
- try:
3798
- column_i = list(self.__headers).index(key)
3799
- except ValueError:
3800
- raise ValueError(
3801
- 'sort_by column {0!r} is not in the table headers'
3802
- .format(key)
3803
- )
3804
-
3805
- def sort_key(row_i):
3806
- cell = self.__rows[row_i][column_i]
3807
- if isinstance(cell, ValuePlacer):
3808
- # Missing sorts as empty string so it is stable and low.
3809
- return (1, '')
3810
- return (0, cell)
3865
+ if isinstance(key, int):
3866
+ column_i = key
3867
+ else:
3868
+ try:
3869
+ column_i = list(self.__headers).index(key)
3870
+ except ValueError:
3871
+ raise ValueError(
3872
+ 'sort_by column {0!r} is not in the table headers'
3873
+ .format(key)
3874
+ )
3875
+
3876
+ def sort_key(row_i, _column_i=column_i):
3877
+ cell = self.__rows[row_i][_column_i]
3878
+ if isinstance(cell, ValuePlacer):
3879
+ # Missing sorts as empty string so it is stable and low.
3880
+ return (1, '')
3881
+ return (0, cell)
3811
3882
 
3812
3883
  indices.sort(key=sort_key, reverse=self.__sort_reverse)
3813
3884
 
@@ -4191,6 +4262,7 @@ class Table(object):
4191
4262
  header_alignments_list = self.__header_alignments_list(
4192
4263
  column_alignments_list, column_titles
4193
4264
  )
4265
+ user_hidden = self.__user_hidden_column_indexes(table_with_i)
4194
4266
  # Header and body rows get aligned
4195
4267
  aligned_header = _align_headers(
4196
4268
  self.__style_composition,
@@ -4199,7 +4271,8 @@ class Table(object):
4199
4271
  column_widths_list,
4200
4272
  self.__empty_column_indexes,
4201
4273
  self.__show_empty_columns,
4202
- float_column_widths
4274
+ float_column_widths,
4275
+ user_hidden,
4203
4276
  )
4204
4277
  # Colour is applied after alignment, never before. By this point every
4205
4278
  # cell has been padded to its exact visible width, so wrapping it in
@@ -4219,7 +4292,8 @@ class Table(object):
4219
4292
  column_widths_list,
4220
4293
  self.__empty_column_indexes,
4221
4294
  self.__show_empty_columns,
4222
- float_column_widths
4295
+ float_column_widths,
4296
+ user_hidden,
4223
4297
  ))
4224
4298
  if colors_on:
4225
4299
  # Stash body length so footer_rows can resolve during paint.
@@ -4246,6 +4320,7 @@ class Table(object):
4246
4320
  self.__empty_column_indexes,
4247
4321
  self.__show_empty_columns,
4248
4322
  column_alignments_list,
4323
+ user_hidden,
4249
4324
  )
4250
4325
  empty_rows_for_render = (
4251
4326
  self.__compose_empty_row_indexes
@@ -4597,9 +4672,7 @@ class Table(object):
4597
4672
  # Columns the table is leaving out take up no room in a line, so the
4598
4673
  # merge offsets must not count them either -- the same list the
4599
4674
  # separators were built from.
4600
- hidden_columns = (
4601
- () if self.__show_empty_columns else self.__empty_column_indexes
4602
- )
4675
+ hidden_columns = self.__effective_hidden_columns(table_with_i)
4603
4676
 
4604
4677
  regions = self.__regions_with_colors()
4605
4678
  merged = apply_merges(
@@ -4638,10 +4711,7 @@ class Table(object):
4638
4711
 
4639
4712
  def __rule_specs_for_row(self, row_index, column_titles, column_widths):
4640
4713
  """One colour spec per *drawn* column for the rule under ``row_index``."""
4641
- hidden = (
4642
- () if self.__show_empty_columns else self.__empty_column_indexes
4643
- )
4644
- hidden = set(hidden)
4714
+ hidden = set(self.__effective_hidden_columns(self.__show_index))
4645
4715
  specs = []
4646
4716
  for col_i, _width in enumerate(column_widths):
4647
4717
  if col_i in hidden:
@@ -4866,9 +4936,7 @@ class Table(object):
4866
4936
  """
4867
4937
  from .merges import compute_layout, paint_rule_cell_backgrounds
4868
4938
 
4869
- hidden = (
4870
- () if self.__show_empty_columns else self.__empty_column_indexes
4871
- )
4939
+ hidden = self.__effective_hidden_columns(self.__show_index)
4872
4940
  layout = compute_layout(
4873
4941
  column_widths, self.__style_composition, hidden
4874
4942
  )
@@ -5079,6 +5147,230 @@ class Table(object):
5079
5147
  # +-----------------------------------------------------------------------------+
5080
5148
  # start +------------------------+ DATA WRITING +------------------------+ start
5081
5149
 
5150
+ # Named colour+style bundles (Spectre / Rich theme spirit).
5151
+ THEMES = {
5152
+ 'plain': {
5153
+ 'style_name': 'plain',
5154
+ 'use_colors': False,
5155
+ 'header_color': None,
5156
+ 'border_color': None,
5157
+ 'zebra': None,
5158
+ },
5159
+ 'dark': {
5160
+ 'style_name': 'rounded',
5161
+ 'use_colors': True,
5162
+ 'header_color': 'bold cyan',
5163
+ 'border_color': 'dim',
5164
+ 'zebra': 'on #2a2a2a',
5165
+ },
5166
+ 'midnight': {
5167
+ 'style_name': 'sharp',
5168
+ 'use_colors': True,
5169
+ 'header_color': 'bold white',
5170
+ 'border_color': 'blue',
5171
+ 'zebra': ('', 'on #1a1a2e'),
5172
+ },
5173
+ 'matrix': {
5174
+ 'style_name': 'ascii',
5175
+ 'use_colors': True,
5176
+ 'header_color': 'bold green',
5177
+ 'border_color': 'green',
5178
+ 'zebra': 'dim green',
5179
+ },
5180
+ 'report': {
5181
+ 'style_name': 'simple_bold',
5182
+ 'use_colors': True,
5183
+ 'header_color': 'bold',
5184
+ 'border_color': None,
5185
+ 'zebra': None,
5186
+ },
5187
+ 'markdown': {
5188
+ 'style_name': 'markdown',
5189
+ 'use_colors': False,
5190
+ 'header_color': None,
5191
+ 'border_color': None,
5192
+ 'zebra': None,
5193
+ },
5194
+ 'ocean': {
5195
+ 'style_name': 'rounded',
5196
+ 'use_colors': True,
5197
+ 'header_color': 'bold #7fdbff',
5198
+ 'border_color': '#0074d9',
5199
+ 'zebra': ('', 'on #001f3f'),
5200
+ },
5201
+ }
5202
+
5203
+ def apply_theme(self, name):
5204
+ """
5205
+ Apply a named theme: style plus header/border/zebra colours.
5206
+
5207
+ Themes: ``plain``, ``dark``, ``midnight``, ``matrix``, ``report``,
5208
+ ``markdown``, ``ocean``. Returns ``self`` for chaining.
5209
+ """
5210
+ if name not in self.THEMES:
5211
+ raise ValueError(
5212
+ 'unknown theme {0!r}; choose from {1}'.format(
5213
+ name, ', '.join(sorted(self.THEMES))
5214
+ )
5215
+ )
5216
+ for key, value in self.THEMES[name].items():
5217
+ setattr(self, key, value)
5218
+ return self
5219
+
5220
+ def stream(self, rows, append=False):
5221
+ """
5222
+ Yield table lines as rows arrive (beautifultable-style streaming).
5223
+
5224
+ Column widths are frozen from headers, existing rows, and any
5225
+ ``column_min_width`` / ``column_max_width`` before iteration starts
5226
+ (beautifultable contract: set floors ahead of time if later rows are
5227
+ wider than the seed). Cells that exceed those widths follow
5228
+ ``overflow`` (truncate/wrap).
5229
+
5230
+ Requires headers (or existing columns) so widths can be measured
5231
+ before the first streamed row.
5232
+
5233
+ Parameters
5234
+ ----------
5235
+ rows : iterable
5236
+ Yields one row (list/tuple) at a time.
5237
+ append : bool
5238
+ If True, streamed rows are added to this table when the
5239
+ generator is exhausted. If False (default), this table is
5240
+ left unchanged; streaming mutates only an internal copy.
5241
+
5242
+ Yields
5243
+ ------
5244
+ str
5245
+ Individual composed lines (borders, header, body, caption).
5246
+ """
5247
+ if not self.__headers and self.__real_column_count == 0:
5248
+ raise ValueError(
5249
+ 'stream() needs headers or existing columns so widths '
5250
+ 'can be frozen before rows arrive'
5251
+ )
5252
+
5253
+ work = self.__display_clone(include_rows=True)
5254
+ # Measure natural widths, then pin min=max so later rows cannot
5255
+ # widen the table (beautifultable stream contract).
5256
+ work.compose()
5257
+ widths = list(work.__column_widths_as_list)
5258
+ # Honour caller floors already set on self.
5259
+ if self.__column_min_width is not None:
5260
+ for i, header in enumerate(work.headers):
5261
+ floor = self.__lookup_width_map(
5262
+ self.__column_min_width, header, i
5263
+ )
5264
+ if floor is not None:
5265
+ widths[i] = max(widths[i], int(floor))
5266
+ if self.__column_max_width is not None:
5267
+ for i, header in enumerate(work.headers):
5268
+ ceil = self.__lookup_width_map(
5269
+ self.__column_max_width, header, i
5270
+ )
5271
+ if ceil is not None:
5272
+ widths[i] = min(widths[i], int(ceil))
5273
+ work.column_min_width = list(widths)
5274
+ work.column_max_width = list(widths)
5275
+
5276
+ n_close = self.__stream_closing_line_count(work, widths)
5277
+ before = work.compose().splitlines()
5278
+ open_part = before[:-n_close] if n_close else before
5279
+ for line in open_part:
5280
+ yield line
5281
+
5282
+ streamed = []
5283
+ for row in rows:
5284
+ row = list(row)
5285
+ streamed.append(row)
5286
+ work.add_row(row)
5287
+ after = work.compose().splitlines()
5288
+ open_after = after[:-n_close] if n_close else after
5289
+ open_before_len = len(before) - n_close if n_close else len(before)
5290
+ for line in open_after[open_before_len:]:
5291
+ yield line
5292
+ before = after
5293
+
5294
+ for line in (before[-n_close:] if n_close else []):
5295
+ yield line
5296
+
5297
+ if append and streamed:
5298
+ for row in streamed:
5299
+ self.add_row(row)
5300
+
5301
+ def __stream_closing_line_count(self, template, widths):
5302
+ """
5303
+ How many trailing lines are shared by empty-body and one-row tables
5304
+ (bottom border + caption). Those are deferred until stream ends.
5305
+ """
5306
+ empty = self.__display_clone(include_rows=False)
5307
+ one = self.__display_clone(include_rows=False)
5308
+ empty.column_min_width = list(widths)
5309
+ empty.column_max_width = list(widths)
5310
+ one.column_min_width = list(widths)
5311
+ one.column_max_width = list(widths)
5312
+ placeholders = ['' for _ in empty.headers] or ['']
5313
+ if empty.headers:
5314
+ one.add_row(placeholders)
5315
+ else:
5316
+ return 0
5317
+ la = empty.compose().splitlines()
5318
+ lb = one.compose().splitlines()
5319
+ n = 0
5320
+ while n < len(la) and n < len(lb) and la[-(n + 1)] == lb[-(n + 1)]:
5321
+ n += 1
5322
+ return n
5323
+
5324
+ def __display_clone(self, include_rows=True):
5325
+ """Shallow display copy used by stream/paginate helpers."""
5326
+ headers = list(self.headers)
5327
+ rows = []
5328
+ if include_rows:
5329
+ for row_i in range(self.__real_row_count):
5330
+ row = []
5331
+ for header in headers:
5332
+ col = self.__columns.get(header, [])
5333
+ if row_i < len(col):
5334
+ cell = col[row_i]
5335
+ if isinstance(cell, ValuePlacer):
5336
+ cell = self.__missing_value
5337
+ row.append(cell)
5338
+ else:
5339
+ row.append(self.__missing_value)
5340
+ rows.append(row)
5341
+ out = type(self).from_records(
5342
+ rows,
5343
+ headers=headers if headers else None,
5344
+ style_name=self.style_name,
5345
+ missing_val=self.__missing_value,
5346
+ )
5347
+ for attr in (
5348
+ 'title', 'caption', 'show_headers', 'show_index', 'header_color',
5349
+ 'border_color', 'use_colors', 'zebra', 'footer_rows', 'footer_color',
5350
+ 'cell_padding', 'overflow', 'auto_wrap', 'valign', 'col_valign',
5351
+ 'panel', 'shadow', 'col_alignment', 'header_align', 'max_width',
5352
+ 'table_align', 'hide_columns',
5353
+ ):
5354
+ try:
5355
+ setattr(out, attr, getattr(self, attr))
5356
+ except Exception:
5357
+ pass
5358
+ return out
5359
+
5360
+ def __lookup_width_map(self, spec, header, index):
5361
+ """Resolve column_min/max_width entry for one column."""
5362
+ if spec is None:
5363
+ return None
5364
+ if isinstance(spec, dict):
5365
+ if header in spec:
5366
+ return spec[header]
5367
+ return spec.get(index)
5368
+ if is_some_instance(spec, list, tuple):
5369
+ if index < len(spec):
5370
+ return spec[index]
5371
+ return None
5372
+ return spec
5373
+
5082
5374
  def transpose(self, **options):
5083
5375
  """
5084
5376
  Return a new table with rows and columns swapped (display rotate).
@@ -5150,6 +5442,7 @@ class Table(object):
5150
5442
  'cell_padding', 'overflow', 'auto_wrap', 'valign', 'col_valign',
5151
5443
  'panel', 'shadow', 'col_alignment', 'header_align', 'max_width',
5152
5444
  'column_min_width', 'column_max_width', 'table_align',
5445
+ 'hide_columns',
5153
5446
  ):
5154
5447
  try:
5155
5448
  setattr(page, attr, getattr(self, attr))
@@ -286,7 +286,8 @@ def __get_horizontal_line_group(line_style: SeparatorLine,
286
286
  will_have_indicators: bool,
287
287
  indicator_margin: str,
288
288
  full_margin_width: int,
289
- always_center_indicator: bool
289
+ always_center_indicator: bool,
290
+ hidden_columns_i=()
290
291
  ) -> Generator[str, None, None]:
291
292
  """
292
293
  This creates a group of horizontal lines for all the columns
@@ -322,10 +323,12 @@ def __get_horizontal_line_group(line_style: SeparatorLine,
322
323
  middle = __check_if_none(line_style.middle)
323
324
 
324
325
  # Create a line for each column (width)
326
+ hidden = set(hidden_columns_i or ())
325
327
  for width_i, width in enumerate(widths):
326
328
  # Do it only if the column is shown
327
- if (not show_empty and width_i not in empty_column_i
328
- ) or show_empty:
329
+ if width_i not in hidden and (
330
+ show_empty or width_i not in empty_column_i
331
+ ):
329
332
  if is_align_sensitive and will_have_indicators:
330
333
  checking_sets = list(map(lambda checker: [
331
334
  alignments[width_i],
@@ -410,7 +413,8 @@ def __get_column_lines(line_styles: List[SeparatorLine],
410
413
  left_right_upon_centering: bool,
411
414
  lines_with_indicator: List[int],
412
415
  indicator_margin: int,
413
- always_center_indicator: bool
416
+ always_center_indicator: bool,
417
+ hidden_columns_i=()
414
418
  ) -> Generator[str, None, None]:
415
419
  """
416
420
  Will get all the horizontal separators for the table based on
@@ -438,7 +442,8 @@ def __get_column_lines(line_styles: List[SeparatorLine],
438
442
  will_have_indicators,
439
443
  indicator_margin_string,
440
444
  full_margin_width,
441
- always_center_indicator
445
+ always_center_indicator,
446
+ hidden_columns_i,
442
447
  )
443
448
  )
444
449
  else:
@@ -449,7 +454,8 @@ def _get_separators(style_composition: TableComposition,
449
454
  col_widths: list,
450
455
  empty_column_i: List[int],
451
456
  show_empty: bool,
452
- alignments: list
457
+ alignments: list,
458
+ hidden_columns_i=()
453
459
  ) -> HorizontalComposition:
454
460
  """
455
461
  Get the horizontal separators for the table.
@@ -545,7 +551,8 @@ def _get_separators(style_composition: TableComposition,
545
551
  left_right_upon_centering,
546
552
  lines_with_indicator,
547
553
  indicator_margin,
548
- always_center
554
+ always_center,
555
+ hidden_columns_i,
549
556
  )
550
557
 
551
558
  # Create a HorizontalComposition object and pass the separator lines.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib
3
- Version: 2.0.14
3
+ Version: 2.0.15
4
4
  Summary: Flexible console and HTML tables for Python
5
5
  Home-page: https://github.com/Opus-Perpetuus/flexablelib
6
6
  Download-URL:
@@ -40,5 +40,6 @@ tests/test_two_pass_measurement.py
40
40
  tests/test_upstream_issues.py
41
41
  tests/test_v213_features.py
42
42
  tests/test_v214_features.py
43
+ tests/test_v215_features.py
43
44
  tools/benchmark.py
44
45
  tools/generate_width_tables.py
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flexablelib",
3
- "version": "2.0.14",
3
+ "version": "2.0.15",
4
4
  "description": "Flexible console and HTML tables for Python: styles, merges, colors, widths, decimal alignment.",
5
5
  "main": "__init__.py",
6
6
  "scripts": {
@@ -0,0 +1,101 @@
1
+ """Features shipped in 2.0.15 (stream, hide_columns, themes, sort callable)."""
2
+ import re
3
+ import pytest
4
+ from flexablelib.table import Table
5
+
6
+
7
+ def bare(text: str) -> str:
8
+ return re.sub(r'\x1b\[[0-9;]*m', '', text)
9
+
10
+
11
+ def test_stream_yields_lines_and_leaves_table_untouched():
12
+ t = Table(headers=['Num', 'Sq'], style_name='rounded')
13
+ lines = list(t.stream(([i, i * i] for i in range(4))))
14
+ out = '\n'.join(lines)
15
+ assert 'Num' in out and 'Sq' in out
16
+ assert '│ 3 │ 9 │' in bare(out) or '3' in bare(out)
17
+ assert t.row_count == 0
18
+ # Full streamed body appears between header and bottom.
19
+ assert bare(out).count('│') >= 4
20
+
21
+
22
+ def test_stream_append_keeps_rows():
23
+ t = Table(headers=['A', 'B'], style_name='sharp')
24
+ list(t.stream(([1, 2], [3, 4]), append=True))
25
+ assert t.row_count == 2
26
+ assert t.columns['A'] == [1, 3]
27
+
28
+
29
+ def test_stream_requires_headers():
30
+ t = Table()
31
+ with pytest.raises(ValueError, match='headers'):
32
+ list(t.stream([[1]]))
33
+
34
+
35
+ def test_stream_with_existing_rows_and_pretty_grid_separators():
36
+ t = Table.from_records([[0, 0]], headers=['A', 'B'], style_name='pretty_grid')
37
+ # Widths freeze from seed content; set floors so later rows are not
38
+ # truncated (beautifultable stream contract).
39
+ t.column_min_width = [4, 4]
40
+ lines = list(t.stream(([1, 10], [2, 20])))
41
+ joined = '\n'.join(lines)
42
+ # Inter-row rules present in pretty_grid.
43
+ assert '├' in joined or '+' in joined
44
+ assert '0' in joined and '20' in joined
45
+ assert t.row_count == 1 # append=False
46
+
47
+
48
+ def test_hide_columns_by_name_and_index():
49
+ t = Table.from_records(
50
+ [[1, 2, 3], [4, 5, 6]],
51
+ headers=['A', 'B', 'C'],
52
+ style_name='sharp',
53
+ )
54
+ t.hide_columns = 'B'
55
+ out = bare(t.compose())
56
+ assert 'B' not in out
57
+ assert '2' not in out and '5' not in out
58
+ assert 'A' in out and 'C' in out
59
+ t.hide_columns = [0, 2]
60
+ out2 = bare(t.compose())
61
+ assert 'B' in out2
62
+ assert 'A' not in out2 and 'C' not in out2
63
+
64
+
65
+ def test_hide_columns_bad_key():
66
+ t = Table.from_records([[1]], headers=['A'])
67
+ with pytest.raises(ValueError):
68
+ t.hide_columns = 'nope'
69
+ t.compose()
70
+
71
+
72
+ def test_apply_theme_and_unknown():
73
+ t = Table.from_records([[1, 2]], headers=['X', 'Y'])
74
+ t.apply_theme('markdown')
75
+ assert t.style_name == 'markdown'
76
+ assert t.use_colors is False
77
+ t.apply_theme('matrix')
78
+ assert t.style_name == 'ascii'
79
+ assert t.header_color == 'bold green'
80
+ with pytest.raises(ValueError, match='unknown theme'):
81
+ t.apply_theme('neon-disco')
82
+
83
+
84
+ def test_sort_by_callable():
85
+ t = Table.from_records(
86
+ [['z', 1], ['a', 2], ['m', 3]],
87
+ headers=['N', 'V'],
88
+ style_name='simple',
89
+ )
90
+ t.sort_by = lambda row: row[0]
91
+ out = bare(t.compose())
92
+ # 'a' row should appear before 'm' before 'z'
93
+ pos_a = out.find('a')
94
+ pos_m = out.find('m')
95
+ pos_z = out.find('z')
96
+ assert pos_a < pos_m < pos_z
97
+
98
+
99
+ def test_themes_catalog_nonempty():
100
+ assert 'dark' in Table.THEMES
101
+ assert 'ocean' in Table.THEMES
File without changes
File without changes
File without changes
File without changes
File without changes