Skip to content

Commit d80cd69

Browse files
committed
Further shorten output messages
1 parent f038c8e commit d80cd69

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

attotree/attotree.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030

3131
def shorten_output(s):
3232
# return pprint.pformat(s)
33-
if len(s)>40:
34-
s=s[:40]+"..."
33+
if len(s) > 40:
34+
s = s[:40] + "..."
3535
return s
3636

37+
3738
def error(*msg, error_code=1):
3839
"""
3940
Prints an error message to stderr and exits the program with the specified error code.
@@ -103,7 +104,7 @@ def run_safe(command, output_fn=None, output_fo=None, err_msg=None, thr_exc=True
103104
command_str_nice = shorten_output(command_str)
104105

105106
if not silent:
106-
message("Shell command:", command_str_nice)
107+
message(f"Shell command: '{command_str_nice}'")
107108

108109
if output_fn is None:
109110
if output_fo is None:
@@ -130,9 +131,9 @@ def run_safe(command, output_fn=None, output_fo=None, err_msg=None, thr_exc=True
130131

131132
if error_code == 0 or error_code == 141:
132133
if not silent:
133-
message("Finished: {}".format(command_str_nice))
134+
message(f"Finished: '{command_str_nice}'")
134135
else:
135-
message("Unfinished, an error occurred (error code {}): {}".format(error_code, command_str))
136+
message(f"Unfinished, an error occurred (error code {error_code}): '{command_str}'")
136137

137138
if err_msg is not None:
138139
print('Error: {}'.format(err_msg), file=sys.stderr)
@@ -161,7 +162,7 @@ def mash_triangle(inp_fns, phylip_fn, k, s, t, fof, verbose):
161162
Raises:
162163
None
163164
"""
164-
message("Running mash")
165+
message("Running Mash")
165166
cmd = f"mash triangle -s {s} -k {k} -p {t}".split()
166167
if fof:
167168
cmd += ["-l"]
@@ -203,11 +204,11 @@ def postprocess_mash_phylip(phylip_in_fn, phylip_out_fn, verbose):
203204
for i, x in enumerate(f):
204205
x = x.strip()
205206
if i != 0:
206-
print(x, file=sys.stderr)
207207
l, sep, r = x.partition("\t")
208208
l = fn_to_node_name(l)
209209
x = l + sep + r
210-
message(x)
210+
if verbose:
211+
message("Mash output:", x)
211212
print(x, file=g)
212213
#basename_components = os.path.basename(p[0]).split(".")
213214
#if len(basename_components) == 1:
@@ -283,7 +284,7 @@ def attotree(fns, newick_fo, k, s, t, phylogeny_algorithm, fof, verbose):
283284
None
284285
"""
285286
with tempfile.TemporaryDirectory() as d:
286-
message('created a temporary directory', d)
287+
message('Created a temporary directory', d)
287288
phylip1_fn = os.path.join(d, "distances.phylip0")
288289
phylip2_fn = os.path.join(d, "distances.phylip")
289290
newick1_fn = os.path.join(d, "tree.nw")

0 commit comments

Comments
 (0)