From 2820c4ae8b3e39b47b942eeb4e58ad1791a764ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Czech?= Date: Thu, 29 Feb 2024 21:11:23 +0100 Subject: [PATCH 1/2] Extend contest API allow for contest specific features on export. --- src/sinol_make/__init__.py | 1 - src/sinol_make/commands/export/__init__.py | 14 +++++++++++--- src/sinol_make/contest_types/default.py | 8 ++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/sinol_make/__init__.py b/src/sinol_make/__init__.py index 54254a4b..f3b3227f 100644 --- a/src/sinol_make/__init__.py +++ b/src/sinol_make/__init__.py @@ -1,7 +1,6 @@ # PYTHON_ARGCOMPLETE_OK import argparse import traceback -from time import sleep import argcomplete diff --git a/src/sinol_make/commands/export/__init__.py b/src/sinol_make/commands/export/__init__.py index 04405229..e8248006 100644 --- a/src/sinol_make/commands/export/__init__.py +++ b/src/sinol_make/commands/export/__init__.py @@ -5,7 +5,6 @@ import tarfile import tempfile import argparse -import yaml from sinol_make import util, contest_types from sinol_make.commands.ingen.ingen_util import get_ingen, compile_ingen, run_ingen, ingen_exists @@ -13,6 +12,7 @@ from sinol_make.interfaces.BaseCommand import BaseCommand from sinol_make.commands.outgen import Command as OutgenCommand, compile_correct_solution, get_correct_solution from sinol_make.commands.doc import Command as DocCommand +from sinol_make.interfaces.Errors import UnknownContestType class Command(BaseCommand): @@ -221,7 +221,7 @@ def compress(self, target_dir): :param target_dir: Target directory path. :return: Path to archive. """ - archive = os.path.join(os.getcwd(), f'{self.task_id}.tgz') + archive = os.path.join(os.getcwd(), f'{self.export_name}.tgz') with tarfile.open(archive, "w:gz") as tar: tar.add(target_dir, arcname=os.path.basename(target_dir)) return archive @@ -231,7 +231,12 @@ def run(self, args: argparse.Namespace): self.args = args self.task_id = package_util.get_task_id() + self.export_name = self.task_id package_util.validate_test_names(self.task_id) + try: + self.contest = contest_types.get_contest_type() + except UnknownContestType as e: + util.exit_with_error(str(e)) config = package_util.get_config() @@ -246,6 +251,9 @@ def run(self, args: argparse.Namespace): self.copy_package_required_files(export_package_path) self.clear_files(export_package_path) self.create_makefile_in(export_package_path, config) + export_name = self.contest.additional_export_job() + if export_name is not None: + self.export_name = export_name archive = self.compress(export_package_path) - print(util.info(f'Exported to {self.task_id}.tgz')) + print(util.info(f'Exported to {self.export_name}.tgz')) diff --git a/src/sinol_make/contest_types/default.py b/src/sinol_make/contest_types/default.py index 9655a626..e139a7c4 100644 --- a/src/sinol_make/contest_types/default.py +++ b/src/sinol_make/contest_types/default.py @@ -100,3 +100,11 @@ def get_global_score(self, groups_scores: Dict[int, Dict], global_max_score) -> :return: Global score """ return sum(group["points"] for group in groups_scores.values()) + + def additional_export_job(self): + """ + Called once during package export, just before compressing it to archive. + Allows for contest specific jobs before during package export. + :return: If not None, returned value will be used as name of the archive + """ + return None From 6b8f8f603b7bd8f3d948bfa47b4404f532eb2a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Czech?= Date: Sun, 3 Mar 2024 18:44:47 +0100 Subject: [PATCH 2/2] API for config verification --- src/sinol_make/contest_types/default.py | 6 ++++++ src/sinol_make/util.py | 8 +++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/sinol_make/contest_types/default.py b/src/sinol_make/contest_types/default.py index e139a7c4..afa38b99 100644 --- a/src/sinol_make/contest_types/default.py +++ b/src/sinol_make/contest_types/default.py @@ -100,6 +100,12 @@ def get_global_score(self, groups_scores: Dict[int, Dict], global_max_score) -> :return: Global score """ return sum(group["points"] for group in groups_scores.values()) + + def verify_config(self): + """ + Used for verifing contest specific config.yml settings + """ + pass def additional_export_job(self): """ diff --git a/src/sinol_make/util.py b/src/sinol_make/util.py index 15e36c05..df699de2 100644 --- a/src/sinol_make/util.py +++ b/src/sinol_make/util.py @@ -3,15 +3,11 @@ import multiprocessing import platform import tarfile -import tempfile -import shutil import hashlib -import subprocess import multiprocessing import resource from typing import Union -import sinol_make from sinol_make.contest_types import get_contest_type from sinol_make.helpers import paths, cache from sinol_make.structs.status_structs import Status @@ -56,7 +52,9 @@ def init_package_command(args): that require being in package directory """ exit_if_not_package() - return get_contest_type().argument_overrides(args) + contest = get_contest_type() + contest.verify_config() + return contest.argument_overrides(args) def exit_if_not_package():