Skip to content

Commit 435c13f

Browse files
Fix compatibility with tabulate 0.10.0
Because `tabulate.PRESERVE_WHITESPACE` was replaced with a keyword argument but was not removed from the module namespace (even though modifying it no longer has any effect), the only way to check whether we should pass the new `preserve_whitespace` argument is to examine `tabulate.__version__`. This required adding a dependency on `packaging` to parse and compare the version string.
1 parent 9fb9f65 commit 435c13f

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

cli_helpers/tabular_output/tabulate_adapter.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
escape_newlines,
2222
)
2323

24+
from packaging.version import Version
2425
import tabulate
2526

2627

@@ -249,7 +250,10 @@ def adapter(data, headers, table_format=None, preserve_whitespace=False, **kwarg
249250
if table_format in supported_markup_formats:
250251
tkwargs.update(numalign=None, stralign=None)
251252

252-
tabulate.PRESERVE_WHITESPACE = preserve_whitespace
253+
if Version(tabulate.__version__) < Version("0.10.0"):
254+
tabulate.PRESERVE_WHITESPACE = preserve_whitespace
255+
else:
256+
tkwargs.update(preserve_whitespace=preserve_whitespace)
253257

254258
tkwargs.update(default_kwargs.get(table_format, {}))
255259
if table_format in headless_formats:

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def open_file(filename):
3737
long_description_content_type="text/x-rst",
3838
install_requires=[
3939
"configobj >= 5.0.5",
40+
"packaging",
4041
"tabulate[widechars] >= 0.9.0",
4142
],
4243
extras_require={

0 commit comments

Comments
 (0)