chore: better code style
All checks were successful
build / build (push) Successful in 2m23s
build / build (pull_request) Successful in 2m21s

This commit is contained in:
张泊明518370910136 2025-03-02 15:33:44 -05:00
parent 8baca08696
commit 0c2baf67bd
GPG Key ID: D47306D7062CDA9D
3 changed files with 103 additions and 117 deletions

View File

@ -10,7 +10,7 @@ def get_conf_stage(
task_stage: task.Stage, executor_with_config: result.ExecutorWith task_stage: task.Stage, executor_with_config: result.ExecutorWith
) -> result.StageDetail: ) -> result.StageDetail:
conf_stage = result.StageDetail( conf_stage = result.StageDetail(
name=task_stage.name if task_stage.name is not None else "", name=task_stage.name,
# group is determined by adding between "[]" in the name of the task # group is determined by adding between "[]" in the name of the task
# FIXME: this is probably outdated # FIXME: this is probably outdated
group=( group=(
@ -27,8 +27,6 @@ def get_conf_stage(
result.ParserConfig(name=parser, with_={}) result.ParserConfig(name=parser, with_={})
for parser in task_stage.parsers for parser in task_stage.parsers
] ]
if task_stage.parsers is not None
else []
), ),
) )
return conf_stage return conf_stage
@ -43,11 +41,7 @@ def get_executor_with_config(
copy_out_files = ["stdout", "stderr"] copy_out_files = ["stdout", "stderr"]
executor_with_config = result.ExecutorWith( executor_with_config = result.ExecutorWith(
default=result.Cmd( default=result.Cmd(
args=( args=shlex.split(task_stage.command),
shlex.split(task_stage.command)
if task_stage.command is not None
else []
),
copy_in={ copy_in={
file: result.LocalFile(src=str(JOJ3_CONFIG_ROOT / file)) file: result.LocalFile(src=str(JOJ3_CONFIG_ROOT / file))
# all copyin files store in this tools folder # all copyin files store in this tools folder
@ -56,7 +50,7 @@ def get_executor_with_config(
}, },
copy_out=copy_out_files, copy_out=copy_out_files,
copy_in_cached={file: file for file in cached}, copy_in_cached={file: file for file in cached},
copy_out_cached=file_export or [], copy_out_cached=file_export,
cpu_limit=task_stage.limit.cpu, cpu_limit=task_stage.limit.cpu,
clock_limit=2 * task_stage.limit.cpu, clock_limit=2 * task_stage.limit.cpu,
memory_limit=task_stage.limit.mem, memory_limit=task_stage.limit.mem,
@ -65,7 +59,6 @@ def get_executor_with_config(
), ),
cases=[], cases=[],
) )
if file_export is not None:
for file in file_export: for file in file_export:
if file not in cached: if file not in cached:
cached.append(file) cached.append(file)
@ -76,7 +69,7 @@ def fix_keyword(
task_stage: task.Stage, conf_stage: result.StageDetail task_stage: task.Stage, conf_stage: result.StageDetail
) -> result.StageDetail: ) -> result.StageDetail:
keyword_parser = ["clangtidy", "keyword", "cppcheck", "cpplint"] keyword_parser = ["clangtidy", "keyword", "cppcheck", "cpplint"]
for parser in task_stage.parsers or []: for parser in task_stage.parsers:
if parser in keyword_parser: if parser in keyword_parser:
keyword_parser_ = next(p for p in conf_stage.parsers if p.name == parser) keyword_parser_ = next(p for p in conf_stage.parsers if p.name == parser)
keyword_weight = [] keyword_weight = []
@ -107,11 +100,11 @@ def fix_keyword(
def fix_result_detail( def fix_result_detail(
task_stage: task.Stage, conf_stage: result.StageDetail task_stage: task.Stage, conf_stage: result.StageDetail
) -> result.StageDetail: ) -> result.StageDetail:
if (task_stage.parsers is not None) and ("result-detail" in task_stage.parsers): if "result-detail" not in task_stage.parsers:
return conf_stage
result_detail_parser = next( result_detail_parser = next(
p for p in conf_stage.parsers if p.name == "result-detail" p for p in conf_stage.parsers if p.name == "result-detail"
) )
if task_stage.result_detail is not None:
show_files = [] show_files = []
if task_stage.result_detail.stdout: if task_stage.result_detail.stdout:
show_files.append("stdout") show_files.append("stdout")
@ -138,7 +131,6 @@ def fix_dummy(
"dummy", "dummy",
"result-status", "result-status",
] ]
if task_stage.parsers is not None:
for parser in task_stage.parsers: for parser in task_stage.parsers:
if parser not in dummy_parser: if parser not in dummy_parser:
continue continue
@ -161,14 +153,11 @@ def fix_file(
task_stage: task.Stage, conf_stage: result.StageDetail task_stage: task.Stage, conf_stage: result.StageDetail
) -> result.StageDetail: ) -> result.StageDetail:
file_parser = ["file"] file_parser = ["file"]
if task_stage.parsers is not None:
for parser in task_stage.parsers: for parser in task_stage.parsers:
if parser in file_parser: if parser not in file_parser:
file_parser_ = next(p for p in conf_stage.parsers if p.name == parser)
if task_stage.file is not None:
file_parser_.with_.update({"name": task_stage.file.name})
else:
continue continue
file_parser_ = next(p for p in conf_stage.parsers if p.name == parser)
file_parser_.with_.update({"name": task_stage.file.name})
return conf_stage return conf_stage
@ -177,10 +166,11 @@ def fix_diff(
conf_stage: result.StageDetail, conf_stage: result.StageDetail,
task_conf: task.Config, task_conf: task.Config,
) -> result.StageDetail: ) -> result.StageDetail:
if task_stage.parsers is not None and "diff" in task_stage.parsers: if "diff" not in task_stage.parsers:
return conf_stage
diff_parser = next((p for p in conf_stage.parsers if p.name == "diff"), None) diff_parser = next((p for p in conf_stage.parsers if p.name == "diff"), None)
skip = task_stage.skip or [] skip = task_stage.skip
cases = task_stage.cases or {} cases = task_stage.cases
finalized_cases = [case for case in cases if case not in skip] finalized_cases = [case for case in cases if case not in skip]
stage_cases = [] stage_cases = []
@ -194,7 +184,7 @@ def fix_diff(
cpu_limit = case_stage.limit.cpu cpu_limit = case_stage.limit.cpu
clock_limit = 2 * case_stage.limit.cpu clock_limit = 2 * case_stage.limit.cpu
memory_limit = case_stage.limit.mem memory_limit = case_stage.limit.mem
command = case_stage.command if case_stage.command is not None else None command = case_stage.command
stdin = case_stage.in_ if case_stage.in_ != "" else f"{case}.in" stdin = case_stage.in_ if case_stage.in_ != "" else f"{case}.in"
stdout = case_stage.out_ if case_stage.out_ != "" else f"{case}.out" stdout = case_stage.out_ if case_stage.out_ != "" else f"{case}.out"
@ -203,7 +193,7 @@ def fix_diff(
stdin=result.LocalFile( stdin=result.LocalFile(
src=str(JOJ3_CONFIG_ROOT / task_conf.task.type_ / stdin), src=str(JOJ3_CONFIG_ROOT / task_conf.task.type_ / stdin),
), ),
args=(shlex.split(command) if command is not None else None), args=shlex.split(command) if command else None,
cpu_limit=cpu_limit, cpu_limit=cpu_limit,
clock_limit=clock_limit, clock_limit=clock_limit,
memory_limit=memory_limit, memory_limit=memory_limit,
@ -235,7 +225,7 @@ def fix_diff(
} }
) )
if diff_parser and task_stage.diff is not None: if diff_parser:
diff_parser.with_.update({"name": "diff", "cases": parser_cases}) diff_parser.with_.update({"name": "diff", "cases": parser_cases})
conf_stage.executor.with_.cases = stage_cases conf_stage.executor.with_.cases = stage_cases

View File

@ -660,7 +660,6 @@
}, },
"cases": [ "cases": [
{ {
"args": [],
"stdin": { "stdin": {
"src": "/home/tt/.config/joj/homework/h7/e2/case0.in" "src": "/home/tt/.config/joj/homework/h7/e2/case0.in"
}, },
@ -670,7 +669,6 @@
"procLimit": 50 "procLimit": 50
}, },
{ {
"args": [],
"stdin": { "stdin": {
"src": "/home/tt/.config/joj/homework/h7/e2/case1.in" "src": "/home/tt/.config/joj/homework/h7/e2/case1.in"
}, },

View File

@ -63,7 +63,6 @@
}, },
"cases": [ "cases": [
{ {
"args": [],
"stdin": { "stdin": {
"src": "/home/tt/.config/joj/homework/h7/e2/case0.in" "src": "/home/tt/.config/joj/homework/h7/e2/case0.in"
}, },
@ -73,7 +72,6 @@
"procLimit": 50 "procLimit": 50
}, },
{ {
"args": [],
"stdin": { "stdin": {
"src": "/home/tt/.config/joj/homework/h7/e2/case1.in" "src": "/home/tt/.config/joj/homework/h7/e2/case1.in"
}, },