Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend contest API #202

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/sinol_make/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# PYTHON_ARGCOMPLETE_OK
import argparse
import traceback
from time import sleep

import argcomplete

Expand Down
14 changes: 11 additions & 3 deletions src/sinol_make/commands/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
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
from sinol_make.helpers import package_util, parsers, paths
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):
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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'))
14 changes: 14 additions & 0 deletions src/sinol_make/contest_types/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,17 @@ 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):
"""
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
8 changes: 3 additions & 5 deletions src/sinol_make/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down
Loading