Skip to content

Commit ff0fc58

Browse files
finish parenthesizing print statements (#24)
* finish parenthesizing print statements * [pre-commit.ci] auto fixes from pre-commit hooks --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c28b97b commit ff0fc58

30 files changed

+757
-930
lines changed

Diff for: devutils/prep.py

+23-21
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,21 @@ def __init__(self):
1818

1919
def test(self, call, *args, **kwds):
2020
m = sys.modules[call.__module__]
21-
testname = m.__name__+'.'+call.__name__
21+
testname = m.__name__ + "." + call.__name__
2222
path = os.path.dirname(m.__file__)
2323
os.chdir(path)
2424
try:
2525
call(*args, **kwds)
26-
self.messages.append("%s: success" %testname)
27-
except Exception, e:
28-
self.messages.append("%s: error, details below.\n%s" %(testname, e))
26+
self.messages.append("%s: success" % testname)
27+
except Exception as e:
28+
self.messages.append("%s: error, details below.\n%s" % (testname, e))
2929
finally:
3030
os.chdir(__basedir__)
3131

3232
def report(self):
33-
print '==== Results of Tests ===='
34-
print '\n'.join(self.messages)
33+
print("==== Results of Tests ====")
34+
print("\n".join(self.messages))
35+
3536

3637
def scrubeol(directory, filerestr):
3738
"""Use unix-style endlines for files in directory matched by regex string.
@@ -50,11 +51,11 @@ def scrubeol(directory, filerestr):
5051
text = unicode(original.read())
5152
original.close()
5253

53-
updated = io.open(f, 'w', newline='\n')
54+
updated = io.open(f, "w", newline="\n")
5455
updated.write(text)
5556
updated.close()
5657

57-
print "Updated %s to unix-style endlines." %f
58+
print("Updated %s to unix-style endlines." % f)
5859

5960

6061
def rm(directory, filerestr):
@@ -72,14 +73,13 @@ def rm(directory, filerestr):
7273
for f in files:
7374
os.remove(f)
7475

75-
print "Deleted %s." %f
76-
76+
print("Deleted %s." % f)
7777

7878

7979
if __name__ == "__main__":
8080

8181
# Temporarily add examples to path
82-
lib_path = os.path.abspath(os.path.join('..','doc','examples'))
82+
lib_path = os.path.abspath(os.path.join("..", "doc", "examples"))
8383
sys.path.append(lib_path)
8484

8585
# Delete existing files that don't necessarily have a fixed name.
@@ -88,14 +88,16 @@ def rm(directory, filerestr):
8888

8989
### Testing examples
9090
examples = Test()
91-
test_names = ["extract_single_peak",
92-
"parameter_summary",
93-
"fit_initial",
94-
"query_results",
95-
"multimodel_known_dG1",
96-
"multimodel_known_dG2",
97-
"multimodel_unknown_dG1",
98-
"multimodel_unknown_dG2"]
91+
test_names = [
92+
"extract_single_peak",
93+
"parameter_summary",
94+
"fit_initial",
95+
"query_results",
96+
"multimodel_known_dG1",
97+
"multimodel_known_dG2",
98+
"multimodel_unknown_dG1",
99+
"multimodel_unknown_dG2",
100+
]
99101

100102
test_modules = []
101103
for test in test_names:
@@ -107,7 +109,7 @@ def rm(directory, filerestr):
107109
examples.report()
108110

109111
### Convert output of example files to Unix-style endlines for sdist.
110-
if os.linesep != '\n':
111-
print"==== Scrubbing Endlines ===="
112+
if os.linesep != "\n":
113+
print("==== Scrubbing Endlines ====")
112114
# All *.srmise and *.pwa files in examples directory.
113115
scrubeol("../doc/examples/output", r".*(\.srmise|\.pwa)")

Diff for: diffpy/srmise/applications/extract.py

+12-33
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ def main():
149149
"--pf",
150150
dest="peakfunction",
151151
metavar="PF",
152-
help="Fit peak function PF defined in "
153-
"diffpy.srmise.peaks, e.g. "
154-
"'GaussianOverR(maxwidth=0.7)'",
152+
help="Fit peak function PF defined in " "diffpy.srmise.peaks, e.g. " "'GaussianOverR(maxwidth=0.7)'",
155153
)
156154
parser.add_option(
157155
"--cres",
@@ -230,34 +228,30 @@ def main():
230228
dest="bpoly0",
231229
type="string",
232230
metavar="a0[c]",
233-
help="Use constant baseline given by y=a0. "
234-
"Append 'c' to make parameter constant.",
231+
help="Use constant baseline given by y=a0. " "Append 'c' to make parameter constant.",
235232
)
236233
group.add_option(
237234
"--bpoly1",
238235
dest="bpoly1",
239236
type="string",
240237
nargs=2,
241238
metavar="a1[c] a0[c]",
242-
help="Use baseline given by y=a1*x + a0. Append 'c' to "
243-
"make parameter constant.",
239+
help="Use baseline given by y=a1*x + a0. Append 'c' to " "make parameter constant.",
244240
)
245241
group.add_option(
246242
"--bpoly2",
247243
dest="bpoly2",
248244
type="string",
249245
nargs=3,
250246
metavar="a2[c] a1[c] a0[c]",
251-
help="Use baseline given by y=a2*x^2+a1*x + a0. Append "
252-
"'c' to make parameter constant.",
247+
help="Use baseline given by y=a2*x^2+a1*x + a0. Append " "'c' to make parameter constant.",
253248
)
254249
group.add_option(
255250
"--bseq",
256251
dest="bseq",
257252
type="string",
258253
metavar="FILE",
259-
help="Use baseline interpolated from x,y values in FILE. "
260-
"This baseline has no free parameters.",
254+
help="Use baseline interpolated from x,y values in FILE. " "This baseline has no free parameters.",
261255
)
262256
group.add_option(
263257
"--bspherical",
@@ -343,9 +337,7 @@ def main():
343337
metavar="FILE",
344338
help="Save result of extraction to FILE (.srmise " "format).",
345339
)
346-
group.add_option(
347-
"--plot", "-p", action="store_true", dest="plot", help="Plot extracted peaks."
348-
)
340+
group.add_option("--plot", "-p", action="store_true", dest="plot", help="Plot extracted peaks.")
349341
group.add_option(
350342
"--liveplot",
351343
"-l",
@@ -362,9 +354,7 @@ def main():
362354
)
363355
parser.add_option_group(group)
364356

365-
group = OptionGroup(
366-
parser, "Verbosity Options", "Control detail printed to console."
367-
)
357+
group = OptionGroup(parser, "Verbosity Options", "Control detail printed to console.")
368358
group.add_option(
369359
"--informative",
370360
"-i",
@@ -435,9 +425,7 @@ def main():
435425
options.peakfunction = eval("peaks." + options.peakfunction)
436426
except Exception as err:
437427
print(err)
438-
print(
439-
"Could not create peak function '%s'. Exiting." % options.peakfunction
440-
)
428+
print("Could not create peak function '%s'. Exiting." % options.peakfunction)
441429
return
442430

443431
if options.modelevaluator is not None:
@@ -447,9 +435,7 @@ def main():
447435
options.modelevaluator = eval("modelevaluators." + options.modelevaluator)
448436
except Exception as err:
449437
print(err)
450-
print(
451-
"Could not find ModelEvaluator '%s'. Exiting." % options.modelevaluator
452-
)
438+
print("Could not find ModelEvaluator '%s'. Exiting." % options.modelevaluator)
453439
return
454440

455441
if options.bcrystal is not None:
@@ -534,9 +520,7 @@ def main():
534520
if options.rng is not None:
535521
pdict["rng"] = list(options.rng)
536522
if options.qmax is not None:
537-
pdict["qmax"] = (
538-
options.qmax if options.qmax == "automatic" else float(options.qmax)
539-
)
523+
pdict["qmax"] = options.qmax if options.qmax == "automatic" else float(options.qmax)
540524
if options.nyquist is not None:
541525
pdict["nyquist"] = options.nyquist
542526
if options.supersample is not None:
@@ -624,10 +608,7 @@ def _format_text(self, text):
624608
# the above is still the same
625609
bits = text.split("\n")
626610
formatted_bits = [
627-
textwrap.fill(
628-
bit, text_width, initial_indent=indent, subsequent_indent=indent
629-
)
630-
for bit in bits
611+
textwrap.fill(bit, text_width, initial_indent=indent, subsequent_indent=indent) for bit in bits
631612
]
632613
result = "\n".join(formatted_bits) + "\n"
633614
return result
@@ -665,9 +646,7 @@ def format_option(self, option):
665646
help_lines.extend(textwrap.wrap(para, self.help_width))
666647
# Everything is the same after here
667648
result.append("%*s%s\n" % (indent_first, "", help_lines[0]))
668-
result.extend(
669-
["%*s%s\n" % (self.help_position, "", line) for line in help_lines[1:]]
670-
)
649+
result.extend(["%*s%s\n" % (self.help_position, "", line) for line in help_lines[1:]])
671650
elif opts[-1] != "\n":
672651
result.append("\n")
673652
return "".join(result)

Diff for: diffpy/srmise/applications/plot.py

+11-44
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,7 @@ def makeplot(ppe_or_stability, ip=None, **kwds):
194194
x = ppe.x[rangeslice]
195195
y = ppe.y[rangeslice]
196196
dy = ppe.effective_dy[rangeslice]
197-
mcluster = ModelCluster(
198-
ppe.initial_peaks, ppe.baseline, x, y, dy, None, ppe.error_method, ppe.pf
199-
)
197+
mcluster = ModelCluster(ppe.initial_peaks, ppe.baseline, x, y, dy, None, ppe.error_method, ppe.pf)
200198
ext = mcluster
201199
else:
202200
ext = ppe.extracted
@@ -255,9 +253,7 @@ def makeplot(ppe_or_stability, ip=None, **kwds):
255253
# Define the various data which will be plotted
256254
r = ext.r_cluster
257255
dr = (r[-1] - r[0]) / len(r)
258-
rexpand = np.concatenate(
259-
(np.arange(r[0] - dr, xlo, -dr)[::-1], r, np.arange(r[-1] + dr, xhi + dr, dr))
260-
)
256+
rexpand = np.concatenate((np.arange(r[0] - dr, xlo, -dr)[::-1], r, np.arange(r[-1] + dr, xhi + dr, dr)))
261257
rfine = np.arange(r[0], r[-1], 0.1 * dr)
262258
gr_obs = np.array(resample(ppe.x, ppe.y, rexpand)) * scale
263259
# gr_fit = resample(r, ext.value(), rfine)
@@ -295,21 +291,10 @@ def makeplot(ppe_or_stability, ip=None, **kwds):
295291
max_res = 0.0
296292

297293
# Derive various y limits based on all the offsets
298-
rel_height = (
299-
100.0
300-
- top_offset
301-
- dg_height
302-
- cmp_height
303-
- datatop_offset
304-
- databottom_offset
305-
- bottom_offset
306-
)
294+
rel_height = 100.0 - top_offset - dg_height - cmp_height - datatop_offset - databottom_offset - bottom_offset
307295
abs_height = 100 * ((max_gr - min_gr) + (max_res - min_res)) / rel_height
308296

309-
yhi = (
310-
max_gr
311-
+ (top_offset + dg_height + cmp_height + datatop_offset) * abs_height / 100
312-
)
297+
yhi = max_gr + (top_offset + dg_height + cmp_height + datatop_offset) * abs_height / 100
313298
ylo = yhi - abs_height
314299

315300
yhi = kwds.get("yhi", yhi)
@@ -353,13 +338,7 @@ def makeplot(ppe_or_stability, ip=None, **kwds):
353338

354339
# Remove labels above where insets begin
355340
# ax_data.yaxis.set_ticklabels([str(int(loc)) for loc in ax_data.yaxis.get_majorticklocs() if loc < datatop])
356-
ax_data.yaxis.set_ticks(
357-
[
358-
loc
359-
for loc in ax_data.yaxis.get_majorticklocs()
360-
if (loc < datatop and loc >= ylo)
361-
]
362-
)
341+
ax_data.yaxis.set_ticks([loc for loc in ax_data.yaxis.get_majorticklocs() if (loc < datatop and loc >= ylo)])
363342

364343
# Dataset label
365344
if datalabel is not None:
@@ -378,9 +357,7 @@ def makeplot(ppe_or_stability, ip=None, **kwds):
378357

379358
# Create new x axis at bottom edge of compare inset
380359
ax_data.axis["top"].set_visible(False)
381-
ax_data.axis["newtop"] = ax_data.new_floating_axis(
382-
0, datatop, axis_direction="bottom"
383-
) # "top" bugged?
360+
ax_data.axis["newtop"] = ax_data.new_floating_axis(0, datatop, axis_direction="bottom") # "top" bugged?
384361
ax_data.axis["newtop"].toggle(all=False, ticks=True)
385362
ax_data.axis["newtop"].major_ticks.set_tick_out(True)
386363
ax_data.axis["newtop"].minor_ticks.set_tick_out(True)
@@ -399,9 +376,7 @@ def makeplot(ppe_or_stability, ip=None, **kwds):
399376
transform=ax_data.transAxes,
400377
)
401378
labeldict[fig] = newylabel # so we can find the correct text object
402-
fig.canvas.mpl_connect(
403-
"draw_event", on_draw
404-
) # original label invisibility and updating
379+
fig.canvas.mpl_connect("draw_event", on_draw) # original label invisibility and updating
405380

406381
# Compare extracted (and ideal, if provided) peak positions clearly.
407382
if cmp_height > 0:
@@ -610,15 +585,9 @@ def main():
610585
type="int",
611586
help="Plot given model from set. Ignored if srmise_file is not a PeakStability file.",
612587
)
613-
parser.add_option(
614-
"--show", action="store_true", help="execute pylab.show() blocking call"
615-
)
616-
parser.add_option(
617-
"-o", "--output", type="string", help="save plot to the specified file"
618-
)
619-
parser.add_option(
620-
"--format", type="string", default="eps", help="output format for plot saving"
621-
)
588+
parser.add_option("--show", action="store_true", help="execute pylab.show() blocking call")
589+
parser.add_option("-o", "--output", type="string", help="save plot to the specified file")
590+
parser.add_option("--format", type="string", default="eps", help="output format for plot saving")
622591
parser.allow_interspersed_args = True
623592
opts, args = parser.parse_args(sys.argv[1:])
624593

@@ -636,9 +605,7 @@ def main():
636605
try:
637606
toplot.load(filename)
638607
except Exception:
639-
print(
640-
"File '%s' is not a .srmise or PeakStability data file." % filename
641-
)
608+
print("File '%s' is not a .srmise or PeakStability data file." % filename)
642609
return
643610

644611
if opts.model is not None:

0 commit comments

Comments
 (0)