Skip to content

Commit 4a148ac

Browse files
authored
Merge branch 'master' into dev
2 parents fe30fce + e6ace5c commit 4a148ac

33 files changed

+1850
-365
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Python package
1+
name: Test
22

33
on:
44
- push
@@ -8,26 +8,27 @@ jobs:
88
build:
99
strategy:
1010
matrix:
11-
platform: [ubuntu-20.04, windows-latest]
11+
platform: [ubuntu-22.04, windows-latest]
1212
runs-on: ${{ matrix.platform }}
1313
steps:
1414
- uses: actions/checkout@v3
15-
- name: Set up Python 3.6
15+
- name: Set up Python 3.6 (Windows)
16+
if: matrix.platform == 'windows-latest'
1617
uses: actions/setup-python@v4
1718
with:
18-
python-version: '3.6'
19+
python-version: "3.6"
1920
- name: Set up Python 3.8
2021
uses: actions/setup-python@v4
2122
with:
22-
python-version: '3.8'
23+
python-version: "3.8"
2324
- name: Set up Python 3.10
2425
uses: actions/setup-python@v4
2526
with:
26-
python-version: '3.10'
27+
python-version: "3.10"
2728
- name: Set up Python 3.12
2829
uses: actions/setup-python@v4
2930
with:
30-
python-version: '3.12'
31+
python-version: "3.12"
3132
- name: Install dependencies
3233
run: |
3334
python -m pip install --upgrade pip

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
config.py
2+
*.cpp
23
*.in
34
*.out
45
*.exe

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[MASTER]
2-
py-version=3.5
2+
py-version=3.6
33
disable=R0902,R0903,R0913,R0917,R0912

cyaron/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from random import choice, randint, random, randrange, uniform
1010

11-
#from .visual import visualize
11+
# from .visual import visualize
1212
from . import log
1313
from .compare import Compare
1414
from .consts import *
@@ -21,3 +21,4 @@
2121
from .string import String
2222
from .utils import *
2323
from .vector import Vector
24+
from .query import RangeQuery

cyaron/compare.py

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
class CompareMismatch(ValueError):
15+
1516
def __init__(self, name, mismatch):
1617
super(CompareMismatch, self).__init__(name, mismatch)
1718
self.name = name
@@ -22,6 +23,7 @@ def __str__(self):
2223

2324

2425
class Compare:
26+
2527
@staticmethod
2628
def __compare_two(name, content, std, grader):
2729
(result, info) = CYaRonGraders.invoke(grader, content, std)
@@ -67,21 +69,20 @@ def output(cls, *files, **kwargs):
6769
max_workers = kwargs["max_workers"]
6870
job_pool = kwargs["job_pool"]
6971
if kwargs["stop_on_incorrect"] is not None:
70-
log.warn("parameter stop_on_incorrect is deprecated and has no effect.")
72+
log.warn(
73+
"parameter stop_on_incorrect is deprecated and has no effect.")
7174

7275
if (max_workers is None or max_workers >= 0) and job_pool is None:
7376
max_workers = cls.__normal_max_workers(max_workers)
7477
try:
7578
from concurrent.futures import ThreadPoolExecutor
7679

7780
with ThreadPoolExecutor(max_workers=max_workers) as job_pool:
78-
return cls.output(
79-
*files,
80-
std=std,
81-
grader=grader,
82-
max_workers=max_workers,
83-
job_pool=job_pool
84-
)
81+
return cls.output(*files,
82+
std=std,
83+
grader=grader,
84+
max_workers=max_workers,
85+
job_pool=job_pool)
8586
except ImportError:
8687
pass
8788

@@ -124,47 +125,44 @@ def program(cls, *programs, **kwargs):
124125
max_workers = kwargs["max_workers"]
125126
job_pool = kwargs["job_pool"]
126127
if kwargs["stop_on_incorrect"] is not None:
127-
log.warn("parameter stop_on_incorrect is deprecated and has no effect.")
128+
log.warn(
129+
"parameter stop_on_incorrect is deprecated and has no effect.")
128130

129131
if (max_workers is None or max_workers >= 0) and job_pool is None:
130132
max_workers = cls.__normal_max_workers(max_workers)
131133
try:
132134
from concurrent.futures import ThreadPoolExecutor
133135

134136
with ThreadPoolExecutor(max_workers=max_workers) as job_pool:
135-
return cls.program(
136-
*programs,
137-
input=input,
138-
std=std,
139-
std_program=std_program,
140-
grader=grader,
141-
max_workers=max_workers,
142-
job_pool=job_pool
143-
)
137+
return cls.program(*programs,
138+
input=input,
139+
std=std,
140+
std_program=std_program,
141+
grader=grader,
142+
max_workers=max_workers,
143+
job_pool=job_pool)
144144
except ImportError:
145145
pass
146146

147147
if not isinstance(input, IO):
148-
raise TypeError(
149-
"expect {}, got {}".format(type(IO).__name__, type(input).__name__)
150-
)
148+
raise TypeError("expect {}, got {}".format(
149+
type(IO).__name__,
150+
type(input).__name__))
151151
input.flush_buffer()
152152
input.input_file.seek(0)
153153

154154
if std_program is not None:
155155

156156
def get_std():
157-
with open(
158-
os.dup(input.input_file.fileno()), "r", newline="\n"
159-
) as input_file:
157+
with open(os.dup(input.input_file.fileno()), "r",
158+
newline="\n") as input_file:
160159
content = make_unicode(
161160
subprocess.check_output(
162161
std_program,
163162
shell=(not list_like(std_program)),
164163
stdin=input.input_file,
165164
universal_newlines=True,
166-
)
167-
)
165+
))
168166
input_file.seek(0)
169167
return content
170168

@@ -188,24 +186,19 @@ def get_std():
188186

189187
def do(program_name):
190188
timeout = None
191-
if (
192-
list_like(program_name)
193-
and len(program_name) == 2
194-
and int_like(program_name[-1])
195-
):
189+
if (list_like(program_name) and len(program_name) == 2
190+
and int_like(program_name[-1])):
196191
program_name, timeout = program_name
197-
with open(
198-
os.dup(input.input_file.fileno()), "r", newline="\n"
199-
) as input_file:
192+
with open(os.dup(input.input_file.fileno()), "r",
193+
newline="\n") as input_file:
200194
if timeout is None:
201195
content = make_unicode(
202196
subprocess.check_output(
203197
program_name,
204198
shell=(not list_like(program_name)),
205199
stdin=input_file,
206200
universal_newlines=True,
207-
)
208-
)
201+
))
209202
else:
210203
content = make_unicode(
211204
subprocess.check_output(
@@ -214,8 +207,7 @@ def do(program_name):
214207
stdin=input_file,
215208
universal_newlines=True,
216209
timeout=timeout,
217-
)
218-
)
210+
))
219211
input_file.seek(0)
220212
cls.__compare_two(program_name, content, std, grader)
221213

cyaron/consts.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import absolute_import
22
import math
33
import string
4-
54
"""Constants Package.
65
Constants:
76
ALPHABET_SMALL -> All the lower ascii letters
@@ -18,7 +17,7 @@
1817
ALPHABET_CAPITAL = string.ascii_uppercase
1918
ALPHABET = ALPHABET_SMALL + ALPHABET_CAPITAL
2019
NUMBERS = string.digits
21-
SENTENCE_SEPARATORS = ',,,,,,,;;:' # 70% ',' 20% ';' 10% ':'
22-
SENTENCE_TERMINATORS = '....!' # 80% '.' 20% '!'
20+
SENTENCE_SEPARATORS = ',,,,,,,;;:' # 70% ',' 20% ';' 10% ':'
21+
SENTENCE_TERMINATORS = '....!' # 80% '.' 20% '!'
2322

2423
DEFAULT_GRADER = "NOIPStyle"

cyaron/graders/fulltext.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
from .graderregistry import CYaRonGraders
33
from .mismatch import HashMismatch
44

5+
56
@CYaRonGraders.grader("FullText")
67
def fulltext(content, std):
78
content_hash = hashlib.sha256(content.encode('utf-8')).hexdigest()
89
std_hash = hashlib.sha256(std.encode('utf-8')).hexdigest()
9-
return (True, None) if content_hash == std_hash else (False, HashMismatch(content, std, content_hash, std_hash))
10-
10+
return (True, None) if content_hash == std_hash else (
11+
False, HashMismatch(content, std, content_hash, std_hash))

cyaron/graders/graderregistry.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ class GraderRegistry:
22
_registry = dict()
33

44
def grader(self, name):
5+
56
def wrapper(func):
67
self._registry[name] = func
78
return func
@@ -15,4 +16,4 @@ def check(self, name):
1516
return name in self._registry
1617

1718

18-
CYaRonGraders = GraderRegistry()
19+
CYaRonGraders = GraderRegistry()

cyaron/graders/mismatch.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class Mismatch(ValueError):
22
"""exception for content mismatch"""
3+
34
def __init__(self, content, std, *args):
45
"""
56
content -> content got
@@ -9,25 +10,38 @@ def __init__(self, content, std, *args):
910
self.content = content
1011
self.std = std
1112

13+
1214
class HashMismatch(Mismatch):
1315
"""exception for hash mismatch"""
16+
1417
def __init__(self, content, std, content_hash, std_hash):
1518
"""
1619
content -> content got
1720
std -> content expected
1821
content_hash -> hash of content
1922
std_hash -> hash of std
2023
"""
21-
super(HashMismatch, self).__init__(content, std, content_hash, std_hash)
24+
super(HashMismatch, self).__init__(content, std, content_hash,
25+
std_hash)
2226
self.content_hash = content_hash
2327
self.std_hash = std_hash
2428

2529
def __str__(self):
26-
return "Hash mismatch: read %s, expected %s" % (self.content_hash, self.std_hash)
30+
return "Hash mismatch: read %s, expected %s" % (self.content_hash,
31+
self.std_hash)
32+
2733

2834
class TextMismatch(Mismatch):
2935
"""exception for text mismatch"""
30-
def __init__(self, content, std, err_msg, lineno=None, colno=None, content_token=None, std_token=None):
36+
37+
def __init__(self,
38+
content,
39+
std,
40+
err_msg,
41+
lineno=None,
42+
colno=None,
43+
content_token=None,
44+
std_token=None):
3145
"""
3246
content -> content got
3347
std -> content expected
@@ -37,7 +51,8 @@ def __init__(self, content, std, err_msg, lineno=None, colno=None, content_token
3751
content_token -> the token of content mismatch
3852
std_token -> the token of std
3953
"""
40-
super(TextMismatch, self).__init__(content, std, err_msg, lineno, colno, content_token, std_token)
54+
super(TextMismatch, self).__init__(content, std, err_msg, lineno,
55+
colno, content_token, std_token)
4156
self.err_msg = err_msg.format(lineno, colno, content_token, std_token)
4257
self.lineno = lineno
4358
self.colno = colno

cyaron/graders/noipstyle.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ def noipstyle(content, std):
2222
std_lines[i][j:j + 5]))
2323
if len(std_lines[i]) > len(content_lines[i]):
2424
return False, TextMismatch(
25-
content, std, 'Too short on line {}.', i + 1, j + 1,
26-
content_lines[i][j:j + 5], std_lines[i][j:j + 5])
25+
content,
26+
std,
27+
'Too short on line {}.',
28+
i + 1,
29+
)
2730
if len(std_lines[i]) < len(content_lines[i]):
2831
return False, TextMismatch(
29-
content, std, 'Too long on line {}.', i + 1, j + 1,
30-
content_lines[i][j:j + 5], std_lines[i][j:j + 5])
32+
content,
33+
std,
34+
'Too long on line {}.',
35+
i + 1,
36+
)
3137

3238
return True, None

0 commit comments

Comments
 (0)