Skip to content

Commit

Permalink
Closed #10: CLI option for setting floatfmt for tabulate
Browse files Browse the repository at this point in the history
  • Loading branch information
retifrav committed Jan 16, 2022
1 parent b758997 commit 5137515
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/tap_adql_sandbox/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
mainWindowID = "main-window"
queryTextID = "query-text"

tabulateFloatfmtPrecision = "g"

lastQueryResults = {}
executingQuery = False

Expand Down Expand Up @@ -105,13 +107,17 @@ def executeQuery():

if debugMode:
print("\n[DEBUG] Results found:", len(results))
print(
tabulate(
results.to_table(),
headers=results.fieldnames,
tablefmt="psql"
try:
print(
tabulate(
results.to_table(),
headers=results.fieldnames,
tablefmt="psql",
floatfmt=tabulateFloatfmtPrecision
)
)
)
except Exception as ex:
print(f"[WARNING] Couldn't print results. {ex}")

showLoading(False)

Expand Down Expand Up @@ -177,6 +183,8 @@ def showDPGabout():

def main():
global debugMode
global tabulateFloatfmtPrecision

argParser = argparse.ArgumentParser(
prog="tap-adql-sandbox",
description=" ".join((
Expand All @@ -197,10 +205,16 @@ def main():
action='store_true',
help=f"enable debug/dev mode (default: %(default)s)"
)
argParser.add_argument(
"--tbl-flt-prcs",
metavar=".8f",
help="floating point precision for tabulate output"
)
cliArgs = argParser.parse_args()
# print(cliArgs)

debugMode = cliArgs.debug
tabulateFloatfmtPrecision = cliArgs.tbl_flt_prcs

dpg.create_context()

Expand Down

0 comments on commit 5137515

Please sign in to comment.