kattis-cli 1.0.1__tar.gz → 1.0.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kattis-cli
3
- Version: 1.0.1
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
- Based on Official Kattis CLI: [https://github.com/Kattis/kattis-cli](https://github.com/Kattis/kattis-cli)
30
+ Inspired by the official Kattis CLI: [https://github.com/Kattis/kattis-cli](https://github.com/Kattis/kattis-cli)
31
+
32
+ ![Tests](https://github.com/rambasnet/kattis-cli/actions/workflows/ci-test.yml/badge.svg)
33
+ [![PyPI version](https://badge.fury.io/py/kattis-cli.svg)](https://badge.fury.io/py/kattis-cli)
34
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/kattis-cli)](https://pypi.org/project/kattis-cli/)
35
+ [![PyPI - License](https://img.shields.io/pypi/l/kattis-cli)](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 code)
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
- ![Problem id](images/problemid.png)
120
+ ![Problem id](./images/problemid.png)
112
121
 
113
122
  ```bash
114
123
  kattis get <problem_id>
115
124
  ```
116
125
 
117
- ![Get problem id from URL](images/kattis_get.png)
126
+ ![Get problem id from URL](./images/kattis_get.png)
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
- ![Problem info](images/kattis_info.png)
135
+ ![Problem info](./images/kattis_info.png)
127
136
 
128
137
  ### Test a solution locally
129
138
 
139
+ ![Test](images/kattis_test.png)
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
- ![Test](images/kattis_test.png)
143
164
 
144
165
  ### Submit a problem
145
166
 
@@ -1,11 +1,16 @@
1
1
  # Kattis-CLI
2
2
 
3
3
  Kattis CLI - download, test and submit Kattis problems using CLI.
4
- Based on Official Kattis CLI: [https://github.com/Kattis/kattis-cli](https://github.com/Kattis/kattis-cli)
4
+ Inspired by the official Kattis CLI: [https://github.com/Kattis/kattis-cli](https://github.com/Kattis/kattis-cli)
5
+
6
+ ![Tests](https://github.com/rambasnet/kattis-cli/actions/workflows/ci-test.yml/badge.svg)
7
+ [![PyPI version](https://badge.fury.io/py/kattis-cli.svg)](https://badge.fury.io/py/kattis-cli)
8
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/kattis-cli)](https://pypi.org/project/kattis-cli/)
9
+ [![PyPI - License](https://img.shields.io/pypi/l/kattis-cli)](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 code)
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
@@ -44,21 +49,25 @@ If you've Python version 3.8 or higher, you can skip creating virtual environmen
44
49
  ```bash
45
50
  pip install kattis-cli
46
51
  python -m pip install kattis-cli
52
+ kattis --version
47
53
  ```
48
54
 
49
55
  - on Windows add the path shown in the output of the above command to your PATH environment variable
50
56
 
51
-
52
- ## Update Kattis-CLI
57
+ ## Update/Upgrade Kattis-CLI
53
58
 
54
59
  - remove or rename **.kattis-cli.toml** file in your home directory
55
60
  - activate virtual environment if you've created one for kattis-cli
56
61
 
57
62
  ```bash
63
+ kattis --version
58
64
  pip install kattis-cli --upgrade
59
65
  python -m pip install kattis-cli --upgrade
60
66
  ```
61
67
 
68
+ - on Windows add the path shown in the output of the above command to your PATH environment variable
69
+
70
+
62
71
  ## Kattis configuration
63
72
 
64
73
  - run the following command and enter your Kattis credentials
@@ -82,13 +91,13 @@ kattis --help
82
91
  - problem id can be found in the last part of the URL of the problem
83
92
  - example: [https://open.kattis.com/problems/cold](https://open.kattis.com/problems/cold) => problem id: **cold**
84
93
 
85
- ![Problem id](images/problemid.png)
94
+ ![Problem id](./images/problemid.png)
86
95
 
87
96
  ```bash
88
97
  kattis get <problem_id>
89
98
  ```
90
99
 
91
- ![Get problem id from URL](images/kattis_get.png)
100
+ ![Get problem id from URL](./images/kattis_get.png)
92
101
 
93
102
  ### Display problem metadata
94
103
 
@@ -97,10 +106,12 @@ cd <problem_id>
97
106
  kattis info
98
107
  ```
99
108
 
100
- ![Problem info](images/kattis_info.png)
109
+ ![Problem info](./images/kattis_info.png)
101
110
 
102
111
  ### Test a solution locally
103
112
 
113
+ ![Test](images/kattis_test.png)
114
+
104
115
  - currently the following languages have been tested: Python 3, C++, NodeJS, C, Java
105
116
  - make sure CLI compilers are in your PATH
106
117
  - make sure python3 files have first line shebang: !/usr/bin/env python3
@@ -110,10 +121,20 @@ kattis info
110
121
 
111
122
  ```bash
112
123
  cd <problem_id>
113
- kattis test
124
+ kattis test # for exact comparion of answers (string and int)
125
+ kattis test -a 6 # Answer accepted upto 6 decimal places of accuracy
126
+ ```
127
+
128
+ ### Testing floating point results
129
+
130
+ - for floating point ouput, problem provides the tolerance or accuracy upto certain decimal points
131
+ - one can use `-a <N>` switch after kattis test command to provide the decimal places of accuracy
132
+ - e.g., the following command checks for accuracy upto 6 decimal points or absolute error upto $10^-6$
133
+
134
+ ```bash
135
+ kattis test -a 6
114
136
  ```
115
137
 
116
- ![Test](images/kattis_test.png)
117
138
 
118
139
  ### Submit a problem
119
140
 
@@ -1,6 +1,15 @@
1
- """ Main module for the kattis_cli package."""
2
- __version__ = '0.1.6'
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.')
@@ -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 expected == ans.encode('utf-8').strip():
130
- result = "[bold green]✅[/bold green]"
131
- count += 1
132
- else:
133
- result = "[bold red]❌[/bold red]"
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
- if is_python2(files):
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
  [tool.poetry]
2
2
  name = "kattis-cli"
3
- version = "1.0.1"
3
+ version = "1.0.3"
4
4
  authors = ["Ram Basnet <rambasnet@gmail.com>"]
5
5
  description = "A command-line tool for Kattis"
6
6
  readme = "README.md"
File without changes
File without changes