Skip to content

Commit

Permalink
some pylint fixes:
Browse files Browse the repository at this point in the history
  • Loading branch information
zingale committed Apr 2, 2024
1 parent dfb14d7 commit 391a28e
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 152 deletions.
66 changes: 39 additions & 27 deletions params.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
try: import ConfigParser as configparser
except ImportError:
import configparser # python 3
import configparser

import getpass
import os
Expand All @@ -16,19 +14,27 @@ def convert_type(string):
if string is None:
return None

try: int(string)
except: pass
else: return int(string)
try:
int(string)
except:
pass
else:
return int(string)

try: float(string)
except: pass
else: return float(string)
try:
float(string)
except:
pass
else:
return float(string)

return string.strip()

def safe_get(cp, sec, opt, default=None):
try: v = cp.get(sec, opt)
except: v = default
try:
v = cp.get(sec, opt)
except:
v = default
return v

def load_params(args):
Expand All @@ -52,8 +58,9 @@ def load_params(args):

if not os.path.exists(args.input_file[0]):
raise OSError(f"Parameter file {args.input_file[0]} does not exist")

try: cp.read(args.input_file[0])

try:
cp.read(args.input_file[0])
except:
log.fail(f"ERROR: unable to read parameter file {args.input_file[0]}")

Expand Down Expand Up @@ -120,7 +127,8 @@ def load_params(args):

# now all the other build and source directories
other_srcs = [s for s in cp.sections() if s.startswith("extra-")]
if not mysuite.sourceTree in ["AMReX", "amrex"]: other_srcs.append("source")
if not mysuite.sourceTree in ["AMReX", "amrex"]:
other_srcs.append("source")

for s in other_srcs:
if s.startswith("extra-"):
Expand All @@ -134,7 +142,8 @@ def load_params(args):


build = convert_type(safe_get(cp, s, "build", default=0))
if s == "source": build = 1
if s == "source":
build = 1

comp_string = safe_get(cp, s, "comp_string")

Expand Down Expand Up @@ -165,14 +174,14 @@ def load_params(args):

# now flesh out the compile strings -- they may refer to either themselves
# or the source dir
for r in mysuite.repos.keys():
for r in mysuite.repos:
s = mysuite.repos[r].comp_string
if not s is None:
mysuite.repos[r].comp_string = \
s.replace("@self@", mysuite.repos[r].dir).replace("@source@", mysuite.repos["source"].dir)

# the suite needs to know any ext_src_comp_string
for r in mysuite.repos.keys():
for r in mysuite.repos:
if not mysuite.repos[r].build == 1:
if not mysuite.repos[r].comp_string is None:
mysuite.extra_src_comp_string += f" {mysuite.repos[r].comp_string} "
Expand All @@ -197,7 +206,8 @@ def load_params(args):
mysuite.slack_post = 0
else:
print(mysuite.slack_webhookfile)
try: f = open(mysuite.slack_webhookfile)
try:
f = open(mysuite.slack_webhookfile)
except:
mysuite.log.warn("unable to open webhook file")
mysuite.slack_post = 0
Expand All @@ -212,7 +222,8 @@ def load_params(args):

# Make sure the web dir is valid
if not os.path.isdir(mysuite.webTopDir):
try: os.mkdir(mysuite.webTopDir)
try:
os.mkdir(mysuite.webTopDir)
except:
mysuite.log.fail("ERROR: unable to create the web directory: {}\n".format(
mysuite.webTopDir))
Expand All @@ -223,7 +234,8 @@ def load_params(args):

for sec in cp.sections():

if sec in ["main", "AMReX", "source"] or sec.startswith("extra-"): continue
if sec in ["main", "AMReX", "source"] or sec.startswith("extra-"):
continue

# maximum test name length -- used for HTML formatting
mysuite.lenTestName = max(mysuite.lenTestName, len(sec))
Expand Down Expand Up @@ -252,17 +264,17 @@ def load_params(args):
else:
# generic setting of the object attribute
setattr(mytest, opt, value)

elif aux_pat.match(opt):

mytest.auxFiles.append(value)

elif link_pat.match(opt):

mytest.linkFiles.append(value)

else:

mysuite.log.warn(f"unrecognized parameter {opt} for test {sec}")


Expand All @@ -284,7 +296,7 @@ def load_params(args):
invalid = 1

else:

input_file_invalid = mytest.inputFile == "" and not mytest.run_as_script
if mytest.buildDir == "" or input_file_invalid or mytest.dim == -1:
warn_msg = [f"required params for test {sec} not set",
Expand Down Expand Up @@ -329,7 +341,7 @@ def load_params(args):


# if any runs are parallel, make sure that the MPIcommand is defined
any_MPI = any([t.useMPI for t in test_list])
any_MPI = any(t.useMPI for t in test_list)

if any_MPI and mysuite.MPIcommand == "":
mysuite.log.fail("ERROR: some tests are MPI parallel, but MPIcommand not defined")
Expand Down
61 changes: 29 additions & 32 deletions regtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _check_safety(cs):

def check_realclean_safety(compile_strings):
split_strings = compile_strings.strip().split()
return all([_check_safety(cs) for cs in split_strings])
return all(_check_safety(cs) for cs in split_strings)

def find_build_dirs(tests):
""" given the list of test objects, find the set of UNIQUE build
Expand All @@ -48,15 +48,15 @@ def find_build_dirs(tests):
last_safe = False

for obj in tests:

# keep track of the build directory and which source tree it is
# in (e.g. the extra build dir)

# first find the list of unique build directories
dir_pair = (obj.buildDir, obj.extra_build_dir)
if build_dirs.count(dir_pair) == 0:
build_dirs.append(dir_pair)

# re-make all problems that specify an extra compile argument,
# and the test that comes after, just to make sure that any
# unique build commands are seen.
Expand All @@ -66,9 +66,9 @@ def find_build_dirs(tests):
obj.reClean = 0
else:
last_safe = True

return build_dirs

def cmake_setup(suite):
"Setup for cmake"

Expand Down Expand Up @@ -357,7 +357,7 @@ def test_suite(argv):
#--------------------------------------------------------------------------
# check bench dir and create output directories
#--------------------------------------------------------------------------
all_compile = all([t.compileTest == 1 for t in test_list])
all_compile = all(t.compileTest == 1 for t in test_list)

if not all_compile:
bench_dir = suite.get_bench_dir()
Expand All @@ -369,12 +369,11 @@ def test_suite(argv):

if suite.slack_post:
if args.note == "" and suite.repos["source"].pr_wanted is not None:
note = "testing PR-{}".format(suite.repos["source"].pr_wanted)
note = f"testing PR-{suite.repos["source"].pr_wanted}"
else:
note = args.note

msg = "> {} ({}) test suite started, id: {}\n> {}".format(
suite.suiteName, suite.sub_title, suite.test_dir, note)
msg = f"> {suite.suiteName} ({suite.sub_title}) test suite started, id: {suite.test_dir}\n> {note}"
suite.slack_post_it(msg)

if not args.copy_benchmarks is None:
Expand Down Expand Up @@ -591,7 +590,7 @@ def test_suite(argv):
needed_files.append((test.run_as_script, "copy"))

if test.inputFile:
suite.log.log("path to input file: {}".format(test.inputFile))
suite.log.log(f"path to input file: {test.inputFile}")
needed_files.append((test.inputFile, "copy"))
# strip out any sub-directory from the build dir
test.inputFile = os.path.basename(test.inputFile)
Expand Down Expand Up @@ -741,7 +740,7 @@ def test_suite(argv):

if test.customRunCmd is not None:
base_cmd = test.customRunCmd
base_cmd += " amr.restart={}".format(restart_file)
base_cmd += f" amr.restart={restart_file}"

if args.with_valgrind:
base_cmd = "valgrind " + args.valgrind_options + " " + base_cmd
Expand Down Expand Up @@ -780,7 +779,7 @@ def test_suite(argv):
# get the number of levels for reporting
if not test.run_as_script and "fboxinfo" in suite.tools:

prog = "{} -l {}".format(suite.tools["fboxinfo"], output_file)
prog = f"{suite.tools["fboxinfo"]} -l {output_file}"
stdout0, _, rc = test_util.run(prog)
test.nlevels = stdout0.rstrip('\n')
if not isinstance(params.convert_type(test.nlevels), int):
Expand Down Expand Up @@ -825,15 +824,15 @@ def test_suite(argv):

else:

command = "{} --abort_if_not_all_found -n 0".format(suite.tools["fcompare"])
command = f"{suite.tools["fcompare"]} --abort_if_not_all_found -n 0"

if test.tolerance is not None:
command += " --rel_tol {}".format(test.tolerance)
command += f" --rel_tol {test.tolerance}"

if test.abs_tolerance is not None:
command += " --abs_tol {}".format(test.abs_tolerance)
command += f" --abs_tol {test.abs_tolerance}"

command += " {} {}".format(bench_file, output_file)
command += f" {bench_file} {output_file}"

sout, _, ierr = test_util.run(command,
outfile=test.comparison_outfile,
Expand All @@ -859,15 +858,15 @@ def test_suite(argv):

if test.compareParticles:
for ptype in test.particleTypes.strip().split():
command = "{}".format(suite.tools["particle_compare"])
command = f"{suite.tools["particle_compare"]}"

if test.particle_tolerance is not None:
command += " --rel_tol {}".format(test.particle_tolerance)
command += f" --rel_tol {test.particle_tolerance}"

if test.particle_abs_tolerance is not None:
command += " --abs_tol {}".format(test.particle_abs_tolerance)
command += f" --abs_tol {test.particle_abs_tolerance}"

command += " {} {} {}".format(bench_file, output_file, ptype)
command += f" {bench_file} {output_file} {ptype}"

sout, _, ierr = test_util.run(command,
outfile=test.comparison_outfile, store_command=True)
Expand All @@ -892,11 +891,10 @@ def test_suite(argv):
suite.log.log("doing the diff...")
suite.log.log(f"diff dir: {test.diffDir}")

command = "diff {} -r {} {}".format(
test.diffOpts, diff_dir_bench, test.diffDir)
command = f"diff {test.diffOpts} -r {diff_dir_bench} {test.diffDir}"

outfile = test.comparison_outfile
sout, serr, diff_status = test_util.run(command, outfile=outfile, store_command=True)
sout, _, diff_status = test_util.run(command, outfile=outfile, store_command=True)

if diff_status == 0:
diff_successful = True
Expand Down Expand Up @@ -1134,24 +1132,23 @@ def test_suite(argv):
pass

if test.inputFile:
shutil.copy(test.inputFile, "{}/{}.{}".format(
suite.full_web_dir, test.name, test.inputFile))
shutil.copy(test.inputFile,
f"{suite.full_web_dir}/{test.name}.{test.inputFile}")

if test.has_jobinfo:
shutil.copy(job_info_file, "{}/{}.job_info".format(
suite.full_web_dir, test.name))
shutil.copy(job_info_file,
f"{suite.full_web_dir}/{test.name}")

if suite.sourceTree == "C_Src" and test.probinFile != "":
shutil.copy(test.probinFile, "{}/{}.{}".format(
suite.full_web_dir, test.name, test.probinFile))
shutil.copy(test.probinFile,
f"{suite.full_web_dir}/{test.name}.{test.probinFile}")

for af in test.auxFiles:

# strip out any sub-directory under build dir for the aux file
# when copying
shutil.copy(os.path.basename(af),
"{}/{}.{}".format(suite.full_web_dir,
test.name, os.path.basename(af)))
f"{suite.full_web_dir}/{test.name}.{os.path.basename(af)}")

if not test.png_file is None:
try:
Expand Down
Loading

0 comments on commit 391a28e

Please sign in to comment.