Skip to content

Commit 359fe2c

Browse files
committed
Execute format on existing code
1 parent 1a78199 commit 359fe2c

File tree

6 files changed

+173
-141
lines changed

6 files changed

+173
-141
lines changed

sbysrc/sby.py

+51-56
Original file line numberDiff line numberDiff line change
@@ -24,59 +24,44 @@
2424

2525
class DictAction(argparse.Action):
2626
def __call__(self, parser, namespace, values, option_string=None):
27-
assert isinstance(getattr(namespace, self.dest), dict), "Use ArgumentParser.set_defaults() to initialize {} to dict()".format(self.dest)
27+
assert isinstance(getattr(namespace, self.dest),
28+
dict), "Use ArgumentParser.set_defaults() to initialize {} to dict()".format(self.dest)
2829
name = option_string.lstrip(parser.prefix_chars).replace("-", "_")
2930
getattr(namespace, self.dest)[name] = values
3031

31-
parser = argparse.ArgumentParser(prog="sby",
32-
usage="%(prog)s [options] [<jobname>.sby [tasknames] | <dirname>]")
32+
parser = argparse.ArgumentParser(prog="sby", usage="%(prog)s [options] [<jobname>.sby [tasknames] | <dirname>]")
3333
parser.set_defaults(exe_paths=dict())
3434

3535
parser.add_argument("-d", metavar="<dirname>", dest="workdir",
36-
help="set workdir name. default: <jobname> or <jobname>_<taskname>")
37-
parser.add_argument("-f", action="store_true", dest="force",
38-
help="remove workdir if it already exists")
39-
parser.add_argument("-b", action="store_true", dest="backup",
40-
help="backup workdir if it already exists")
41-
parser.add_argument("-t", action="store_true", dest="tmpdir",
42-
help="run in a temporary workdir (remove when finished)")
36+
help="set workdir name. default: <jobname> or <jobname>_<taskname>")
37+
parser.add_argument("-f", action="store_true", dest="force", help="remove workdir if it already exists")
38+
parser.add_argument("-b", action="store_true", dest="backup", help="backup workdir if it already exists")
39+
parser.add_argument("-t", action="store_true", dest="tmpdir", help="run in a temporary workdir (remove when finished)")
4340
parser.add_argument("-T", metavar="<taskname>", action="append", dest="tasknames", default=list(),
44-
help="add taskname (useful when sby file is read from stdin)")
41+
help="add taskname (useful when sby file is read from stdin)")
4542
parser.add_argument("-E", action="store_true", dest="throw_err",
46-
help="throw an exception (incl stack trace) for most errors")
47-
48-
parser.add_argument("--yosys", metavar="<path_to_executable>",
49-
action=DictAction, dest="exe_paths")
50-
parser.add_argument("--abc", metavar="<path_to_executable>",
51-
action=DictAction, dest="exe_paths")
52-
parser.add_argument("--smtbmc", metavar="<path_to_executable>",
53-
action=DictAction, dest="exe_paths")
54-
parser.add_argument("--suprove", metavar="<path_to_executable>",
55-
action=DictAction, dest="exe_paths")
56-
parser.add_argument("--aigbmc", metavar="<path_to_executable>",
57-
action=DictAction, dest="exe_paths")
58-
parser.add_argument("--avy", metavar="<path_to_executable>",
59-
action=DictAction, dest="exe_paths")
60-
parser.add_argument("--btormc", metavar="<path_to_executable>",
61-
action=DictAction, dest="exe_paths")
62-
parser.add_argument("--pono", metavar="<path_to_executable>",
63-
action=DictAction, dest="exe_paths",
64-
help="configure which executable to use for the respective tool")
43+
help="throw an exception (incl stack trace) for most errors")
44+
45+
parser.add_argument("--yosys", metavar="<path_to_executable>", action=DictAction, dest="exe_paths")
46+
parser.add_argument("--abc", metavar="<path_to_executable>", action=DictAction, dest="exe_paths")
47+
parser.add_argument("--smtbmc", metavar="<path_to_executable>", action=DictAction, dest="exe_paths")
48+
parser.add_argument("--suprove", metavar="<path_to_executable>", action=DictAction, dest="exe_paths")
49+
parser.add_argument("--aigbmc", metavar="<path_to_executable>", action=DictAction, dest="exe_paths")
50+
parser.add_argument("--avy", metavar="<path_to_executable>", action=DictAction, dest="exe_paths")
51+
parser.add_argument("--btormc", metavar="<path_to_executable>", action=DictAction, dest="exe_paths")
52+
parser.add_argument("--pono", metavar="<path_to_executable>", action=DictAction, dest="exe_paths",
53+
help="configure which executable to use for the respective tool")
6554
parser.add_argument("--dumpcfg", action="store_true", dest="dump_cfg",
66-
help="print the pre-processed configuration file")
67-
parser.add_argument("--dumptasks", action="store_true", dest="dump_tasks",
68-
help="print the list of tasks")
69-
parser.add_argument("--dumpfiles", action="store_true", dest="dump_files",
70-
help="print the list of source files")
71-
parser.add_argument("--setup", action="store_true", dest="setupmode",
72-
help="set up the working directory and exit")
73-
74-
parser.add_argument("--init-config-file", dest="init_config_file",
75-
help="create a default .sby config file")
55+
help="print the pre-processed configuration file")
56+
parser.add_argument("--dumptasks", action="store_true", dest="dump_tasks", help="print the list of tasks")
57+
parser.add_argument("--dumpfiles", action="store_true", dest="dump_files", help="print the list of source files")
58+
parser.add_argument("--setup", action="store_true", dest="setupmode", help="set up the working directory and exit")
59+
60+
parser.add_argument("--init-config-file", dest="init_config_file", help="create a default .sby config file")
7661
parser.add_argument("sbyfile", metavar="<jobname>.sby | <dirname>", nargs="?",
77-
help=".sby file OR directory containing config.sby file")
62+
help=".sby file OR directory containing config.sby file")
7863
parser.add_argument("arg_tasknames", metavar="tasknames", nargs="*",
79-
help="tasks to run (only valid when <jobname>.sby is used)")
64+
help="tasks to run (only valid when <jobname>.sby is used)")
8065

8166
args = parser.parse_args()
8267

@@ -198,11 +183,11 @@ def handle_line(line):
198183
task_skip_line = False
199184

200185
for t in task_tags_all:
201-
if line.startswith(t+":"):
202-
line = line[len(t)+1:].lstrip()
186+
if line.startswith(t + ":"):
187+
line = line[len(t) + 1:].lstrip()
203188
match = t in task_tags_active
204-
elif line.startswith("~"+t+":"):
205-
line = line[len(t)+2:].lstrip()
189+
elif line.startswith("~" + t + ":"):
190+
line = line[len(t) + 2:].lstrip()
206191
match = t not in task_tags_active
207192
else:
208193
continue
@@ -268,7 +253,6 @@ def handle_line(line):
268253

269254
return cfgdata, tasklist
270255

271-
272256
sbydata = list()
273257
with (open(sbyfile, "r") if sbyfile is not None else sys.stdin) as f:
274258
for line in f:
@@ -295,7 +279,7 @@ def find_files(taskname):
295279
if start_index == -1:
296280
return
297281

298-
for line in sbyconfig[start_index+1:]:
282+
for line in sbyconfig[start_index + 1:]:
299283
line = line.strip()
300284
if line.startswith("["):
301285
break
@@ -341,7 +325,9 @@ def run_job(taskname):
341325
backup_idx = 0
342326
while os.path.exists("{}.bak{:03d}".format(my_workdir, backup_idx)):
343327
backup_idx += 1
344-
early_log(my_workdir, "Moving directory '{}' to '{}'.".format(my_workdir, "{}.bak{:03d}".format(my_workdir, backup_idx)))
328+
early_log(
329+
my_workdir, "Moving directory '{}' to '{}'.".format(my_workdir,
330+
"{}.bak{:03d}".format(my_workdir, backup_idx)))
345331
shutil.move(my_workdir, "{}.bak{:03d}".format(my_workdir, backup_idx))
346332

347333
if opt_force and not reusedir:
@@ -361,7 +347,8 @@ def run_job(taskname):
361347
my_opt_tmpdir = True
362348
my_workdir = tempfile.mkdtemp()
363349

364-
junit_ts_name = os.path.basename(sbyfile[:-4]) if sbyfile is not None else workdir if workdir is not None else "stdin"
350+
junit_ts_name = os.path.basename(
351+
sbyfile[:-4]) if sbyfile is not None else workdir if workdir is not None else "stdin"
365352
junit_tc_name = taskname if taskname is not None else "default"
366353

367354
if reusedir:
@@ -404,33 +391,41 @@ def run_job(taskname):
404391
junit_errors = 1 if job.retcode == 16 else 0
405392
junit_failures = 1 if job.retcode != 0 and junit_errors == 0 else 0
406393
print('<?xml version="1.0" encoding="UTF-8"?>', file=f)
407-
print('<testsuites disabled="0" errors="{}" failures="{}" tests="1" time="{}">'.format(junit_errors, junit_failures, job.total_time), file=f)
408-
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)
394+
print(
395+
'<testsuites disabled="0" errors="{}" failures="{}" tests="1" time="{}">'.format(
396+
junit_errors, junit_failures, job.total_time), file=f)
397+
print(
398+
'<testsuite disabled="0" errors="{}" failures="{}" name="{}" skipped="0" tests="1" time="{}">'.format(
399+
junit_errors, junit_failures, junit_ts_name, job.total_time), file=f)
409400
print('<properties>', file=f)
410401
print('<property name="os" value="{}"/>'.format(os.name), file=f)
411402
print('</properties>', file=f)
412-
print('<testcase classname="{}" name="{}" status="{}" time="{}">'.format(junit_ts_name, junit_tc_name, job.status, job.total_time), file=f)
403+
print(
404+
'<testcase classname="{}" name="{}" status="{}" time="{}">'.format(junit_ts_name, junit_tc_name,
405+
job.status, job.total_time), file=f)
413406
if junit_errors:
414407
print('<error message="{}" type="{}"/>'.format(job.status, job.status), file=f)
415408
if junit_failures:
416409
print('<failure message="{}" type="{}"/>'.format(job.status, job.status), file=f)
417410
print('<system-out>', end="", file=f)
418411
with open("{}/logfile.txt".format(job.workdir), "r") as logf:
419412
for line in logf:
420-
print(line.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;"), end="", file=f)
413+
print(
414+
line.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;"),
415+
end="", file=f)
421416
print('</system-out></testcase></testsuite></testsuites>', file=f)
422417
with open("{}/status".format(job.workdir), "w") as f:
423418
print("{} {} {}".format(job.status, job.retcode, job.total_time), file=f)
424419

425420
return job.retcode
426421

427-
428422
retcode = 0
429423
for t in tasknames:
430424
retcode |= run_job(t)
431425

432426
if retcode and (len(tasknames) > 1 or tasknames[0] is not None):
433427
tm = localtime()
434-
print("SBY {:2d}:{:02d}:{:02d} One or more tasks produced a non-zero return code.".format(tm.tm_hour, tm.tm_min, tm.tm_sec))
428+
print("SBY {:2d}:{:02d}:{:02d} One or more tasks produced a non-zero return code.".format(
429+
tm.tm_hour, tm.tm_min, tm.tm_sec))
435430

436431
sys.exit(retcode)

sbysrc/sby_core.py

+45-30
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ def __init__(self, job, info, deps, cmdline, logfile=None, logstderr=True, silen
6060
# Windows command interpreter equivalents for sequential
6161
# commands (; => &) command grouping ({} => ()).
6262
replacements = {
63-
";" : "&",
64-
"{" : "(",
65-
"}" : ")",
63+
";": "&",
64+
"{": "(",
65+
"}": ")",
6666
}
6767

6868
cmdline_copy = cmdline
@@ -140,19 +140,21 @@ def poll(self):
140140
self.job.log("{}: starting process \"{}\"".format(self.info, self.cmdline))
141141

142142
if os.name == "posix":
143+
143144
def preexec_fn():
144145
signal.signal(signal.SIGINT, signal.SIG_IGN)
145146
os.setpgrp()
146147

147-
self.p = subprocess.Popen(["/usr/bin/env", "bash", "-c", self.cmdline], stdin=subprocess.DEVNULL, stdout=subprocess.PIPE,
148-
stderr=(subprocess.STDOUT if self.logstderr else None), preexec_fn=preexec_fn)
148+
self.p = subprocess.Popen(["/usr/bin/env", "bash", "-c", self.cmdline], stdin=subprocess.DEVNULL,
149+
stdout=subprocess.PIPE,
150+
stderr=(subprocess.STDOUT if self.logstderr else None), preexec_fn=preexec_fn)
149151

150152
fl = fcntl.fcntl(self.p.stdout, fcntl.F_GETFL)
151153
fcntl.fcntl(self.p.stdout, fcntl.F_SETFL, fl | os.O_NONBLOCK)
152154

153155
else:
154156
self.p = subprocess.Popen(self.cmdline, shell=True, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE,
155-
stderr=(subprocess.STDOUT if self.logstderr else None))
157+
stderr=(subprocess.STDOUT if self.logstderr else None))
156158

157159
self.job.tasks_pending.remove(self)
158160
self.job.tasks_running.append(self)
@@ -200,11 +202,9 @@ def preexec_fn():
200202
next_task.poll()
201203
return
202204

203-
204205
class SbyAbort(BaseException):
205206
pass
206207

207-
208208
class SbyJob:
209209
def __init__(self, sbyconfig, workdir, early_logs, reusedir):
210210
self.options = dict()
@@ -285,13 +285,19 @@ def taskloop(self):
285285

286286
def log(self, logmessage):
287287
tm = localtime()
288-
print("SBY {:2d}:{:02d}:{:02d} [{}] {}".format(tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage), flush=True)
289-
print("SBY {:2d}:{:02d}:{:02d} [{}] {}".format(tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage), file=self.logfile, flush=True)
288+
print("SBY {:2d}:{:02d}:{:02d} [{}] {}".format(tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage),
289+
flush=True)
290+
print("SBY {:2d}:{:02d}:{:02d} [{}] {}".format(tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage),
291+
file=self.logfile, flush=True)
290292

291293
def error(self, logmessage):
292294
tm = localtime()
293-
print("SBY {:2d}:{:02d}:{:02d} [{}] ERROR: {}".format(tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage), flush=True)
294-
print("SBY {:2d}:{:02d}:{:02d} [{}] ERROR: {}".format(tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage), file=self.logfile, flush=True)
295+
print(
296+
"SBY {:2d}:{:02d}:{:02d} [{}] ERROR: {}".format(tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage),
297+
flush=True)
298+
print(
299+
"SBY {:2d}:{:02d}:{:02d} [{}] ERROR: {}".format(tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage),
300+
file=self.logfile, flush=True)
295301
self.status = "ERROR"
296302
if "ERROR" not in self.expect:
297303
self.retcode = 16
@@ -385,9 +391,9 @@ def make_model(self, model_name):
385391
print("hierarchy -simcheck", file=f)
386392
print("write_ilang ../model/design{}.il".format("" if model_name == "base" else "_nomem"), file=f)
387393

388-
task = SbyTask(self, model_name, [],
389-
"cd {}/src; {} -ql ../model/design{s}.log ../model/design{s}.ys".format(self.workdir, self.exe_paths["yosys"],
390-
s="" if model_name == "base" else "_nomem"))
394+
task = SbyTask(
395+
self, model_name, [], "cd {}/src; {} -ql ../model/design{s}.log ../model/design{s}.ys".format(
396+
self.workdir, self.exe_paths["yosys"], s="" if model_name == "base" else "_nomem"))
391397
task.checkretcode = True
392398

393399
return [task]
@@ -410,8 +416,10 @@ def make_model(self, model_name):
410416
else:
411417
print("write_smt2 -wires design_{}.smt2".format(model_name), file=f)
412418

413-
task = SbyTask(self, model_name, self.model("nomem" if "_nomem" in model_name else "base"),
414-
"cd {}/model; {} -ql design_{s}.log design_{s}.ys".format(self.workdir, self.exe_paths["yosys"], s=model_name))
419+
task = SbyTask(
420+
self, model_name, self.model("nomem" if "_nomem" in model_name else "base"),
421+
"cd {}/model; {} -ql design_{s}.log design_{s}.ys".format(self.workdir, self.exe_paths["yosys"],
422+
s=model_name))
415423
task.checkretcode = True
416424

417425
return [task]
@@ -433,10 +441,14 @@ def make_model(self, model_name):
433441
print("delete -output", file=f)
434442
print("dffunmap", file=f)
435443
print("stat", file=f)
436-
print("write_btor {}-i design_{m}.info design_{m}.btor".format("-c " if self.opt_mode == "cover" else "", m=model_name), file=f)
437-
438-
task = SbyTask(self, model_name, self.model("nomem" if "_nomem" in model_name else "base"),
439-
"cd {}/model; {} -ql design_{s}.log design_{s}.ys".format(self.workdir, self.exe_paths["yosys"], s=model_name))
444+
print(
445+
"write_btor {}-i design_{m}.info design_{m}.btor".format("-c " if self.opt_mode == "cover" else "",
446+
m=model_name), file=f)
447+
448+
task = SbyTask(
449+
self, model_name, self.model("nomem" if "_nomem" in model_name else "base"),
450+
"cd {}/model; {} -ql design_{s}.log design_{s}.ys".format(self.workdir, self.exe_paths["yosys"],
451+
s=model_name))
440452
task.checkretcode = True
441453

442454
return [task]
@@ -458,8 +470,9 @@ def make_model(self, model_name):
458470
print("stat", file=f)
459471
print("write_aiger -I -B -zinit -map design_aiger.aim design_aiger.aig", file=f)
460472

461-
task = SbyTask(self, "aig", self.model("nomem"),
462-
"cd {}/model; {} -ql design_aiger.log design_aiger.ys".format(self.workdir, self.exe_paths["yosys"]))
473+
task = SbyTask(
474+
self, "aig", self.model("nomem"),
475+
"cd {}/model; {} -ql design_aiger.log design_aiger.ys".format(self.workdir, self.exe_paths["yosys"]))
463476
task.checkretcode = True
464477

465478
return [task]
@@ -668,16 +681,18 @@ def run(self, setupmode):
668681
self.total_time = total_process_time
669682

670683
self.summary = [
671-
"Elapsed clock time [H:MM:SS (secs)]: {}:{:02d}:{:02d} ({})".format
672-
(total_clock_time // (60*60), (total_clock_time // 60) % 60, total_clock_time % 60, total_clock_time),
673-
"Elapsed process time [H:MM:SS (secs)]: {}:{:02d}:{:02d} ({})".format
674-
(total_process_time // (60*60), (total_process_time // 60) % 60, total_process_time % 60, total_process_time),
684+
"Elapsed clock time [H:MM:SS (secs)]: {}:{:02d}:{:02d} ({})".format(
685+
total_clock_time // (60 * 60),
686+
(total_clock_time // 60) % 60, total_clock_time % 60, total_clock_time),
687+
"Elapsed process time [H:MM:SS (secs)]: {}:{:02d}:{:02d} ({})".format(
688+
total_process_time // (60 * 60),
689+
(total_process_time // 60) % 60, total_process_time % 60, total_process_time),
675690
] + self.summary
676691
else:
677692
self.summary = [
678-
"Elapsed clock time [H:MM:SS (secs)]: {}:{:02d}:{:02d} ({})".format
679-
(total_clock_time // (60*60), (total_clock_time // 60) % 60, total_clock_time % 60, total_clock_time),
680-
"Elapsed process time unvailable on Windows"
693+
"Elapsed clock time [H:MM:SS (secs)]: {}:{:02d}:{:02d} ({})".format(
694+
total_clock_time // (60 * 60), (total_clock_time // 60) % 60, total_clock_time % 60,
695+
total_clock_time), "Elapsed process time unvailable on Windows"
681696
] + self.summary
682697

683698
for line in self.summary:

0 commit comments

Comments
 (0)