Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane committed Sep 13, 2023
2 parents d41e039 + e5705ef commit c4cf380
Show file tree
Hide file tree
Showing 63 changed files with 1,151 additions and 209 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/macOS.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Prepare system
run: |
rm -f '/usr/local/bin/2to3' # Homebrew will fail if this exists
- name: Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand All @@ -25,7 +28,7 @@ jobs:
brew install gnu-time coreutils diffutils dpkg
- name: Install Python dependencies
run: |
pip3 install .[tests]
python3 -m pip install .[tests]
- name: Run pytest
run: |
python3 -m pytest -v --time-tool time
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build
.idea
__pycache__
/tests/packages/**/cache
/tests/packages/**/.cache
src/sinol_make/data

# pytest-cov
Expand Down
83 changes: 83 additions & 0 deletions examples/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
### Keys used by sio2:

# Title of the package is defined in `title` key.
title: Example task package
# Title can be different for different languages.
# They are defined in `title_<lang>` keys.
# <lang> is a language code (for example 'pl' or 'en').
# Available languages are defined in settings of `oioioi` instance.
title_pl: Przykładowe zadanie

# Number of points for each group can be defined in `scores` key.
# If this key is not specified, then all groups have the same number of points.
# (if number of groups doesn't divide 100, then the last groups will have the remaining points).
# Group 0 always has zero points.
scores:
1: 20
2: 30
3: 25
4: 25

# Time limit for all tests is defined in `time_limit` key.
# More precise time limit for each group or test can be defined in `time_limits` key.
# The more precise time limit has higher priority (first group, then global time limit).
# Time limit is in milliseconds.
time_limit: 1000
time_limits:
1: 2000

# Memory limit for all tests is defined in `memory_limit` key.
# More precise memory limits can be defined in `memory_limits` key.
# Same as with time limits, the more precise memory limit has higher priority.
# Memory limit is in kB
memory_limit: 262144
memory_limits:
3: 131072

# Time and memory limits can be overriden for other languages in `override_limits` key.
# If this key is not specified, then all languages have the same limits.
override_limits:
py:
time_limit: 5000
memory_limit: 524288

# Extra compilation arguments can be defined in `extra_compile_args` key.
# Each language can have different extra arguments.
extra_compilation_args:
cpp: 'abclib.cpp'
# The arguments can also be in an array:
extra_compilation_args:
cpp:
- 'abclib.cpp'
- 'abclib2.cpp'

# Additional files used in compilation can be defined in `extra_compilation_files` key.
# They are copied to the directory where the source code is compiled.
# All languages have the same additional files.
extra_compilation_files: ['abclib.cpp', 'abclib.py']


### Keys used by sinol-make:

# This key represents the short name (consisting of 3 letters) of the task.
# The names of files in `prog/`, `doc/`, `in/` and `out/` directories have to start with this task id.
# This key is only used by `sinol-make`: running `sinol-make export` creates
# an archive with the proper name, which sio2 uses as the task id.
sinol_task_id: abc

# sinol-make can behave differently depending on the value of `sinol_contest_type` key.
# Mainly, it affects how points are calculated.
# If the key is not specified, then `default` is used.
# Possible values are:
# - `default` - Points for a test can only be 100 or 0 (unless checker assigns points).
# Points for a group are calculated based of the lowest number of points for a test in this group.
# - `oi` - Points for a test are unchanged if the execution time is less or equal to the time limit.
# Otherwise, number of points decreases linearly to one depending on the execution time.
# Points for a group are calculated same as in `default` mode.
sinol_contest_type: oi

# sinol-make can check if the solutions run as expected when using `run` command.
# Key `sinol_expected_scores` defines expected scores for each solution on each tests.
# There should be no reason to change this key manually.
# It is automatically generated and managed by sinol-make.
sinol_expected_scores: {}
4 changes: 2 additions & 2 deletions src/sinol_make/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from sinol_make import util, oiejq

__version__ = "1.5.1"
__version__ = "1.5.6"

def configure_parsers():
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -45,7 +45,7 @@ def main_exn():
f'New version of sinol-make is available (your version: {__version__}, available version: {new_version}).\n'
f' You can update it by running `pip3 install sinol-make --upgrade`.'))

if sys.platform == 'linux' and not oiejq.check_oiejq():
if util.is_linux() and not oiejq.check_oiejq():
print(util.warning('`oiejq` in `~/.local/bin/` not found, installing now...'))

try:
Expand Down
15 changes: 10 additions & 5 deletions src/sinol_make/commands/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import yaml

from sinol_make import util
from sinol_make.helpers import package_util, parsers
from sinol_make.helpers import package_util, parsers, paths
from sinol_make.commands.gen import gen_util
from sinol_make.interfaces.BaseCommand import BaseCommand

Expand Down Expand Up @@ -34,7 +34,7 @@ def get_generated_tests(self):
if not gen_util.ingen_exists(self.task_id):
return []

working_dir = os.path.join(os.getcwd(), 'cache', 'export', 'tests')
working_dir = paths.get_cache_path('export', 'tests')
if os.path.exists(working_dir):
shutil.rmtree(working_dir)
os.makedirs(working_dir)
Expand Down Expand Up @@ -92,11 +92,16 @@ def create_makefile_in(self, target_dir: str, config: dict):
with open(os.path.join(target_dir, 'makefile.in'), 'w') as f:
cxx_flags = '-std=c++17'
c_flags = '-std=c17'
def format_multiple_arguments(obj):
if isinstance(obj, str):
return obj
return ' '.join(obj)

if 'extra_compilation_args' in config:
if 'cpp' in config['extra_compilation_args']:
cxx_flags += ' ' + ' '.join(config['extra_compilation_args']['cpp'])
cxx_flags += ' ' + format_multiple_arguments(config['extra_compilation_args']['cpp'])
if 'c' in config['extra_compilation_args']:
c_flags += ' ' + ' '.join(config['extra_compilation_args']['c'])
c_flags += ' ' + format_multiple_arguments(config['extra_compilation_args']['c'])

f.write(f'MODE = wer\n'
f'ID = {self.task_id}\n'
Expand Down Expand Up @@ -131,7 +136,7 @@ def run(self, args: argparse.Namespace):
with open(os.path.join(os.getcwd(), 'config.yml'), 'r') as config_file:
config = yaml.load(config_file, Loader=yaml.FullLoader)

export_package_path = os.path.join(os.getcwd(), 'cache', 'export', self.task_id)
export_package_path = paths.get_cache_path('export', self.task_id)
if os.path.exists(export_package_path):
shutil.rmtree(export_package_path)
os.makedirs(export_package_path)
Expand Down
3 changes: 2 additions & 1 deletion src/sinol_make/commands/gen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def calculate_md5_sums(self):
outputs_to_generate = []
for file in glob.glob(os.path.join(os.getcwd(), 'in', '*.in')):
basename = os.path.basename(file)
md5_sums[basename] = hashlib.md5(open(file, 'rb').read()).hexdigest()
md5_sums[basename] = util.get_file_md5(file)

if old_md5_sums is None or old_md5_sums.get(basename, '') != md5_sums[basename]:
output_basename = os.path.splitext(os.path.basename(basename))[0] + '.out'
outputs_to_generate.append(os.path.join(os.getcwd(), "out", output_basename))
Expand Down
12 changes: 8 additions & 4 deletions src/sinol_make/commands/gen/gen_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ def get_ingen(task_id=None, ingen_path=None):
util.exit_with_error(f'Ingen source file for task {task_id} does not exist.')

# Sio2 first chooses shell scripts, then non-shell source codes.
if os.path.splitext(ingen[0])[1] == '.sh' and len(ingen) > 1:
return ingen[1]
else:
return ingen[0]
correct_ingen = None
for i in ingen:
if os.path.splitext(i)[1] == '.sh':
correct_ingen = i
break
if correct_ingen is None:
correct_ingen = ingen[0]
return correct_ingen


def compile_ingen(ingen_path: str, args: argparse.Namespace, weak_compilation_flags=False):
Expand Down
4 changes: 2 additions & 2 deletions src/sinol_make/commands/inwer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from sinol_make import util
from sinol_make.commands.inwer.structs import TestResult, InwerExecution, VerificationResult, TableData
from sinol_make.helpers import package_util, compile, printer
from sinol_make.helpers import package_util, compile, printer, paths
from sinol_make.helpers.parsers import add_compilation_arguments
from sinol_make.interfaces.BaseCommand import BaseCommand
from sinol_make.commands.inwer import inwer_util
Expand Down Expand Up @@ -52,7 +52,7 @@ def verify_test(execution: InwerExecution) -> VerificationResult:
"""
Verifies a test and returns the result of inwer on this test.
"""
output_dir = os.path.join(os.getcwd(), 'cache', 'executions', execution.test_name)
output_dir = paths.get_executables_path(execution.test_name)
os.makedirs(output_dir, exist_ok=True)

command = [execution.inwer_exe_path]
Expand Down
13 changes: 8 additions & 5 deletions src/sinol_make/commands/inwer/inwer_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ def print_line_separator():
else:
output.append("")

print(output[0].ljust(column_lengths[3]))
output.pop(0)
if output == []:
print(util.color_gray("No output"))
else:
print(output[0].ljust(column_lengths[3]))
output.pop(0)

for line in output:
print(" " * (column_lengths[0] + 2) + " | " + " " * (column_lengths[1] - 1) + " | " +
" " * (column_lengths[2] - 1) + " | " + line.ljust(column_lengths[3]))
for line in output:
print(" " * (column_lengths[0] + 2) + " | " + " " * (column_lengths[1] - 1) + " | " +
" " * (column_lengths[2] - 1) + " | " + line.ljust(column_lengths[3]))

print_line_separator()
print()
Expand Down
Loading

0 comments on commit c4cf380

Please sign in to comment.