diff --git a/src/sinol_make/commands/doc/__init__.py b/src/sinol_make/commands/doc/__init__.py index cdfd1229..ace6f803 100644 --- a/src/sinol_make/commands/doc/__init__.py +++ b/src/sinol_make/commands/doc/__init__.py @@ -18,7 +18,7 @@ def get_name(self): return "doc" def compile_file_latex_div(self, file_path): - print(util.info(f'Compiling {os.path.basename(file_path)} (latex to dvi)...')) + print(f'Compiling {os.path.basename(file_path)} (latex to dvi)...') os.chdir(os.path.dirname(file_path)) subprocess.run(['latex', file_path]) dvi_file = os.path.splitext(file_path)[0] + '.dvi' @@ -35,7 +35,7 @@ def compile_file_latex_div(self, file_path): return True def compile_pdf_latex(self, file_path): - print(util.info(f'Compiling {os.path.basename(file_path)} (pdflatex)...')) + print(f'Compiling {os.path.basename(file_path)} (pdflatex)...') os.chdir(os.path.dirname(file_path)) subprocess.run(['pdflatex', file_path]) pdf_file = os.path.splitext(file_path)[0] + '.pdf' @@ -62,7 +62,7 @@ def move_logs(self): for pattern in self.LOG_PATTERNS: for file in glob.glob(os.path.join(os.getcwd(), 'doc', pattern)): os.rename(file, os.path.join(output_dir, os.path.basename(file))) - print(util.info(f'Compilation log files can be found in {os.path.relpath(output_dir, os.getcwd())}')) + print(f'Compilation log files can be found in {os.path.relpath(output_dir, os.getcwd())}') def configure_subparser(self, subparser: argparse.ArgumentParser): parser = subparser.add_parser( diff --git a/src/sinol_make/commands/export/__init__.py b/src/sinol_make/commands/export/__init__.py index a1c820a0..eb727d99 100644 --- a/src/sinol_make/commands/export/__init__.py +++ b/src/sinol_make/commands/export/__init__.py @@ -28,10 +28,7 @@ def configure_subparser(self, subparser: argparse.ArgumentParser): self.get_name(), help='Create archive for oioioi upload', description='Creates archive in the current directory ready to upload to sio2 or szkopul.') - parser.add_argument('-c', '--cpus', type=int, - help=f'number of cpus to use to generate output files ' - f'(default: {util.default_cpu_count()})', - default=util.default_cpu_count()) + parsers.add_cpus_argument(parser, 'number of cpus to use to generate output files') 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', diff --git a/src/sinol_make/commands/gen/__init__.py b/src/sinol_make/commands/gen/__init__.py index dacecc3c..539166b7 100644 --- a/src/sinol_make/commands/gen/__init__.py +++ b/src/sinol_make/commands/gen/__init__.py @@ -31,10 +31,7 @@ def configure_subparser(self, subparser): help='path to ingen source file, for example prog/abcingen.cpp') parser.add_argument('-i', '--only-inputs', action='store_true', help='generate input files only') parser.add_argument('-o', '--only-outputs', action='store_true', help='generate output files only') - parser.add_argument('-c', '--cpus', type=int, - help=f'number of cpus to use to generate output files ' - f'(default: {util.default_cpu_count()})', - default=util.default_cpu_count()) + parsers.add_cpus_argument(parser, 'number of cpus to use to generate output files') parser.add_argument('-n', '--no-validate', default=False, action='store_true', help='do not validate test contents') parser.add_argument('-f', '--fsanitize', default=False, action='store_true', diff --git a/src/sinol_make/commands/ingen/__init__.py b/src/sinol_make/commands/ingen/__init__.py index baf2ca94..c75401eb 100644 --- a/src/sinol_make/commands/ingen/__init__.py +++ b/src/sinol_make/commands/ingen/__init__.py @@ -45,7 +45,7 @@ def run(self, args: argparse.Namespace): package_util.validate_test_names(self.task_id) util.change_stack_size_to_unlimited() self.ingen = get_ingen(self.task_id, args.ingen_path) - print(util.info(f'Using ingen file {os.path.basename(self.ingen)}')) + print(f'Using ingen file {os.path.basename(self.ingen)}') self.ingen_exe = compile_ingen(self.ingen, self.args, self.args.compile_mode, self.args.fsanitize) previous_tests = [] @@ -64,7 +64,7 @@ def run(self, args: argparse.Namespace): else: util.exit_with_error('Failed to generate input files.') - print(util.info('Cleaning up old input files.')) + print('Cleaning up old input files.') for test in glob.glob(os.path.join(os.getcwd(), "in", f"{self.task_id}*.in")): basename = os.path.basename(test) if basename in dates and dates[basename] == os.path.getmtime(test): diff --git a/src/sinol_make/commands/inwer/__init__.py b/src/sinol_make/commands/inwer/__init__.py index abb96be3..39743f35 100644 --- a/src/sinol_make/commands/inwer/__init__.py +++ b/src/sinol_make/commands/inwer/__init__.py @@ -10,8 +10,7 @@ from sinol_make import util from sinol_make.structs.inwer_structs import TestResult, InwerExecution, VerificationResult, TableData -from sinol_make.helpers import package_util, compile, printer, paths -from sinol_make.helpers.parsers import add_compilation_arguments +from sinol_make.helpers import package_util, printer, paths, parsers from sinol_make.interfaces.BaseCommand import BaseCommand from sinol_make.commands.inwer import inwer_util @@ -37,12 +36,11 @@ def configure_subparser(self, subparser: argparse.ArgumentParser): help='path to inwer source file, for example prog/abcinwer.cpp') parser.add_argument('-t', '--tests', type=str, nargs='+', help='test to verify, for example in/abc{0,1}*') - parser.add_argument('-c', '--cpus', type=int, - help=f'number of cpus to use (default: {util.default_cpu_count()})') + parsers.add_cpus_argument(parser, 'number of cpus to use when verifying tests') parser.add_argument('-f', '--fsanitize', default=False, action='store_true', help='Use -fsanitize=address,undefined for compilation. Warning: this may fail on some ' 'systems. Tof fix this, run `sudo sysctl vm.mmap_rnd_bits = 28`.') - add_compilation_arguments(parser) + parsers.add_compilation_arguments(parser) return parser @staticmethod diff --git a/src/sinol_make/commands/outgen/__init__.py b/src/sinol_make/commands/outgen/__init__.py index 63a3fc35..ab139610 100644 --- a/src/sinol_make/commands/outgen/__init__.py +++ b/src/sinol_make/commands/outgen/__init__.py @@ -26,11 +26,7 @@ def configure_subparser(self, subparser): help='Generate output files', description='Generate output files using the correct solution.' ) - - parser.add_argument('-c', '--cpus', type=int, - help=f'number of cpus to use to generate output files ' - f'(default: {util.default_cpu_count()})', - default=util.default_cpu_count()) + parsers.add_cpus_argument(parser, 'number of cpus to use to generate output files') parser.add_argument('-n', '--no-validate', default=False, action='store_true', help='do not validate test contents') parsers.add_compilation_arguments(parser) @@ -50,7 +46,7 @@ def generate_outputs(self, outputs_to_generate): for i, result in enumerate(pool.imap(generate_output, arguments)): results.append(result) if result: - print(util.info(f'Successfully generated output file {os.path.basename(arguments[i].output_test)}')) + print(f'Successfully generated output file {os.path.basename(arguments[i].output_test)}') else: print(util.error(f'Failed to generate output file {os.path.basename(arguments[i].output_test)}')) diff --git a/src/sinol_make/commands/run/__init__.py b/src/sinol_make/commands/run/__init__.py index 69cc2f5f..3058ec0d 100644 --- a/src/sinol_make/commands/run/__init__.py +++ b/src/sinol_make/commands/run/__init__.py @@ -8,21 +8,23 @@ import psutil import glob import shutil +import os +import collections +import sys +import math +import dictdiffer +import multiprocessing as mp from io import StringIO from typing import Dict -from sinol_make import contest_types, oiejq +from sinol_make import contest_types, oiejq, util from sinol_make.structs.run_structs import ExecutionData, PrintData from sinol_make.structs.cache_structs import CacheTest, CacheFile -from sinol_make.helpers.parsers import add_compilation_arguments from sinol_make.interfaces.BaseCommand import BaseCommand from sinol_make.interfaces.Errors import CompilationError, CheckerOutputException, UnknownContestType -from sinol_make.helpers import compile, compiler, package_util, printer, paths, cache +from sinol_make.helpers import compile, compiler, package_util, printer, paths, cache, parsers from sinol_make.structs.status_structs import Status, ResultChange, PointsChange, ValidationResult, ExecutionResult, \ TotalPointsChange -import sinol_make.util as util -import yaml, os, collections, sys, re, math, dictdiffer -import multiprocessing as mp def color_memory(memory, limit): @@ -288,8 +290,7 @@ def configure_subparser(self, subparser): help='solutions to be run, for example prog/abc{b,s}*.{cpp,py}') parser.add_argument('-t', '--tests', type=str, nargs='+', help='tests to be run, for example in/abc{0,1}*') - parser.add_argument('-c', '--cpus', type=int, - help=f'number of cpus to use (default: {util.default_cpu_count()}') + parsers.add_cpus_argument(parser, 'number of cpus to use when running solutions') parser.add_argument('--tl', type=float, help='time limit for all tests (in s)') parser.add_argument('--ml', type=float, help='memory limit for all tests (in MB)') parser.add_argument('--hide-memory', dest='hide_memory', action='store_true', @@ -303,7 +304,7 @@ def configure_subparser(self, subparser): parser.add_argument('--ignore-expected', dest='ignore_expected', action='store_true', help='ignore expected scores from config.yml. When this flag is set, ' 'the expected scores are not compared with the actual scores.') - add_compilation_arguments(parser) + parsers.add_compilation_arguments(parser) return parser def parse_time(self, time_str): @@ -1020,7 +1021,7 @@ def set_group_result(solution, group, result): self.config["sinol_expected_scores"] = self.convert_status_to_string(config_expected_scores) util.save_config(self.config) - print(util.info("Saved suggested expected scores description.")) + print("Saved suggested expected scores description.") else: util.exit_with_error("Use flag --apply-suggestions to apply suggestions.") @@ -1214,7 +1215,7 @@ def run(self, args): checker = package_util.get_files_matching_pattern(self.ID, f'{self.ID}chk.*') if len(checker) != 0: - print(util.info("Checker found: %s" % os.path.basename(checker[0]))) + print("Checker found: %s" % os.path.basename(checker[0])) self.checker = checker[0] self.compile_checker() else: diff --git a/src/sinol_make/helpers/parsers.py b/src/sinol_make/helpers/parsers.py index db233ed1..696cb339 100644 --- a/src/sinol_make/helpers/parsers.py +++ b/src/sinol_make/helpers/parsers.py @@ -1,6 +1,7 @@ import sys import argparse +from sinol_make import util from sinol_make.helpers import compiler @@ -29,3 +30,10 @@ def add_compilation_arguments(parser: argparse.ArgumentParser): ' oioioi / o - uses the same flags as oioioi:\n' ' (-Wall -Wno-unused-result -Werror)' ' weak / w - disable all warning flags during C and C++ compilation', default='default') + + +def add_cpus_argument(parser: argparse.ArgumentParser, help: str): + parser.add_argument('-c', '--cpus', type=int, + help=f'{help} ' + f'(default: {util.default_cpu_count()})', + default=util.default_cpu_count())