sio3pack.packages.sinolpack

Package Contents

class sio3pack.packages.sinolpack.Sinolpack[source]

Bases: sio3pack.packages.package.Package

Represents a OIOIOI’s standard problem package.

Parameters:
  • short_name (str) – Short name of the problem.

  • full_name (str) – Full name of the problem.

  • lang_titles (dict[str, str]) – A dictionary of problem titles, where keys are language codes and values are titles.

  • lang_statements (dict[str, File]) – A dictionary of problem statements, where keys are language codes and values are files.

  • config (dict[str, Any]) – Configuration of the problem.

  • model_solutions (list[dict[str, Any]]) – A list of model solutions, where each element is a dict containing a model solution kind and a file.

  • additional_files (list[File]) – A list of additional files for the problem.

  • extra_files (dict[str, File]) – A dictionary of extra files as specified in the config.yml file, where keys are file paths and values are sio3pack.files.File objects.

  • attachments (list[File]) – A list of attachments related to the problem.

  • workflow_manager (SinolpackWorkflowManager) – A workflow manager for the problem.

  • main_model_solution (File | None) – The main model solution file.

  • special_files (dict[str, File | None]) – A dictionary of special files, where keys are file names and values are booleans indicating whether the file exists or not.

  • tests (list[Test]) – A list of tests, where each element is a sio3pack.Test object.

  • is_from_db (bool) – A flag indicating whether the package is loaded from the database or not.

  • workflow_manager – A workflow manager for the problem.

classmethod identify(file)[source]

Identifies whether file is a Sinolpack.

Parameters:

file (sio3pack.files.LocalFile) – File with package.

Returns:

True when file is a Sinolpack, otherwise False.

Return type:

bool

classmethod identify_db(problem_id)[source]

Identifies whether problem is a Sinolpack.

Parameters:

problem_id (int) – ID of the problem.

Returns:

True when problem is a Sinolpack, otherwise False.

Return type:

bool

get_doc_dir()[source]

Returns the path to the directory containing the problem’s documents.

Return type:

str

get_in_doc_dir(filename)[source]

Returns the path to the input file in the documents’ directory.

Parameters:

filename (str)

Return type:

sio3pack.files.File

get_in_root(filename)[source]

Returns the path to the input file in the root directory.

Parameters:

filename (str)

Return type:

sio3pack.files.File

get_prog_dir()[source]

Returns the path to the directory containing the problem’s program files.

Return type:

str

get_in_prog_dir(filename)[source]

Returns the path to the input file in the program directory.

Parameters:

filename (str)

Return type:

sio3pack.files.LocalFile

get_attachments_dir()[source]

Returns the path to the directory containing the problem’s attachments.

Return type:

str

reload_config()[source]

Process the config.yml file again in case it was modified.

get_title(lang=None)[source]

Returns the problem title for a given language code.

Parameters:

lang (str | None)

Return type:

str

get_submittable_extensions()[source]

Returns a list of extensions that are submittable.

get_model_solution_regex()[source]

Returns the regex used to determine model solutions.

main_model_solution_regex()[source]

Returns the regex used to determine main model solution.

sort_model_solutions(model_solutions)[source]

Sorts model solutions by kind.

Parameters:

model_solutions (list[dict[str, Any]])

Return type:

list[dict[str, Any]]

special_file_types()[source]

Returns the list of special file types.

Return type:

list[str]

get_extra_file(package_path)[source]

Returns the extra file with the given package path.

Parameters:

package_path (str) – The path to the extra file in the package.

Returns:

The extra file if it exists, otherwise None.

Return type:

sio3pack.files.File | None

get_statement(lang=None)[source]

Returns the problem statement for a given language code.

Parameters:

lang (str | None)

Return type:

sio3pack.files.File | None

match_test_regex(filename)[source]

Returns match object if the filename matches the test regex.

Parameters:

filename (str)

Return type:

re.Match | None

get_test_id_from_filename(filename)[source]

Returns the test ID from the filename.

Parameters:

filename (str)

Return type:

str

get_group_from_filename(filename)[source]

Returns the group from the filename.

Parameters:

filename (str)

Return type:

str

reload_tests()[source]

Updates self.tests variable with existing tests.

get_input_tests()[source]

Returns the list of tests with input files.

Return type:

list[sio3pack.test.Test]

get_test(test_id)[source]

Returns the test with the given ID.

Parameters:

test_id (str)

Return type:

sio3pack.test.Test

get_tests_with_inputs(tests=None)[source]

Returns the list of input tests.

Parameters:

tests (list[sio3pack.test.Test])

Return type:

list[sio3pack.test.Test]

get_corresponding_out_filename(in_test)[source]

Returns the corresponding output test for the given input test.

Parameters:

in_test (str)

Return type:

str

get_outgen_path()[source]
Return type:

str | None

get_ingen_path()[source]
Return type:

str | None

get_inwer_path()[source]
Return type:

str | None

get_checker_file()[source]

Returns the checker file.

Return type:

sio3pack.files.File | None

get_checker_path()[source]
Return type:

str | None

get_unpack_operation(return_func=None)[source]
Parameters:

return_func (callable)

Return type:

sio3pack.workflow.WorkflowOperation | None

save_to_db(problem_id)[source]

Save the package to the database. If sio3pack isn’t installed with Django support, it should raise an ImproperlyConfigured exception.

Parameters:

problem_id (int)

get_extra_execution_files()[source]

Returns the list of extra execution files specified in the config.yml file. If no such files are specified, an empty list is returned.

Returns:

List of extra execution files.

Return type:

list[sio3pack.files.File]

get_extra_compilation_files()[source]

Returns the list of extra compilation files specified in the config.yml file. If no such files are specified, an empty list is returned.

Returns:

List of extra compilation files.

Return type:

list[sio3pack.files.File]

get_time_limit_for_test(test, language)[source]

Returns the time limit for the given test. Read the Sinolpack specification for more details.

Parameters:
  • test (sio3pack.test.Test) – The test to get the time limit for.

  • language (str) – The language of the program.

Returns:

The time limit for the test in seconds.

Return type:

int

get_memory_limit_for_test(test, language)[source]

Returns the memory limit for the given test. Read the Sinolpack specification for more details.

Parameters:
  • test (sio3pack.test.Test) – The test to get the memory limit for.

  • language (str) – The language of the program.

Returns:

The memory limit for the test in bytes.

Return type:

int

class sio3pack.packages.sinolpack.SinolpackWorkflowManager(package, workflows)[source]

Bases: sio3pack.workflow.WorkflowManager

A workflow manager for Sinolpack packages. It extends the base WorkflowManager and provides additional workflows for ingen, outgen, inwer, and other Sinolpack-specific tasks. It also overrides the get_compile_file_workflow method to add extra compilation files to the workflow.

Parameters:
  • package (Sinolpack) – The Sinolpack package to manage workflows for.

  • workflows (dict[str, Any]) – A dictionary of workflows to manage.

  • workflows

get_compile_file_workflow(file)[source]

Creates a workflow that compiles the given file and returns the path to the compiled file. The difference between this function and the base class is that this function adds the extra_compilation_files to the workflow.

Parameters:

file (sio3pack.files.File | str)

Return type:

tuple[sio3pack.workflow.Workflow, str]

get_default(name)[source]

Get the default workflow for the given name. This method should be overridden by subclasses to provide the default workflow for the given name.

Parameters:

name (str) – The name of the workflow.

Returns:

The default workflow for the given name.

Return type:

sio3pack.workflow.Workflow

get_unpack_operation(has_ingen, has_outgen, has_inwer, return_func=None)[source]

Get the unpack operation for the given data.

Parameters:
  • has_ingen (bool)

  • has_outgen (bool)

  • has_inwer (bool)

  • return_func (callable)

Return type:

sio3pack.workflow.WorkflowOperation

get_run_operation(program, tests=None, return_func=None)[source]

Get the run operation for the given data.

Parameters:
Return type:

sio3pack.workflow.WorkflowOperation

get_user_out_operation(program, test, return_func=None)[source]

Get the workflow for getting the user’s output for a given test.

Parameters:
Return type:

sio3pack.workflow.WorkflowOperation

get_test_run_operation(program, test, return_func=None)[source]

Get the workflow for running a given test on a given program.

Parameters:
Return type:

sio3pack.workflow.WorkflowOperation