From b1d157da18c8bee38267f2e033896e571bb3f2dd Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Thu, 4 Apr 2024 17:34:32 +0200 Subject: [PATCH 1/3] Less colorful printing --- src/sinol_make/commands/doc/__init__.py | 6 +++--- src/sinol_make/commands/ingen/__init__.py | 4 ++-- src/sinol_make/commands/outgen/__init__.py | 2 +- src/sinol_make/commands/run/__init__.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sinol_make/commands/doc/__init__.py b/src/sinol_make/commands/doc/__init__.py index 3d624bed..450457fc 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/ingen/__init__.py b/src/sinol_make/commands/ingen/__init__.py index 9be7a6ef..591d6a26 100644 --- a/src/sinol_make/commands/ingen/__init__.py +++ b/src/sinol_make/commands/ingen/__init__.py @@ -41,7 +41,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) previous_tests = [] @@ -60,7 +60,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/outgen/__init__.py b/src/sinol_make/commands/outgen/__init__.py index c32b7c5a..ff59b54a 100644 --- a/src/sinol_make/commands/outgen/__init__.py +++ b/src/sinol_make/commands/outgen/__init__.py @@ -49,7 +49,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 79612732..fa530b81 100644 --- a/src/sinol_make/commands/run/__init__.py +++ b/src/sinol_make/commands/run/__init__.py @@ -1016,7 +1016,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.") @@ -1210,7 +1210,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: From f4ac3e08253a9f11a0a5dcc0db6a036f0fb054bd Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Thu, 4 Apr 2024 17:40:17 +0200 Subject: [PATCH 2/3] Refactor --cpus flag --- src/sinol_make/commands/export/__init__.py | 5 +---- src/sinol_make/commands/gen/__init__.py | 5 +---- src/sinol_make/commands/inwer/__init__.py | 5 ++--- src/sinol_make/commands/outgen/__init__.py | 6 +----- src/sinol_make/commands/run/__init__.py | 7 +++---- src/sinol_make/helpers/parsers.py | 8 ++++++++ tests/conftest.py | 5 ++--- 7 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/sinol_make/commands/export/__init__.py b/src/sinol_make/commands/export/__init__.py index 5d072040..f49ce6c3 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 afb3b53f..84c8093d 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') parsers.add_compilation_arguments(parser) diff --git a/src/sinol_make/commands/inwer/__init__.py b/src/sinol_make/commands/inwer/__init__.py index 71245b97..7bca2611 100644 --- a/src/sinol_make/commands/inwer/__init__.py +++ b/src/sinol_make/commands/inwer/__init__.py @@ -10,7 +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 import package_util, compile, printer, paths, parsers from sinol_make.helpers.parsers import add_compilation_arguments from sinol_make.interfaces.BaseCommand import BaseCommand from sinol_make.commands.inwer import inwer_util @@ -37,8 +37,7 @@ 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') add_compilation_arguments(parser) @staticmethod diff --git a/src/sinol_make/commands/outgen/__init__.py b/src/sinol_make/commands/outgen/__init__.py index ff59b54a..05a2cff8 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) diff --git a/src/sinol_make/commands/run/__init__.py b/src/sinol_make/commands/run/__init__.py index fa530b81..30a3296f 100644 --- a/src/sinol_make/commands/run/__init__.py +++ b/src/sinol_make/commands/run/__init__.py @@ -14,7 +14,7 @@ from sinol_make import contest_types, oiejq 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.helpers import parsers 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 @@ -288,8 +288,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', @@ -300,7 +299,7 @@ def configure_subparser(self, subparser): help='path to oiejq executable (default: `~/.local/bin/oiejq`)') parser.add_argument('-a', '--apply-suggestions', dest='apply_suggestions', action='store_true', help='apply suggestions from expected scores report') - add_compilation_arguments(parser) + parsers.add_compilation_arguments(parser) def parse_time(self, time_str): if len(time_str) < 3: return -1 diff --git a/src/sinol_make/helpers/parsers.py b/src/sinol_make/helpers/parsers.py index 83f1ae74..598642b6 100644 --- a/src/sinol_make/helpers/parsers.py +++ b/src/sinol_make/helpers/parsers.py @@ -2,6 +2,7 @@ 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()) diff --git a/tests/conftest.py b/tests/conftest.py index 6405706d..bc2eae55 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,7 +8,7 @@ import multiprocessing as mp from sinol_make import util -from sinol_make.helpers import compile, paths +from sinol_make.helpers import compile, paths, parsers from sinol_make.interfaces.Errors import CompilationError @@ -37,8 +37,7 @@ def pytest_addoption(parser): help='Time tool to use. Default: if linux - both, otherwise time' ) parser.addoption("--no-precompile", action="store_true", help="if set, will not precompile all solutions") - parser.addoption("--cpus", type=int, help="number of cpus to use, by default all available", - default=util.default_cpu_count()) + parsers.add_cpus_argument(parser, 'number of cpus to use to compile solutions') def pytest_configure(config): From 7ddad9a890ad78521ffa8c897876c503bf7624b4 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Thu, 4 Apr 2024 17:43:19 +0200 Subject: [PATCH 3/3] Refactor imports --- src/sinol_make/commands/inwer/__init__.py | 5 ++--- src/sinol_make/commands/run/__init__.py | 14 ++++++++------ src/sinol_make/helpers/parsers.py | 1 - tests/conftest.py | 5 +++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/sinol_make/commands/inwer/__init__.py b/src/sinol_make/commands/inwer/__init__.py index 7bca2611..dfe5bba6 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, parsers -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 @@ -38,7 +37,7 @@ def configure_subparser(self, subparser: argparse.ArgumentParser): parser.add_argument('-t', '--tests', type=str, nargs='+', help='test to verify, for example in/abc{0,1}*') parsers.add_cpus_argument(parser, 'number of cpus to use when verifying tests') - add_compilation_arguments(parser) + parsers.add_compilation_arguments(parser) @staticmethod def verify_test(execution: InwerExecution) -> VerificationResult: diff --git a/src/sinol_make/commands/run/__init__.py b/src/sinol_make/commands/run/__init__.py index 30a3296f..4e42f3d0 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 import parsers 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): diff --git a/src/sinol_make/helpers/parsers.py b/src/sinol_make/helpers/parsers.py index 598642b6..4591eca5 100644 --- a/src/sinol_make/helpers/parsers.py +++ b/src/sinol_make/helpers/parsers.py @@ -1,5 +1,4 @@ import sys - import argparse from sinol_make import util diff --git a/tests/conftest.py b/tests/conftest.py index bc2eae55..6405706d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,7 +8,7 @@ import multiprocessing as mp from sinol_make import util -from sinol_make.helpers import compile, paths, parsers +from sinol_make.helpers import compile, paths from sinol_make.interfaces.Errors import CompilationError @@ -37,7 +37,8 @@ def pytest_addoption(parser): help='Time tool to use. Default: if linux - both, otherwise time' ) parser.addoption("--no-precompile", action="store_true", help="if set, will not precompile all solutions") - parsers.add_cpus_argument(parser, 'number of cpus to use to compile solutions') + parser.addoption("--cpus", type=int, help="number of cpus to use, by default all available", + default=util.default_cpu_count()) def pytest_configure(config):