From 930a943887b8a269b7445fa89d4a6c88281b824b Mon Sep 17 00:00:00 2001 From: Sergey Astanin Date: Thu, 6 Oct 2022 12:21:18 +0200 Subject: [PATCH] reformat with black, fix flake warnings --- README.md | 8 ++++---- tabulate.py | 51 ++++++++++++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 73b223c..89ebc63 100644 --- a/README.md +++ b/README.md @@ -460,10 +460,10 @@ format: >>> print(tabulate(table, headers, tablefmt="asciidoc")) [cols="8<,7>",options="header"] |==== -| item | qty -| spam | 42 -| eggs | 451 -| bacon | 0 +| item | qty +| spam | 42 +| eggs | 451 +| bacon | 0 |==== ``` diff --git a/tabulate.py b/tabulate.py index 9e17ece..46f2e0d 100644 --- a/tabulate.py +++ b/tabulate.py @@ -207,52 +207,57 @@ def _latex_line_begin_tabular(colwidths, colaligns, booktabs=False, longtable=Fa ] ) + def _asciidoc_row(is_header, *args): - """ handle header and data rows for asciidoc format """ + """handle header and data rows for asciidoc format""" def make_header_line(is_header, colwidths, colaligns): # generate the column specifiers - + alignment = {"left": "<", "right": ">", "center": "^", "decimal": ">"} # use the column widths generated by tabulate for the asciidoc column width specifiers - asciidoc_alignments = zip(colwidths,[alignment[colalign] for colalign in colaligns]) - asciidoc_column_specifiers = ["{:d}{}".format(width,align) for width, align in asciidoc_alignments] - header_list=['cols="'+(','.join(asciidoc_column_specifiers))+'"'] - + asciidoc_alignments = zip( + colwidths, [alignment[colalign] for colalign in colaligns] + ) + asciidoc_column_specifiers = [ + "{:d}{}".format(width, align) for width, align in asciidoc_alignments + ] + header_list = ['cols="' + (",".join(asciidoc_column_specifiers)) + '"'] + # generate the list of options (currently only "header") options_list = [] - + if is_header: - options_list.append('header') - + options_list.append("header") + if options_list: - header_list += ['options="' + ','.join(options_list) + '"'] - - # generate the list of entries in the table header field + header_list += ['options="' + ",".join(options_list) + '"'] - return '[{}]\n|===='.format(','.join(header_list)) + # generate the list of entries in the table header field + return "[{}]\n|====".format(",".join(header_list)) if len(args) == 2: # two arguments are passed if called in the context of aboveline # print the table header with column widths and optional header tag - return make_header_line(False,*args) + return make_header_line(False, *args) elif len(args) == 3: # three arguments are passed if called in the context of dataline or headerline # print the table line and make the aboveline if it is a header - + cell_values, colwidths, colaligns = args - data_line = '|' + '|'.join(cell_values) - + data_line = "|" + "|".join(cell_values) + if is_header: - return make_header_line(True, colwidths, colaligns) + '\n' + data_line + return make_header_line(True, colwidths, colaligns) + "\n" + data_line else: return data_line else: raise ValueError( - " _asciidoc_row() requires two (colwidths, colaligns) or three (cell_values, colwidths, colaligns) arguments) " + " _asciidoc_row() requires two (colwidths, colaligns) " + + "or three (cell_values, colwidths, colaligns) arguments) " ) @@ -660,9 +665,9 @@ def escape_empty(val): lineabove=partial(_asciidoc_row, False), linebelowheader=None, linebetweenrows=None, - linebelow=Line("|====","","",""), + linebelow=Line("|====", "", "", ""), headerrow=partial(_asciidoc_row, True), - datarow=partial(_asciidoc_row, False), + datarow=partial(_asciidoc_row, False), padding=1, with_header_hide=["lineabove"], ), @@ -1735,8 +1740,8 @@ def tabulate( ┃ eggs ┃ 451 ┃ ┗━━━━━━━━━━━┻━━━━━━━━━━━┛ - "mixed_grid" draws a grid using a mix of light (thin) and heavy (thick) lines box-drawing characters: - characters: + "mixed_grid" draws a grid using a mix of light (thin) and heavy (thick) lines + box-drawing characters: >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]], ... ["strings", "numbers"], "mixed_grid"))