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

Library Checker の更新に追従 #671

Merged
merged 3 commits into from
Feb 7, 2020
Merged
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
32 changes: 18 additions & 14 deletions onlinejudge/service/library_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
the module for yosupo's Library Checker (https://judge.yosupo.jp)
"""

import glob
import os
import pathlib
import re
Expand All @@ -12,7 +13,6 @@
from typing import *

import requests
import toml

import onlinejudge._implementation.logging as log
import onlinejudge._implementation.testcase_zipper
Expand Down Expand Up @@ -49,7 +49,7 @@ def _update_cloned_repository(cls) -> None:
return

try:
subprocess.check_call(['git', '--version'], stdout=sys.stdout, stderr=sys.stderr)
subprocess.check_call(['git', '--version'], stdout=sys.stderr, stderr=sys.stderr)
except FileNotFoundError:
log.error('git command not found')
raise
Expand All @@ -59,11 +59,11 @@ def _update_cloned_repository(cls) -> None:
# init the problem repository
url = 'https://github.com/yosupo06/library-checker-problems'
log.status('$ git clone %s %s', url, path)
subprocess.check_call(['git', 'clone', url, str(path)], stdout=sys.stdout, stderr=sys.stderr)
subprocess.check_call(['git', 'clone', url, str(path)], stdout=sys.stderr, stderr=sys.stderr)
else:
# sync the problem repository
log.status('$ git -C %s pull', str(path))
subprocess.check_call(['git', '-C', str(path), 'pull'], stdout=sys.stdout, stderr=sys.stderr)
subprocess.check_call(['git', '-C', str(path), 'pull'], stdout=sys.stderr, stderr=sys.stderr)

cls.is_repository_updated = True

Expand All @@ -88,7 +88,7 @@ def download_system_cases(self, *, session: Optional[requests.Session] = None) -
files += [(file.name, file.read_bytes()) for file in path.glob('out/*.out')]
return onlinejudge._implementation.testcase_zipper.extract_from_files(iter(files))

def _generate_test_cases_in_cloned_repository(self) -> None:
def _generate_test_cases_in_cloned_repository(self, compile_checker: bool = False) -> None:
LibraryCheckerService._update_cloned_repository()
path = LibraryCheckerService._get_cloned_repository_path()

Expand All @@ -97,18 +97,24 @@ def _generate_test_cases_in_cloned_repository(self) -> None:
if os.name == 'nt':
log.warning("generate.py may not work on Windows")

command = [sys.executable, str(path / 'generate.py'), str(path / 'problems.toml'), '-p', self.problem_id]
problem_spec = str(self._get_problem_directory_path() / 'info.toml')
command = [sys.executable, str(path / 'generate.py'), problem_spec]
if compile_checker:
command.append('--compile-checker')
log.status('$ %s', ' '.join(command))
try:
subprocess.check_call(command, stdout=sys.stdout, stderr=sys.stderr)
subprocess.check_call(command, stdout=sys.stderr, stderr=sys.stderr)
except subprocess.CalledProcessError:
log.error("the generate.py failed: check https://github.com/yosupo06/library-checker-problems/issues")
raise

def _get_problem_directory_path(self) -> pathlib.Path:
path = LibraryCheckerService._get_cloned_repository_path()
problems = toml.load(path / 'problems.toml')
return path / problems['problems'][self.problem_id]['dir']
info_tomls = list(path.glob('**/{}/info.toml'.format(glob.escape(self.problem_id))))
if len(info_tomls) != 1:
log.error("the problem %s not found or broken", self.problem_id)
raise RuntimeError()
return info_tomls[0].parent

def get_url(self) -> str:
return 'https://judge.yosupo.jp/problem/{}'.format(self.problem_id)
Expand All @@ -127,11 +133,9 @@ def from_url(cls, url: str) -> Optional['LibraryCheckerProblem']:
return cls(problem_id=m.group(1))
return None

def download_checker_cpp(self) -> bytes:
LibraryCheckerService._update_cloned_repository()
path = self._get_problem_directory_path()
with open(str(path / "checker.cpp"), "rb") as fh:
return fh.read()
def download_checker_binary(self) -> pathlib.Path:
self._generate_test_cases_in_cloned_repository(compile_checker=True)
return self._get_problem_directory_path() / "checker"


onlinejudge.dispatch.services += [LibraryCheckerService]
Expand Down