Skip to content

Commit

Permalink
Add contest specific arguments (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
adespawn authored Feb 21, 2024
1 parent 259f7dc commit f8abf6f
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/sinol_make/commands/doc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def configure_subparser(self, subparser: argparse.ArgumentParser):
parser.add_argument('files', type=str, nargs='*', help='files to compile')

def run(self, args: argparse.Namespace):
util.exit_if_not_package()
args = util.init_package_command(args)

if args.files == []:
self.files = glob.glob(os.path.join(os.getcwd(), 'doc', '*.tex'))
Expand Down
6 changes: 4 additions & 2 deletions src/sinol_make/commands/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def configure_subparser(self, subparser: argparse.ArgumentParser):
default=util.default_cpu_count())
parser.add_argument('--no-statement', dest='no_statement', action='store_true',
help='allow export without statement')
parser.add_argument('--export-ocen', dest='export_ocen', action='store_true',
help='Create ocen archive')
parsers.add_compilation_arguments(parser)

def generate_input_tests(self):
Expand Down Expand Up @@ -165,7 +167,7 @@ def copy_package_required_files(self, target_dir: str):
shutil.copy(test[1], os.path.join(cache_test_dir, test[0], os.path.basename(test[1])))

self.generate_output_files()
if isinstance(contest_types.get_contest_type(), contest_types.OIContest):
if self.args.export_ocen:
print('Generating ocen archive...')
self.create_ocen(target_dir)

Expand Down Expand Up @@ -225,7 +227,7 @@ def compress(self, target_dir):
return archive

def run(self, args: argparse.Namespace):
util.exit_if_not_package()
args = util.init_package_command(args)

self.args = args
self.task_id = package_util.get_task_id()
Expand Down
2 changes: 1 addition & 1 deletion src/sinol_make/commands/gen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def configure_subparser(self, subparser):
parsers.add_compilation_arguments(parser)

def run(self, args: argparse.Namespace):
util.exit_if_not_package()
args = util.init_package_command(args)

self.args = args
self.ins = args.only_inputs
Expand Down
2 changes: 1 addition & 1 deletion src/sinol_make/commands/ingen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def configure_subparser(self, subparser):
parsers.add_compilation_arguments(parser)

def run(self, args: argparse.Namespace):
util.exit_if_not_package()
args = util.init_package_command(args)

self.args = args

Expand Down
2 changes: 1 addition & 1 deletion src/sinol_make/commands/inwer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def compare_id(test1, test2):
last_test = test

def run(self, args: argparse.Namespace):
util.exit_if_not_package()
args = util.init_package_command(args)

self.task_id = package_util.get_task_id()
package_util.validate_test_names(self.task_id)
Expand Down
2 changes: 1 addition & 1 deletion src/sinol_make/commands/outgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def calculate_md5_sums(self, tests=None):
return md5_sums, outputs_to_generate

def run(self, args: argparse.Namespace):
util.exit_if_not_package()
args = util.init_package_command(args)

self.args = args
self.task_id = package_util.get_task_id()
Expand Down
2 changes: 1 addition & 1 deletion src/sinol_make/commands/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ def compile_checker(self):
util.exit_with_error('Checker compilation failed.')

def run(self, args):
util.exit_if_not_package()
args = util.init_package_command(args)

self.set_constants()
package_util.validate_test_names(self.ID)
Expand Down
7 changes: 7 additions & 0 deletions src/sinol_make/contest_types/default.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
from math import ceil
from typing import List, Dict

Expand All @@ -15,6 +16,12 @@ class DefaultContest:
Max possible score is sum of group scores.
"""

def argument_overrides(self, args: argparse.Namespace) -> argparse.Namespace:
"""
Add contest specific arguments
"""
return args

def assign_scores(self, groups: List[int]) -> Dict[int, int]:
"""
Returns dictionary with scores for each group.
Expand Down
9 changes: 9 additions & 0 deletions src/sinol_make/contest_types/oi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import argparse

from sinol_make.structs.status_structs import ExecutionResult
from sinol_make.contest_types.default import DefaultContest

Expand All @@ -7,6 +9,13 @@ class OIContest(DefaultContest):
Contest type for Polish Olympiad in Informatics.
"""

def argument_overrides(self, args: argparse.Namespace) -> argparse.Namespace:
"""
Add arguments for features required by OI contest
"""
args.export_ocen = True
return args

def get_test_score(self, result: ExecutionResult, time_limit, memory_limit):
"""
Full score if took less than half of limit, otherwise linearly decreasing to 1.
Expand Down
9 changes: 9 additions & 0 deletions src/sinol_make/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ def find_and_chdir_package():
return False


def init_package_command(args):
"""
Updates arguments with contest specific overrides for commands
that require being in package directory
"""
exit_if_not_package()
return get_contest_type().argument_overrides(args)


def exit_if_not_package():
"""
Checks if current directory or parent directory is a package directory.
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/export/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def _create_package(tmpdir, path):
command.args = argparse.Namespace(cpus=1, weak_compilation_flags=False,
cpp_compiler_path=compiler.get_cpp_compiler_path(),
c_compiler_path=None, python_interpreter_path=None,
java_compiler_path=None)
java_compiler_path=None, export_ocen=False)
return command


Expand Down

0 comments on commit f8abf6f

Please sign in to comment.