Skip to content

Commit

Permalink
reformat with black, fix flake warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
astanin committed Oct 6, 2022
1 parent 569fc99 commit 930a943
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -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
|====
```

Expand Down
51 changes: 28 additions & 23 deletions tabulate.py
Expand Up @@ -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) "
)


Expand Down Expand Up @@ -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"],
),
Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit 930a943

Please sign in to comment.