-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove tabulate dependency and optimize table formatting
- Loading branch information
Showing
5 changed files
with
65 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from itertools import zip_longest | ||
|
||
__all__ = ["tabulate"] | ||
|
||
|
||
def tabulate(tabular_data, aligns): | ||
cols = list(zip_longest(*tabular_data)) | ||
cols = [["" if v is None else str(v) for v in c] for c in cols] | ||
cols = [_align_column(c, a) for c, a in zip(cols, aligns)] | ||
rows = list(zip(*cols)) | ||
return _format_table(rows) | ||
|
||
|
||
def _padleft(width, s): | ||
fmt = "{0:>%ds}" % width | ||
return fmt.format(s) | ||
|
||
|
||
def _padright(width, s): | ||
fmt = "{0:<%ds}" % width | ||
return fmt.format(s) | ||
|
||
|
||
def _align_column_choose_padfn(strings, alignment): | ||
strings = [s.strip() for s in strings] | ||
padfn = _padleft if alignment == "right" else _padright | ||
return strings, padfn | ||
|
||
|
||
def _align_column(strings, alignment): | ||
"""[string] -> [padded_string]""" | ||
strings, padfn = _align_column_choose_padfn(strings, alignment) | ||
|
||
s_widths = list(map(len, strings)) | ||
maxwidth = max(s_widths) | ||
return [padfn(maxwidth, s) for s in strings] | ||
|
||
|
||
def _build_row(padded_cells): | ||
"Return a string which represents a row of data cells." | ||
return " ".join(padded_cells).rstrip() | ||
|
||
|
||
def _append_basic_row(lines, padded_cells): | ||
lines.append(_build_row(padded_cells)) | ||
return lines | ||
|
||
|
||
def _format_table(rows): | ||
"""Produce a plain-text representation of the table.""" | ||
lines = [] | ||
|
||
padded_rows = [[cell for cell in row] for row in rows] | ||
|
||
for row in padded_rows: | ||
_append_basic_row(lines, row) | ||
|
||
return "\n".join(lines) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "deciphon-snap" | ||
version = "0.11.3" | ||
version = "0.12.0" | ||
description = "Reader for Deciphon snap files." | ||
authors = ["Danilo Horta <[email protected]>"] | ||
license = "MIT" | ||
|
@@ -11,7 +11,6 @@ packages = [{ include = "deciphon_snap" }] | |
python = "^3.9" | ||
fsspec = ">=2024.5.0" | ||
h3result = "^0.3" | ||
tabulate = "^0.9" | ||
fasta-reader = "^3.0" | ||
deciphon-intervals = "^0.1" | ||
prettytable = "^3.10" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters