From 90548808815680ac1e81809aae78afac36f11769 Mon Sep 17 00:00:00 2001 From: Allison Vacanti Date: Thu, 8 Jul 2021 14:48:02 -0400 Subject: [PATCH] Support older versions of tabulate module. Ubuntu 18.04 only provides tabulate v0.7, but colalign and github formatting options were added in 0.8.3. --- scripts/nvbench_compare.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/nvbench_compare.py b/scripts/nvbench_compare.py index 9126092..8a25b69 100755 --- a/scripts/nvbench_compare.py +++ b/scripts/nvbench_compare.py @@ -7,6 +7,12 @@ import sys import tabulate +# Parse version string into tuple, "x.y.z" -> (x, y, z) +def version_tuple(v): + return tuple(map(int, (v.split(".")))) + +tabulate_version = version_tuple(tabulate.__version__) + if len(sys.argv) != 3: print("Usage: %s reference.json compare.json\n" % sys.argv[0]) sys.exit(1) @@ -230,10 +236,17 @@ def compare_benches(ref_benches, cmp_benches): rows.append(row) - print(tabulate.tabulate(rows, - headers=headers, - colalign=colalign, - tablefmt="github")) + # colalign and github format require tabulate 0.8.3 + if tabulate_version >= (0, 8, 3): + print(tabulate.tabulate(rows, + headers=headers, + colalign=colalign, + tablefmt="github")) + else: + print(tabulate.tabulate(rows, + headers=headers, + tablefmt="markdown")) + print("")