Skip to content

Commit

Permalink
Merge branch 'main' into solutions-with-long-names
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane committed Nov 16, 2023
2 parents 6ee5c7d + 15a01c0 commit ef54b36
Show file tree
Hide file tree
Showing 37 changed files with 436 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Arch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: self-hosted
strategy:
matrix:
python-version: ["3.7.17", "3.11.4"]
python-version: ["3.7.17", "3.12.0"]
name: pytest-arch-python-${{ matrix.python-version }}
container:
image: archlinux:latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/GithubRunner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
pytest:
strategy:
matrix:
python-version: ["3.7.17", "3.11.4"]
python-version: ["3.7.17", "3.12.0"]
name: pytest-github-runner-python-${{ matrix.python-version }}
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Ubuntu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: self-hosted
strategy:
matrix:
python-version: ["3.7.17", "3.11.4"]
python-version: ["3.7.17", "3.12.0"]
name: pytest-ubuntu-python-${{ matrix.python-version }}
container:
image: ubuntu:latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macOS.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
python-version: ["3.7.17", "3.11.4"]
python-version: ["3.7.17", "3.12.0"]
name: pytest-macos-python-${{ matrix.python-version }}
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
python3 -m build --sdist --wheel --outdir dist/ .
- name: Publish
if: startsWith(github.ref, 'refs/tags')
# if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.venv
.venv3.12
dist
*.egg-info
build
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ through Python's package manager pip, which usually is installed alongside Pytho
```
pip3 install sinol-make
```
`pip` installs the `sinol-make` executable in `~/.local/bin/` directory,
so make sure this directory is in your `PATH`.
[Here's](https://gist.github.com/nex3/c395b2f8fd4b02068be37c961301caa7) how to add a directory to `PATH`.

As `oiejq` works only on Linux-based operating systems,
*we do not recommend* using operating systems such as Windows or macOS.
Expand Down
2 changes: 1 addition & 1 deletion src/sinol_make/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sinol_make import util, oiejq


__version__ = "1.5.10"
__version__ = "1.5.14"


def configure_parsers():
Expand Down
11 changes: 11 additions & 0 deletions src/sinol_make/commands/doc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import subprocess

from sinol_make import util
from sinol_make.helpers import paths
from sinol_make.interfaces.BaseCommand import BaseCommand


class Command(BaseCommand):
"""
Class for `doc` command.
"""
LOG_PATTERNS = ['*~', '*.aux', '*.log', '*.dvi', '*.err', '*.inf']

def get_name(self):
return "doc"
Expand All @@ -32,6 +34,14 @@ def compile_file(self, file_path):
print(util.info(f'Compilation successful for file {os.path.basename(file_path)}.'))
return True

def move_logs(self):
output_dir = paths.get_cache_path('doc_logs')
os.makedirs(output_dir, exist_ok=True)
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())}'))

def configure_subparser(self, subparser: argparse.ArgumentParser):
parser = subparser.add_parser(
self.get_name(),
Expand Down Expand Up @@ -63,6 +73,7 @@ def run(self, args: argparse.Namespace):
failed.append(file)
os.chdir(original_cwd)

self.move_logs()
if failed:
for failed_file in failed:
print(util.error(f'Failed to compile {failed_file}'))
Expand Down
5 changes: 5 additions & 0 deletions src/sinol_make/commands/export/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import glob
import stat
import shutil
import tarfile
import argparse
Expand Down Expand Up @@ -62,6 +63,10 @@ def copy_package_required_files(self, target_dir: str):
shutil.copytree(file_path, os.path.join(target_dir, file))
else:
shutil.copy(file_path, target_dir)
shell_ingen = os.path.join(target_dir, 'prog', f'{self.task_id}ingen.sh')
if os.path.exists(shell_ingen):
st = os.stat(shell_ingen)
os.chmod(shell_ingen, st.st_mode | stat.S_IEXEC)

print('Copying example tests...')
for ext in ['in', 'out']:
Expand Down
62 changes: 39 additions & 23 deletions src/sinol_make/commands/gen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ def configure_subparser(self, subparser):

parser.add_argument('ingen_path', type=str, nargs='?',
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 (default: {mp.cpu_count()} - all available)',
default=mp.cpu_count())
help=f'number of cpus to use to generate output files '
f'(default: {util.default_cpu_count()})',
default=util.default_cpu_count())
parsers.add_compilation_arguments(parser)

def generate_outputs(self, outputs_to_generate):
Expand Down Expand Up @@ -79,38 +82,51 @@ 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)
output_basename = os.path.splitext(os.path.basename(basename))[0] + '.out'
output_path = os.path.join(os.getcwd(), 'out', output_basename)
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))
outputs_to_generate.append(output_path)
elif not os.path.exists(output_path):
# If output file does not exist, generate it.
outputs_to_generate.append(output_path)

return md5_sums, outputs_to_generate

def run(self, args: argparse.Namespace):
util.exit_if_not_package()

self.args = args
self.ins = args.only_inputs
self.outs = args.only_outputs
# If no arguments are specified, generate both input and output files.
if not self.ins and not self.outs:
self.ins = True
self.outs = True

self.task_id = package_util.get_task_id()
package_util.validate_test_names(self.task_id)
self.ingen = gen_util.get_ingen(self.task_id, args.ingen_path)
print(util.info(f'Using ingen file {os.path.basename(self.ingen)}'))
util.change_stack_size_to_unlimited()
if self.ins:
self.ingen = gen_util.get_ingen(self.task_id, args.ingen_path)
print(util.info(f'Using ingen file {os.path.basename(self.ingen)}'))
self.ingen_exe = gen_util.compile_ingen(self.ingen, self.args, self.args.weak_compilation_flags)

if gen_util.run_ingen(self.ingen_exe):
print(util.info('Successfully generated input files.'))
else:
util.exit_with_error('Failed to generate input files.')

self.correct_solution = gen_util.get_correct_solution(self.task_id)
self.ingen_exe = gen_util.compile_ingen(self.ingen, self.args, self.args.weak_compilation_flags)
if self.outs:
self.correct_solution = gen_util.get_correct_solution(self.task_id)

util.change_stack_size_to_unlimited()
if gen_util.run_ingen(self.ingen_exe):
print(util.info('Successfully generated input files.'))
else:
util.exit_with_error('Failed to generate input files.')
md5_sums, outputs_to_generate = self.calculate_md5_sums()
if len(outputs_to_generate) == 0:
print(util.info('All output files are up to date.'))
else:
self.correct_solution_exe = gen_util.compile_correct_solution(self.correct_solution, self.args,
self.args.weak_compilation_flags)
self.generate_outputs(outputs_to_generate)

with open(os.path.join(os.getcwd(), 'in', '.md5sums'), 'w') as f:
yaml.dump(md5_sums, f)
md5_sums, outputs_to_generate = self.calculate_md5_sums()
if len(outputs_to_generate) == 0:
print(util.info('All output files are up to date.'))
else:
self.correct_solution_exe = gen_util.compile_correct_solution(self.correct_solution, self.args,
self.args.weak_compilation_flags)
self.generate_outputs(outputs_to_generate)
with open(os.path.join(os.getcwd(), 'in', '.md5sums'), 'w') as f:
yaml.dump(md5_sums, f)
6 changes: 3 additions & 3 deletions src/sinol_make/commands/inwer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,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}*')
parser.add_argument('-c', '--cpus', type=int,
help=f'number of cpus to use (default: {mp.cpu_count()} -all available)')
help=f'number of cpus to use (default: {util.default_cpu_count()})')
add_compilation_arguments(parser)

def compile_inwer(self, args: argparse.Namespace):
Expand Down Expand Up @@ -92,7 +92,7 @@ def verify_and_print_table(self) -> Dict[str, TestResult]:

has_terminal, terminal_width, terminal_height = util.get_terminal_size()

table_data = TableData(results, 0)
table_data = TableData(results, 0, self.task_id)
if has_terminal:
run_event = threading.Event()
run_event.set()
Expand Down Expand Up @@ -133,7 +133,7 @@ def run(self, args: argparse.Namespace):
relative_path = os.path.relpath(self.inwer, os.getcwd())
print(f'Verifying with inwer {util.bold(relative_path)}')

self.cpus = args.cpus or mp.cpu_count()
self.cpus = args.cpus or util.default_cpu_count()
self.tests = package_util.get_tests(self.task_id, args.tests)

if len(self.tests) == 0:
Expand Down
14 changes: 10 additions & 4 deletions src/sinol_make/commands/inwer/inwer_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def compile_inwer(inwer_path: str, args: argparse.Namespace, weak_compilation_fl
return compile.compile_file(inwer_path, package_util.get_executable(inwer_path), compilers, weak_compilation_flags)


def sort_tests(tests, task_id):
# First sort by group, then by test name.
tests.sort(key=lambda test: [package_util.get_group(test, task_id), test])
return tests


def print_view(term_width, term_height, table_data: TableData):
"""
Prints current results of test verification.
Expand All @@ -48,12 +54,12 @@ def print_view(term_width, term_height, table_data: TableData):

results = table_data.results
column_lengths = [0, len('Group') + 1, len('Status') + 1, 0]
sorted_test_paths = []
tests = []
for result in results.values():
column_lengths[0] = max(column_lengths[0], len(result.test_name))
column_lengths[1] = max(column_lengths[1], len(result.test_group))
sorted_test_paths.append(result.test_path)
sorted_test_paths.sort()
tests.append(result.test_path)
tests = sort_tests(tests, table_data.task_id)

column_lengths[3] = max(10, term_width - column_lengths[0] - column_lengths[1] - column_lengths[2] - 9 - 3) # 9 is for " | " between columns, 3 for margin.
margin = " "
Expand All @@ -69,7 +75,7 @@ def print_line_separator():
" | " + "Output")
print_line_separator()

for test_path in sorted_test_paths:
for test_path in tests:
result = results[test_path]
print(margin + result.test_name.ljust(column_lengths[0]) + " | ", end='')
print(result.test_group.ljust(column_lengths[1] - 1) + " | ", end='')
Expand Down
Loading

0 comments on commit ef54b36

Please sign in to comment.