Skip to content

Commit

Permalink
PY3: changes not suggested by pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos committed Dec 6, 2022
1 parent 5cc47eb commit bbeb8aa
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 41 deletions.
27 changes: 15 additions & 12 deletions nmrglue/fileio/sparky.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ def read_2D(filename):
dic = fileheader2dic(get_fileheader(f))

# check for file size mismatch
if seek_pos != dic["seek_pos"]:
warn('Bad file size in header %s vs %s' %
(seek_pos, dic['seek_pos']))
expected_seek_pos = dic["seek_pos"]
if seek_pos != expected_seek_pos:
warn(f'Bad file size in header {seek_pos} vs {expected_seek_pos}')

# read the axis headers...
for i in range(dic['naxis']):
Expand Down Expand Up @@ -448,9 +448,9 @@ def read_3D(filename):
dic = fileheader2dic(get_fileheader(f))

# check for file size mismatch
if seek_pos != dic["seek_pos"]:
warn('Bad file size in header %s vs %s' %
(seek_pos, dic['seek_pos']))
expected_seek_pos = dic["seek_pos"]
if seek_pos != expected_seek_pos:
warn(f'Bad file size in header {seek_pos} vs {expected_seek_pos}')

# read the axis headers...
for i in range(dic['naxis']):
Expand Down Expand Up @@ -512,8 +512,9 @@ def read_4D(filename):
dic = fileheader2dic(get_fileheader(f))

# check for file size mismatch
if seek_pos != dic["seek_pos"]:
warn('Bad file size in header {} vs {}'.format(seek_pos, dic['seek_pos']))
expected_seek_pos = dic['seek_pos']
if seek_pos != expected_seek_pos:
warn(f'Bad file size in header {seek_pos} vs {expected_seek_pos}')

# read the axis headers...
for i in range(dic['naxis']):
Expand Down Expand Up @@ -548,8 +549,9 @@ def read_lowmem_2D(filename):
dic = dict(data.dic)

# check for file size mismatch
if seek_pos != dic["seek_pos"]:
warn('Bad file size in header {} vs {}'.format(seek_pos, dic['seek_pos']))
expected_seek_pos = dic['seek_pos']
if seek_pos != expected_seek_pos:
warn(f'Bad file size in header {seek_pos} vs {expected_seek_pos}')
return dic, data


Expand All @@ -564,8 +566,9 @@ def read_lowmem_3D(filename):
dic = dict(data.dic)

# check for file size mismatch
if seek_pos != dic["seek_pos"]:
warn('Bad file size in header {} vs {}'.format(seek_pos, dic['seek_pos']))
expected_seek_pos = dic['seek_pos']
if seek_pos != expected_seek_pos:
warn(f'Bad file size in header {seek_pos} vs {expected_seek_pos}')

return dic, data

Expand Down
4 changes: 2 additions & 2 deletions nmrglue/fileio/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def guess_pformat(col):
# N is the number of digits in largest value, or 1
N = max(np.ceil(np.log(np.abs(col).max()) / np.log(10)), 1)
# +1 for sign
return '%{0}d'.format(int(N + 1))
return f'%{int(N) + 1}d'

if kind == 'f':
# will be either %+e or %N.3f, see if 'e' is in %g to determine
Expand All @@ -103,7 +103,7 @@ def guess_pformat(col):
else:
N = max(np.ceil(np.log(np.abs(col).max()) / np.log(10)), 1)
# +1 for sign, +1 for decimal points, +3 for precision
return f'%{int(N + 5)}.3f'
return f'%{int(N) + 5}.3f'

# remaining kinds: 'c' - complex, 'b' - boolean, 'U' - unicode, 'V' - void
raise ValueError("unknown kind %s in column" % (kind))
Expand Down
32 changes: 13 additions & 19 deletions nmrglue/util/xcpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,15 @@ def write_cfg(outfile, infile=None):
cpyname, scripts_location = read_cfg(infile)
except OSError:
if exists(infile):
errmsg = """
The following configuration was found in the file {}:
errmsg = f"""
The following configuration was found in the file {infile}:
{}
{show_config(infile, printing=False)}
These settings are likely incorrect.
You can enter the correct settings at the next dialog box.
Press 'Close' to continue.
""".format(
infile, show_config(infile, printing=False)
)
"""
MSG(errmsg)

cpyname, scripts_location = read_cfg(infile, check_python=False)
Expand Down Expand Up @@ -312,14 +310,12 @@ def verify_python(command):
command = command.split(os.sep)[-1]
if command.lower().find("python") != 0:

errmsg = """
{} does not seem to be a valid python file.
errmsg = f"""
{command} does not seem to be a valid python file.
Please check the configuration file using 'xcpy --config',
or change the configuration file using 'xcpy --settings'
This attempt will be aborted.
""".format(
command
)
"""

raise OSError(errmsg)

Expand Down Expand Up @@ -373,14 +369,12 @@ def main():
# if it does not, alert the user and open up a dialog box to write it out
elif not os.path.exists(config_file):
MSG(
"""
f"""
Configuration file does not exist.
An input box will be opened next to write it.
Alternately, it can be manually edited at {}.
Alternately, it can be manually edited at {config_file}.
Press 'Close' to continue.
""".format(
config_file
)
"""
)
write_cfg(config_file)

Expand Down Expand Up @@ -455,10 +449,10 @@ def main():

# executed should be false iff no script was found
if not executed:
scriptname = argv[-1] + ".py"
folders = "\n".join(folders)
raise Exception(
"The file {} was not found in the following folders:\n\n{}".format(
argv[-1] + ".py", "\n".join(folders)
)
f"The file {scriptname} was not found in the following folders:\n\n{folders}"
)

# handle errors and print messages from cpython
Expand Down
16 changes: 8 additions & 8 deletions nmrglue/util/xcpy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ def main():

try:
name, curdir, curexpno, curprocno = sys.argv
message = """
Welcome to Python {}.
The current directory is set to {}
EXPNO {} is currently open at PROCNO {}
""".format(python, curdir, curexpno, curprocno)
message = f"""
Welcome to Python {python}.
The current directory is set to {curdir}
EXPNO {curexpno} is currently open at PROCNO {curprocno}
"""

except ValueError:
message = """
Welcome to Python {}.
message = f"""
Welcome to Python {python}.
No directory is currently open,
or none was passed on to this script.
""".format(python)
"""

print(message)

Expand Down

0 comments on commit bbeb8aa

Please sign in to comment.