mirror of
https://github.com/YosysHQ/sby.git
synced 2025-04-26 23:15:50 +00:00
Turn .format() strings into f-strings
This commit is contained in:
parent
1f6700f21d
commit
2d7d48885b
10 changed files with 219 additions and 172 deletions
|
@ -24,7 +24,7 @@ from time import localtime
|
|||
|
||||
class DictAction(argparse.Action):
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
assert isinstance(getattr(namespace, self.dest), dict), "Use ArgumentParser.set_defaults() to initialize {} to dict()".format(self.dest)
|
||||
assert isinstance(getattr(namespace, self.dest), dict), f"Use ArgumentParser.set_defaults() to initialize {self.dest} to dict()"
|
||||
name = option_string.lstrip(parser.prefix_chars).replace("-", "_")
|
||||
getattr(namespace, self.dest)[name] = values
|
||||
|
||||
|
@ -124,21 +124,21 @@ elif init_config_file is not None:
|
|||
sv_file = init_config_file + ".sv"
|
||||
sby_file = init_config_file + ".sby"
|
||||
with open(sby_file, 'w') as config:
|
||||
config.write("""[options]
|
||||
config.write(f"""[options]
|
||||
mode bmc
|
||||
|
||||
[engines]
|
||||
smtbmc
|
||||
|
||||
[script]
|
||||
read -formal {0}
|
||||
read -formal {sv_file}
|
||||
prep -top top
|
||||
|
||||
[files]
|
||||
{0}
|
||||
""".format(sv_file))
|
||||
{sv_file}
|
||||
""")
|
||||
|
||||
print("sby config written to {}".format(sby_file), file=sys.stderr)
|
||||
print(f"sby config written to {sby_file}", file=sys.stderr)
|
||||
sys.exit(0)
|
||||
|
||||
early_logmsgs = list()
|
||||
|
@ -220,7 +220,7 @@ def read_sbyconfig(sbydata, taskname):
|
|||
if len(task_tags_all) and not found_task_tag:
|
||||
tokens = line.split()
|
||||
if len(tokens) > 0 and tokens[0][0] == line[0] and tokens[0].endswith(":"):
|
||||
print("ERROR: Invalid task specifier \"{}\".".format(tokens[0]), file=sys.stderr)
|
||||
print(f"ERROR: Invalid task specifier \"{tokens[0]}\".", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if task_skip_line or task_skip_block:
|
||||
|
@ -263,7 +263,7 @@ def read_sbyconfig(sbydata, taskname):
|
|||
handle_line(line)
|
||||
|
||||
if taskname is not None and not task_matched:
|
||||
print("ERROR: Task name '{}' didn't match any lines in [tasks].".format(taskname), file=sys.stderr)
|
||||
print(f"ERROR: Task name '{taskname}' didn't match any lines in [tasks].", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
return cfgdata, tasklist
|
||||
|
@ -343,14 +343,14 @@ def run_job(taskname):
|
|||
shutil.move(my_workdir, "{}.bak{:03d}".format(my_workdir, backup_idx))
|
||||
|
||||
if opt_force and not reusedir:
|
||||
early_log(my_workdir, "Removing directory '{}'.".format(os.path.abspath(my_workdir)))
|
||||
early_log(my_workdir, f"Removing directory '{os.path.abspath(my_workdir)}'.")
|
||||
if sbyfile:
|
||||
shutil.rmtree(my_workdir, ignore_errors=True)
|
||||
|
||||
if reusedir:
|
||||
pass
|
||||
elif os.path.isdir(my_workdir):
|
||||
print("ERROR: Directory '{}' already exists.".format(my_workdir))
|
||||
print(f"ERROR: Directory '{my_workdir}' already exists.")
|
||||
sys.exit(1)
|
||||
else:
|
||||
os.makedirs(my_workdir)
|
||||
|
@ -388,13 +388,13 @@ def run_job(taskname):
|
|||
pass
|
||||
|
||||
if my_opt_tmpdir:
|
||||
job.log("Removing directory '{}'.".format(my_workdir))
|
||||
job.log(f"Removing directory '{my_workdir}'.")
|
||||
shutil.rmtree(my_workdir, ignore_errors=True)
|
||||
|
||||
if setupmode:
|
||||
job.log("SETUP COMPLETE (rc={})".format(job.retcode))
|
||||
job.log(f"SETUP COMPLETE (rc={job.retcode})")
|
||||
else:
|
||||
job.log("DONE ({}, rc={})".format(job.status, job.retcode))
|
||||
job.log(f"DONE ({job.status}, rc={job.retcode})")
|
||||
job.logfile.close()
|
||||
|
||||
if not my_opt_tmpdir and not setupmode:
|
||||
|
@ -402,23 +402,23 @@ def run_job(taskname):
|
|||
junit_errors = 1 if job.retcode == 16 else 0
|
||||
junit_failures = 1 if job.retcode != 0 and junit_errors == 0 else 0
|
||||
print('<?xml version="1.0" encoding="UTF-8"?>', file=f)
|
||||
print('<testsuites disabled="0" errors="{}" failures="{}" tests="1" time="{}">'.format(junit_errors, junit_failures, job.total_time), file=f)
|
||||
print('<testsuite disabled="0" errors="{}" failures="{}" name="{}" skipped="0" tests="1" time="{}">'.format(junit_errors, junit_failures, junit_ts_name, job.total_time), file=f)
|
||||
print(f'<testsuites disabled="0" errors="{junit_errors}" failures="{junit_failures}" tests="1" time="{job.total_time}">', file=f)
|
||||
print(f'<testsuite disabled="0" errors="{junit_errors}" failures="{junit_failures}" name="{junit_ts_name}" skipped="0" tests="1" time="{job.total_time}">', file=f)
|
||||
print('<properties>', file=f)
|
||||
print('<property name="os" value="{}"/>'.format(os.name), file=f)
|
||||
print(f'<property name="os" value="{os.name}"/>', file=f)
|
||||
print('</properties>', file=f)
|
||||
print('<testcase classname="{}" name="{}" status="{}" time="{}">'.format(junit_ts_name, junit_tc_name, job.status, job.total_time), file=f)
|
||||
print(f'<testcase classname="{junit_ts_name}" name="{junit_tc_name}" status="{job.status}" time="{job.total_time}">', file=f)
|
||||
if junit_errors:
|
||||
print('<error message="{}" type="{}"/>'.format(job.status, job.status), file=f)
|
||||
print(f'<error message="{job.status}" type="{job.status}"/>', file=f)
|
||||
if junit_failures:
|
||||
print('<failure message="{}" type="{}"/>'.format(job.status, job.status), file=f)
|
||||
print(f'<failure message="{job.status}" type="{job.status}"/>', file=f)
|
||||
print('<system-out>', end="", file=f)
|
||||
with open("{}/logfile.txt".format(job.workdir), "r") as logf:
|
||||
with open(f"{job.workdir}/logfile.txt", "r") as logf:
|
||||
for line in logf:
|
||||
print(line.replace("&", "&").replace("<", "<").replace(">", ">").replace("\"", """), end="", file=f)
|
||||
print('</system-out></testcase></testsuite></testsuites>', file=f)
|
||||
with open("{}/status".format(job.workdir), "w") as f:
|
||||
print("{} {} {}".format(job.status, job.retcode, job.total_time), file=f)
|
||||
with open(f"{job.workdir}/status", "w") as f:
|
||||
print(f"{job.status} {job.retcode} {job.total_time}", file=f)
|
||||
|
||||
return job.retcode
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue