kattis-cli 1.0.1__tar.gz → 1.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/PKG-INFO +8 -3
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/README.md +7 -2
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/kattis_cli/main.py +7 -2
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/kattis_cli/test_solution.py +34 -6
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/kattis_cli/utils/utility.py +1 -33
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/pyproject.toml +1 -1
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/LICENSE +0 -0
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/kattis_cli/.kattis-cli.toml +0 -0
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/kattis_cli/__init__.py +0 -0
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/kattis_cli/download.py +0 -0
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/kattis_cli/kattis.py +0 -0
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/kattis_cli/kattis_setup.py +0 -0
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/kattis_cli/settings.py +0 -0
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/kattis_cli/ui.py +0 -0
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/kattis_cli/utils/__init__.py +0 -0
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/kattis_cli/utils/config.py +0 -0
- {kattis_cli-1.0.1 → kattis_cli-1.0.2}/kattis_cli/utils/run_program.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: kattis-cli
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
4
4
|
Summary: A command-line tool for Kattis
|
|
5
5
|
Home-page: https://github.com/rambasnet/kattis-cli
|
|
6
6
|
Author: Ram Basnet
|
|
@@ -27,11 +27,16 @@ Description-Content-Type: text/markdown
|
|
|
27
27
|
# Kattis-CLI
|
|
28
28
|
|
|
29
29
|
Kattis CLI - download, test and submit Kattis problems using CLI.
|
|
30
|
-
|
|
30
|
+
Inspired by the official Kattis CLI: [https://github.com/Kattis/kattis-cli](https://github.com/Kattis/kattis-cli)
|
|
31
|
+
|
|
32
|
+

|
|
33
|
+
[](https://badge.fury.io/py/kattis-cli)
|
|
34
|
+
[](https://pypi.org/project/kattis-cli/)
|
|
35
|
+
[](https://pypi.org/project/kattis-cli/)
|
|
31
36
|
|
|
32
37
|
## Requirements
|
|
33
38
|
|
|
34
|
-
- Python 3.8+ (PyPy preferred as Kattis uses PyPy to run your
|
|
39
|
+
- Python 3.8+ (PyPy preferred as Kattis uses PyPy to run your Python3 solutions)
|
|
35
40
|
- [Kattis account](https://open.kattis.com/login/email)
|
|
36
41
|
|
|
37
42
|
## Windows
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
# Kattis-CLI
|
|
2
2
|
|
|
3
3
|
Kattis CLI - download, test and submit Kattis problems using CLI.
|
|
4
|
-
|
|
4
|
+
Inspired by the official Kattis CLI: [https://github.com/Kattis/kattis-cli](https://github.com/Kattis/kattis-cli)
|
|
5
|
+
|
|
6
|
+

|
|
7
|
+
[](https://badge.fury.io/py/kattis-cli)
|
|
8
|
+
[](https://pypi.org/project/kattis-cli/)
|
|
9
|
+
[](https://pypi.org/project/kattis-cli/)
|
|
5
10
|
|
|
6
11
|
## Requirements
|
|
7
12
|
|
|
8
|
-
- Python 3.8+ (PyPy preferred as Kattis uses PyPy to run your
|
|
13
|
+
- Python 3.8+ (PyPy preferred as Kattis uses PyPy to run your Python3 solutions)
|
|
9
14
|
- [Kattis account](https://open.kattis.com/login/email)
|
|
10
15
|
|
|
11
16
|
## Windows
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
""" Main module for the kattis_cli package."""
|
|
2
|
-
__version__ = '0.
|
|
2
|
+
__version__ = '1.0.2'
|
|
3
3
|
|
|
4
|
+
from math import inf
|
|
4
5
|
from typing import Tuple
|
|
5
6
|
from rich.console import Console
|
|
6
7
|
import click
|
|
@@ -52,11 +53,14 @@ def info(problemid: str) -> None:
|
|
|
52
53
|
@click.option('-p', '--problemid', default='', help='Problem ID')
|
|
53
54
|
@click.option('-l', '--language', default='', help='Sets language')
|
|
54
55
|
@click.option('-m', '--mainclass', default='', help='Sets mainclass/mainfile')
|
|
56
|
+
@click.option('-a', '--accuracy', default=inf,
|
|
57
|
+
help='Decimal places for float comparison')
|
|
55
58
|
@click.argument('files', nargs=-1, required=False)
|
|
56
59
|
def test(
|
|
57
60
|
problemid: str,
|
|
58
61
|
language: str,
|
|
59
62
|
mainclass: str,
|
|
63
|
+
accuracy: float,
|
|
60
64
|
files: Tuple[str]) -> None:
|
|
61
65
|
"""Test solution with sample files.
|
|
62
66
|
"""
|
|
@@ -74,7 +78,8 @@ def test(
|
|
|
74
78
|
mainclass,
|
|
75
79
|
root_folder,
|
|
76
80
|
_files,
|
|
77
|
-
lang_config
|
|
81
|
+
lang_config,
|
|
82
|
+
accuracy)
|
|
78
83
|
|
|
79
84
|
|
|
80
85
|
@main.command(help='Submit a solution to Kattis.')
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Tester module for Kattis.
|
|
2
2
|
"""
|
|
3
3
|
|
|
4
|
+
from math import inf
|
|
4
5
|
from typing import Any, List, Dict
|
|
5
6
|
import glob
|
|
6
7
|
import time
|
|
@@ -19,13 +20,33 @@ from kattis_cli import kattis
|
|
|
19
20
|
from kattis_cli.utils import run_program, utility
|
|
20
21
|
|
|
21
22
|
|
|
23
|
+
def compare_floats(expected: str, ans: str, places: float) -> bool:
|
|
24
|
+
"""Compare two floating point numbers with given accuracy.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
expected (str): expected result
|
|
28
|
+
ans (str): actual result
|
|
29
|
+
places (float): decimal places for approximation
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
bool: True if the two numbers are equal within the given accuracy
|
|
33
|
+
"""
|
|
34
|
+
try:
|
|
35
|
+
flt_expected = float(expected)
|
|
36
|
+
flt_ans = float(ans)
|
|
37
|
+
return abs(flt_expected - flt_ans) <= 10**(-places)
|
|
38
|
+
except ValueError:
|
|
39
|
+
return False
|
|
40
|
+
|
|
41
|
+
|
|
22
42
|
def test_samples(
|
|
23
43
|
problemid: str,
|
|
24
44
|
loc_language: str,
|
|
25
45
|
mainclass: str,
|
|
26
46
|
problem_root_folder: str,
|
|
27
47
|
files: List[str],
|
|
28
|
-
lang_config: Dict[Any, Any]
|
|
48
|
+
lang_config: Dict[Any, Any],
|
|
49
|
+
accuracy: float = inf
|
|
29
50
|
) -> None:
|
|
30
51
|
"""Tests a problem by running all the .in files in
|
|
31
52
|
the problem folder and comparing the output to the .ans files.
|
|
@@ -126,11 +147,18 @@ def test_samples(
|
|
|
126
147
|
if code != 0:
|
|
127
148
|
ans = error
|
|
128
149
|
# console.print(f"{ans=} {error=}")
|
|
129
|
-
if
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
150
|
+
if accuracy == inf: # string comparison
|
|
151
|
+
if expected == ans.encode('utf-8').strip():
|
|
152
|
+
result = "[bold green]✅[/bold green]"
|
|
153
|
+
count += 1
|
|
154
|
+
else:
|
|
155
|
+
result = "[bold red]❌[/bold red]"
|
|
156
|
+
else: # floating point comparison
|
|
157
|
+
if compare_floats(expected.decode('utf-8'), ans, accuracy):
|
|
158
|
+
result = "[bold green]✅[/bold green]"
|
|
159
|
+
count += 1
|
|
160
|
+
else:
|
|
161
|
+
result = "[bold red]❌[/bold red]"
|
|
134
162
|
|
|
135
163
|
# UI Table Row ---
|
|
136
164
|
in_filename = Path(in_file).parts[-1]
|
|
@@ -66,7 +66,6 @@ GUESS_MAINFILE = {
|
|
|
66
66
|
'Common Lisp',
|
|
67
67
|
'Pascal',
|
|
68
68
|
'PHP',
|
|
69
|
-
'Python 2',
|
|
70
69
|
'Python 3',
|
|
71
70
|
'Ruby',
|
|
72
71
|
'Rust',
|
|
@@ -77,7 +76,6 @@ GUESS_MAINFILE = {
|
|
|
77
76
|
# mapping is used for .kattis-cli.toml file configuration
|
|
78
77
|
LOCAL_TO_KATTIS = {
|
|
79
78
|
'python3': 'Python 3',
|
|
80
|
-
'python2': 'Python 2',
|
|
81
79
|
'java': 'Java',
|
|
82
80
|
'cpp': 'C++',
|
|
83
81
|
'c++': 'C++',
|
|
@@ -132,40 +130,10 @@ def guess_language(ext: str, files: List[str]) -> str:
|
|
|
132
130
|
else:
|
|
133
131
|
return "cpp"
|
|
134
132
|
if ext == ".py":
|
|
135
|
-
|
|
136
|
-
return "python2"
|
|
137
|
-
else:
|
|
138
|
-
return "python3"
|
|
133
|
+
return "python3"
|
|
139
134
|
return LANGUAGE_GUESS.get(ext, '')
|
|
140
135
|
|
|
141
136
|
|
|
142
|
-
def is_python2(files: List[str]) -> bool:
|
|
143
|
-
"""Check if python2.
|
|
144
|
-
|
|
145
|
-
Args:
|
|
146
|
-
files (List[str]): Tuple of files.
|
|
147
|
-
|
|
148
|
-
Returns:
|
|
149
|
-
bool: True if python2, False otherwise.
|
|
150
|
-
"""
|
|
151
|
-
python2 = re.compile(r'^\s*\bprint\b *[^ \(\),\]]|\braw_input\b')
|
|
152
|
-
for filename in files:
|
|
153
|
-
try:
|
|
154
|
-
with open(filename, 'r', encoding='utf-8') as f:
|
|
155
|
-
for index, line in enumerate(f):
|
|
156
|
-
# print(index, line)
|
|
157
|
-
if index == 0 and line.startswith('#!'):
|
|
158
|
-
if 'python2' in line:
|
|
159
|
-
return True
|
|
160
|
-
if 'python3' in line:
|
|
161
|
-
return False
|
|
162
|
-
if python2.search(line.split('#')[0]):
|
|
163
|
-
return True
|
|
164
|
-
except IOError:
|
|
165
|
-
return False
|
|
166
|
-
return False
|
|
167
|
-
|
|
168
|
-
|
|
169
137
|
# flake8: noqa: C901
|
|
170
138
|
def guess_mainfile(
|
|
171
139
|
kat_language: str,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|