kattis-cli 1.0.1__py3-none-any.whl → 1.0.3__py3-none-any.whl
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/main.py +19 -4
- kattis_cli/test_solution.py +34 -6
- kattis_cli/utils/utility.py +1 -33
- {kattis_cli-1.0.1.dist-info → kattis_cli-1.0.3.dist-info}/METADATA +31 -10
- {kattis_cli-1.0.1.dist-info → kattis_cli-1.0.3.dist-info}/RECORD +8 -8
- {kattis_cli-1.0.1.dist-info → kattis_cli-1.0.3.dist-info}/WHEEL +1 -1
- {kattis_cli-1.0.1.dist-info → kattis_cli-1.0.3.dist-info}/LICENSE +0 -0
- {kattis_cli-1.0.1.dist-info → kattis_cli-1.0.3.dist-info}/entry_points.txt +0 -0
kattis_cli/main.py
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
""" Main module for the kattis_cli package.
|
|
2
|
-
|
|
1
|
+
""" Main module for the kattis_cli package.
|
|
2
|
+
This is the main.py file for the kattis_cli package.
|
|
3
3
|
|
|
4
|
+
Change the contents here instead of main.py.
|
|
5
|
+
build.sh script copies the contents of this file to main.py.
|
|
6
|
+
|
|
7
|
+
Change the __version__ to match in pyproject.toml
|
|
8
|
+
Has to be higher than the pypi version.
|
|
9
|
+
"""
|
|
10
|
+
__version__ = '1.0.3'
|
|
11
|
+
|
|
12
|
+
from math import inf
|
|
4
13
|
from typing import Tuple
|
|
5
14
|
from rich.console import Console
|
|
6
15
|
import click
|
|
@@ -14,10 +23,12 @@ import kattis_cli.kattis_setup as kattis_setup
|
|
|
14
23
|
|
|
15
24
|
|
|
16
25
|
@click.group()
|
|
26
|
+
@click.version_option(version=__version__, prog_name='kattis-cli')
|
|
17
27
|
def main() -> None:
|
|
18
28
|
"""
|
|
19
29
|
CLI for downloading, testing and submitting Kattis problems.
|
|
20
30
|
"""
|
|
31
|
+
pass
|
|
21
32
|
|
|
22
33
|
|
|
23
34
|
@main.command(help='Download sample data & metadata.')
|
|
@@ -33,7 +44,7 @@ def get(problemid: str) -> None:
|
|
|
33
44
|
except requests.exceptions.InvalidURL:
|
|
34
45
|
console.print(
|
|
35
46
|
f"""Sample data for Problem ID: [bold blue]
|
|
36
|
-
{problemid}[/bold blue] not found.")
|
|
47
|
+
{problemid}[/bold blue] not found.")
|
|
37
48
|
""")
|
|
38
49
|
console.print(
|
|
39
50
|
f"Downloading metadata: [bold blue]{problemid}[/bold blue]")
|
|
@@ -52,11 +63,14 @@ def info(problemid: str) -> None:
|
|
|
52
63
|
@click.option('-p', '--problemid', default='', help='Problem ID')
|
|
53
64
|
@click.option('-l', '--language', default='', help='Sets language')
|
|
54
65
|
@click.option('-m', '--mainclass', default='', help='Sets mainclass/mainfile')
|
|
66
|
+
@click.option('-a', '--accuracy', default=inf,
|
|
67
|
+
help='Decimal places for float comparison')
|
|
55
68
|
@click.argument('files', nargs=-1, required=False)
|
|
56
69
|
def test(
|
|
57
70
|
problemid: str,
|
|
58
71
|
language: str,
|
|
59
72
|
mainclass: str,
|
|
73
|
+
accuracy: float,
|
|
60
74
|
files: Tuple[str]) -> None:
|
|
61
75
|
"""Test solution with sample files.
|
|
62
76
|
"""
|
|
@@ -74,7 +88,8 @@ def test(
|
|
|
74
88
|
mainclass,
|
|
75
89
|
root_folder,
|
|
76
90
|
_files,
|
|
77
|
-
lang_config
|
|
91
|
+
lang_config,
|
|
92
|
+
accuracy)
|
|
78
93
|
|
|
79
94
|
|
|
80
95
|
@main.command(help='Submit a solution to Kattis.')
|
kattis_cli/test_solution.py
CHANGED
|
@@ -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]
|
kattis_cli/utils/utility.py
CHANGED
|
@@ -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,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: kattis-cli
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
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
|
|
@@ -70,21 +75,25 @@ If you've Python version 3.8 or higher, you can skip creating virtual environmen
|
|
|
70
75
|
```bash
|
|
71
76
|
pip install kattis-cli
|
|
72
77
|
python -m pip install kattis-cli
|
|
78
|
+
kattis --version
|
|
73
79
|
```
|
|
74
80
|
|
|
75
81
|
- on Windows add the path shown in the output of the above command to your PATH environment variable
|
|
76
82
|
|
|
77
|
-
|
|
78
|
-
## Update Kattis-CLI
|
|
83
|
+
## Update/Upgrade Kattis-CLI
|
|
79
84
|
|
|
80
85
|
- remove or rename **.kattis-cli.toml** file in your home directory
|
|
81
86
|
- activate virtual environment if you've created one for kattis-cli
|
|
82
87
|
|
|
83
88
|
```bash
|
|
89
|
+
kattis --version
|
|
84
90
|
pip install kattis-cli --upgrade
|
|
85
91
|
python -m pip install kattis-cli --upgrade
|
|
86
92
|
```
|
|
87
93
|
|
|
94
|
+
- on Windows add the path shown in the output of the above command to your PATH environment variable
|
|
95
|
+
|
|
96
|
+
|
|
88
97
|
## Kattis configuration
|
|
89
98
|
|
|
90
99
|
- run the following command and enter your Kattis credentials
|
|
@@ -108,13 +117,13 @@ kattis --help
|
|
|
108
117
|
- problem id can be found in the last part of the URL of the problem
|
|
109
118
|
- example: [https://open.kattis.com/problems/cold](https://open.kattis.com/problems/cold) => problem id: **cold**
|
|
110
119
|
|
|
111
|
-

|
|
120
|
+

|
|
112
121
|
|
|
113
122
|
```bash
|
|
114
123
|
kattis get <problem_id>
|
|
115
124
|
```
|
|
116
125
|
|
|
117
|
-

|
|
126
|
+

|
|
118
127
|
|
|
119
128
|
### Display problem metadata
|
|
120
129
|
|
|
@@ -123,10 +132,12 @@ cd <problem_id>
|
|
|
123
132
|
kattis info
|
|
124
133
|
```
|
|
125
134
|
|
|
126
|
-

|
|
135
|
+

|
|
127
136
|
|
|
128
137
|
### Test a solution locally
|
|
129
138
|
|
|
139
|
+

|
|
140
|
+
|
|
130
141
|
- currently the following languages have been tested: Python 3, C++, NodeJS, C, Java
|
|
131
142
|
- make sure CLI compilers are in your PATH
|
|
132
143
|
- make sure python3 files have first line shebang: !/usr/bin/env python3
|
|
@@ -136,10 +147,20 @@ kattis info
|
|
|
136
147
|
|
|
137
148
|
```bash
|
|
138
149
|
cd <problem_id>
|
|
139
|
-
kattis test
|
|
150
|
+
kattis test # for exact comparion of answers (string and int)
|
|
151
|
+
kattis test -a 6 # Answer accepted upto 6 decimal places of accuracy
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Testing floating point results
|
|
155
|
+
|
|
156
|
+
- for floating point ouput, problem provides the tolerance or accuracy upto certain decimal points
|
|
157
|
+
- one can use `-a <N>` switch after kattis test command to provide the decimal places of accuracy
|
|
158
|
+
- e.g., the following command checks for accuracy upto 6 decimal points or absolute error upto $10^-6$
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
kattis test -a 6
|
|
140
162
|
```
|
|
141
163
|
|
|
142
|
-

|
|
143
164
|
|
|
144
165
|
### Submit a problem
|
|
145
166
|
|
|
@@ -3,16 +3,16 @@ kattis_cli/__init__.py,sha256=afN92pog2fGyicY6KNBofYbCBYbYj4Fpi_INUSpsc-E,402
|
|
|
3
3
|
kattis_cli/download.py,sha256=aa0hBg_6Ou8SGrufgkNUjfWEHdmiu7U-W4d-yWHZNOA,5877
|
|
4
4
|
kattis_cli/kattis.py,sha256=t5fog-tx1f1GeM-D3aa2YhuhxTnai_kV-x7miZbs6SI,13767
|
|
5
5
|
kattis_cli/kattis_setup.py,sha256=rq_-Fz8oafxFJ8MOcxJqHQT8-bezgVHZXY2hm4EQF3U,4357
|
|
6
|
-
kattis_cli/main.py,sha256=
|
|
6
|
+
kattis_cli/main.py,sha256=hTr63pQfRXxxIL-4G6EZ1g6qDFgaPd8PI35850PL0vs,4461
|
|
7
7
|
kattis_cli/settings.py,sha256=d5q4dYj9VqDSqPalleh2oZWtND-1bPB0T2IwdajFrBg,591
|
|
8
|
-
kattis_cli/test_solution.py,sha256=
|
|
8
|
+
kattis_cli/test_solution.py,sha256=KKYedt3ISQYLIoahLPgPizpApLQnOrBhmkew5aHW9BM,6627
|
|
9
9
|
kattis_cli/ui.py,sha256=dI06yncjm8sdLQkupPxGRODvQ6Gbawwuqn-67FrWg6I,2682
|
|
10
10
|
kattis_cli/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
11
|
kattis_cli/utils/config.py,sha256=cr5ssEVWolDbqP8krts0YSK5vSLatKTveeHBRNsLRC8,2277
|
|
12
12
|
kattis_cli/utils/run_program.py,sha256=NWQ6vtTeWgkaW75r91FIHGXR5cAbeu8yMb5hwzpYFsg,2613
|
|
13
|
-
kattis_cli/utils/utility.py,sha256=
|
|
14
|
-
kattis_cli-1.0.
|
|
15
|
-
kattis_cli-1.0.
|
|
16
|
-
kattis_cli-1.0.
|
|
17
|
-
kattis_cli-1.0.
|
|
18
|
-
kattis_cli-1.0.
|
|
13
|
+
kattis_cli/utils/utility.py,sha256=JkypTfPOlDSxmZsh7KKcAVG2BC58t66corMBtcdvU7E,10532
|
|
14
|
+
kattis_cli-1.0.3.dist-info/LICENSE,sha256=JmBa4SEKBCDWEgiOZcISU4tUCpli6xSpVlSYgkBXSNQ,1067
|
|
15
|
+
kattis_cli-1.0.3.dist-info/METADATA,sha256=pOGeql7dMWdo0fVMb6N2TMYcb3zEHgq4a1aDDyzmfGw,6598
|
|
16
|
+
kattis_cli-1.0.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
17
|
+
kattis_cli-1.0.3.dist-info/entry_points.txt,sha256=kyzGN20VqUPR_H0J_jJUKT-10-cAMFLVegQ6C7tbHss,47
|
|
18
|
+
kattis_cli-1.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|