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

Small refactors #228

Merged
merged 4 commits into from
Apr 5, 2024
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
6 changes: 3 additions & 3 deletions src/sinol_make/commands/doc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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(
Expand Down
5 changes: 1 addition & 4 deletions src/sinol_make/commands/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 1 addition & 4 deletions src/sinol_make/commands/gen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/sinol_make/commands/ingen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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):
Expand Down
8 changes: 3 additions & 5 deletions src/sinol_make/commands/inwer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
8 changes: 2 additions & 6 deletions src/sinol_make/commands/outgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)}'))

Expand Down
23 changes: 12 additions & 11 deletions src/sinol_make/commands/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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',
Expand All @@ -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):
Expand Down Expand Up @@ -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.")

Expand Down Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions src/sinol_make/helpers/parsers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import argparse

from sinol_make import util
from sinol_make.helpers import compiler


Expand Down Expand Up @@ -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())
Loading