kattis-cli 1.0.2__tar.gz → 1.0.4__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,10 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kattis-cli
3
- Version: 1.0.2
3
+ Version: 1.0.4
4
4
  Summary: A command-line tool for Kattis
5
5
  Home-page: https://github.com/rambasnet/kattis-cli
6
6
  Author: Ram Basnet
7
- Author-email: rambasnet@gmail.com
7
+ Author-email: rbasnet@coloradomesa.edu
8
8
  Requires-Python: >=3.8,<4.0
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: OS Independent
@@ -75,21 +75,25 @@ If you've Python version 3.8 or higher, you can skip creating virtual environmen
75
75
  ```bash
76
76
  pip install kattis-cli
77
77
  python -m pip install kattis-cli
78
+ kattis --version
78
79
  ```
79
80
 
80
81
  - on Windows add the path shown in the output of the above command to your PATH environment variable
81
82
 
82
-
83
- ## Update Kattis-CLI
83
+ ## Update/Upgrade Kattis-CLI
84
84
 
85
85
  - remove or rename **.kattis-cli.toml** file in your home directory
86
86
  - activate virtual environment if you've created one for kattis-cli
87
87
 
88
88
  ```bash
89
+ kattis --version
89
90
  pip install kattis-cli --upgrade
90
91
  python -m pip install kattis-cli --upgrade
91
92
  ```
92
93
 
94
+ - on Windows add the path shown in the output of the above command to your PATH environment variable
95
+
96
+
93
97
  ## Kattis configuration
94
98
 
95
99
  - run the following command and enter your Kattis credentials
@@ -113,13 +117,13 @@ kattis --help
113
117
  - problem id can be found in the last part of the URL of the problem
114
118
  - example: [https://open.kattis.com/problems/cold](https://open.kattis.com/problems/cold) => problem id: **cold**
115
119
 
116
- ![Problem id](images/problemid.png)
120
+ ![Problem id](./images/problemid.png)
117
121
 
118
122
  ```bash
119
123
  kattis get <problem_id>
120
124
  ```
121
125
 
122
- ![Get problem id from URL](images/kattis_get.png)
126
+ ![Get problem id from URL](./images/kattis_get.png)
123
127
 
124
128
  ### Display problem metadata
125
129
 
@@ -128,10 +132,12 @@ cd <problem_id>
128
132
  kattis info
129
133
  ```
130
134
 
131
- ![Problem info](images/kattis_info.png)
135
+ ![Problem info](./images/kattis_info.png)
132
136
 
133
137
  ### Test a solution locally
134
138
 
139
+ ![Test](images/kattis_test.png)
140
+
135
141
  - currently the following languages have been tested: Python 3, C++, NodeJS, C, Java
136
142
  - make sure CLI compilers are in your PATH
137
143
  - make sure python3 files have first line shebang: !/usr/bin/env python3
@@ -141,10 +147,20 @@ kattis info
141
147
 
142
148
  ```bash
143
149
  cd <problem_id>
144
- 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
145
162
  ```
146
163
 
147
- ![Test](images/kattis_test.png)
148
164
 
149
165
  ### Submit a problem
150
166
 
@@ -49,21 +49,25 @@ If you've Python version 3.8 or higher, you can skip creating virtual environmen
49
49
  ```bash
50
50
  pip install kattis-cli
51
51
  python -m pip install kattis-cli
52
+ kattis --version
52
53
  ```
53
54
 
54
55
  - on Windows add the path shown in the output of the above command to your PATH environment variable
55
56
 
56
-
57
- ## Update Kattis-CLI
57
+ ## Update/Upgrade Kattis-CLI
58
58
 
59
59
  - remove or rename **.kattis-cli.toml** file in your home directory
60
60
  - activate virtual environment if you've created one for kattis-cli
61
61
 
62
62
  ```bash
63
+ kattis --version
63
64
  pip install kattis-cli --upgrade
64
65
  python -m pip install kattis-cli --upgrade
65
66
  ```
66
67
 
68
+ - on Windows add the path shown in the output of the above command to your PATH environment variable
69
+
70
+
67
71
  ## Kattis configuration
68
72
 
69
73
  - run the following command and enter your Kattis credentials
@@ -87,13 +91,13 @@ kattis --help
87
91
  - problem id can be found in the last part of the URL of the problem
88
92
  - example: [https://open.kattis.com/problems/cold](https://open.kattis.com/problems/cold) => problem id: **cold**
89
93
 
90
- ![Problem id](images/problemid.png)
94
+ ![Problem id](./images/problemid.png)
91
95
 
92
96
  ```bash
93
97
  kattis get <problem_id>
94
98
  ```
95
99
 
96
- ![Get problem id from URL](images/kattis_get.png)
100
+ ![Get problem id from URL](./images/kattis_get.png)
97
101
 
98
102
  ### Display problem metadata
99
103
 
@@ -102,10 +106,12 @@ cd <problem_id>
102
106
  kattis info
103
107
  ```
104
108
 
105
- ![Problem info](images/kattis_info.png)
109
+ ![Problem info](./images/kattis_info.png)
106
110
 
107
111
  ### Test a solution locally
108
112
 
113
+ ![Test](images/kattis_test.png)
114
+
109
115
  - currently the following languages have been tested: Python 3, C++, NodeJS, C, Java
110
116
  - make sure CLI compilers are in your PATH
111
117
  - make sure python3 files have first line shebang: !/usr/bin/env python3
@@ -115,10 +121,20 @@ kattis info
115
121
 
116
122
  ```bash
117
123
  cd <problem_id>
118
- 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
119
136
  ```
120
137
 
121
- ![Test](images/kattis_test.png)
122
138
 
123
139
  ### Submit a problem
124
140
 
@@ -2,14 +2,12 @@
2
2
  and save them to data folders.
3
3
  """
4
4
 
5
- # import sys
6
5
  import shutil
7
6
  from typing import Any, Dict
8
7
  from pathlib import Path
9
8
  import requests
10
9
  import yaml
11
10
  from bs4 import BeautifulSoup
12
-
13
11
  from .utils import config, utility
14
12
  from . import settings
15
13
 
@@ -20,7 +20,7 @@ from rich.align import Align
20
20
  from rich.live import Live
21
21
  from rich.prompt import Confirm
22
22
 
23
- from kattis_cli.utils import utility
23
+ from kattis_cli.utils import languages
24
24
  from kattis_cli.utils import config
25
25
  from kattis_cli import ui
26
26
 
@@ -182,7 +182,7 @@ def confirm_or_die(problem: str, language: str,
182
182
  console.print('Language:', language)
183
183
  console.print('Files:', ', '.join(files))
184
184
  if mainclass:
185
- if language in utility.GUESS_MAINFILE:
185
+ if language in languages.GUESS_MAINFILE:
186
186
  console.print('Main file:', mainclass)
187
187
  else:
188
188
  console.print('Mainclass:', mainclass)
@@ -1,5 +1,13 @@
1
- """ Main module for the kattis_cli package."""
2
- __version__ = '1.0.2'
1
+ """ Main module for the kattis_cli package.
2
+ This is the main.py file for the kattis_cli package.
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.4'
3
11
 
4
12
  from math import inf
5
13
  from typing import Tuple
@@ -10,15 +18,17 @@ import kattis_cli.download as download
10
18
  import kattis_cli.ui as ui
11
19
  import kattis_cli.test_solution as test_solution
12
20
  import kattis_cli.kattis as kattis
13
- import kattis_cli.utils.utility as utility
21
+ import kattis_cli.utils.languages as languages
14
22
  import kattis_cli.kattis_setup as kattis_setup
15
23
 
16
24
 
17
25
  @click.group()
26
+ @click.version_option(version=__version__, prog_name='kattis-cli')
18
27
  def main() -> None:
19
28
  """
20
29
  CLI for downloading, testing and submitting Kattis problems.
21
30
  """
31
+ pass
22
32
 
23
33
 
24
34
  @main.command(help='Download sample data & metadata.')
@@ -34,7 +44,7 @@ def get(problemid: str) -> None:
34
44
  except requests.exceptions.InvalidURL:
35
45
  console.print(
36
46
  f"""Sample data for Problem ID: [bold blue]
37
- {problemid}[/bold blue] not found.")
47
+ {problemid}[/bold blue] not found.")
38
48
  """)
39
49
  console.print(
40
50
  f"Downloading metadata: [bold blue]{problemid}[/bold blue]")
@@ -65,11 +75,11 @@ def test(
65
75
  """Test solution with sample files.
66
76
  """
67
77
  problemid, loc_language, mainclass, _files, root_folder, lang_config = \
68
- utility.update_args(problemid, language, mainclass, list(files))
78
+ languages.update_args(problemid, language, mainclass, list(files))
69
79
  # print('After - ', f'{problemid=} {language=} {mainclass=} {_files=}')
70
80
  # lang_config = config.parse_config(language)
71
81
  if not mainclass:
72
- mainclass = utility.guess_mainfile(
82
+ mainclass = languages.guess_mainfile(
73
83
  language, _files, problemid, lang_config)
74
84
 
75
85
  test_solution.test_samples(
@@ -101,14 +111,14 @@ def submit(problemid: str, language: str,
101
111
  """Submit a solution to Kattis.
102
112
  """
103
113
  problemid, language, mainclass, _files, _, lang_config = \
104
- utility.update_args(
114
+ languages.update_args(
105
115
  problemid, language, mainclass, list(files))
106
116
  # Finally, submit the solution
107
117
  # print(f'{problemid=} {language=} {mainclass=} {tag=} {force=} {_files=}')
108
118
  if not mainclass:
109
- mainclass = utility.guess_mainfile(
119
+ mainclass = languages.guess_mainfile(
110
120
  language, _files, problemid, lang_config)
111
- kat_lang = utility.LOCAL_TO_KATTIS[language]
121
+ kat_lang = languages.LOCAL_TO_KATTIS[language]
112
122
  kattis.submit_solution(_files, problemid,
113
123
  kat_lang, mainclass,
114
124
  tag, force)
@@ -1,7 +1,6 @@
1
1
  """Tester module for Kattis.
2
2
  """
3
3
 
4
- from math import inf
5
4
  from typing import Any, List, Dict
6
5
  import glob
7
6
  import time
@@ -17,26 +16,7 @@ from rich.prompt import Confirm
17
16
  from rich.markup import escape
18
17
 
19
18
  from kattis_cli import kattis
20
- from kattis_cli.utils import run_program, utility
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
19
+ from kattis_cli.utils import languages, run_program, utility
40
20
 
41
21
 
42
22
  def test_samples(
@@ -46,7 +26,7 @@ def test_samples(
46
26
  problem_root_folder: str,
47
27
  files: List[str],
48
28
  lang_config: Dict[Any, Any],
49
- accuracy: float = inf
29
+ accuracy: float = 0
50
30
  ) -> None:
51
31
  """Tests a problem by running all the .in files in
52
32
  the problem folder and comparing the output to the .ans files.
@@ -147,14 +127,15 @@ def test_samples(
147
127
  if code != 0:
148
128
  ans = error
149
129
  # console.print(f"{ans=} {error=}")
150
- if accuracy == inf: # string comparison
130
+ if accuracy == 0: # string comparison
151
131
  if expected == ans.encode('utf-8').strip():
152
132
  result = "[bold green]✅[/bold green]"
153
133
  count += 1
154
134
  else:
155
135
  result = "[bold red]❌[/bold red]"
156
136
  else: # floating point comparison
157
- if compare_floats(expected.decode('utf-8'), ans, accuracy):
137
+ if utility.compare_floats(expected.decode('utf-8'),
138
+ ans, accuracy):
158
139
  result = "[bold green]✅[/bold green]"
159
140
  count += 1
160
141
  else:
@@ -188,7 +169,7 @@ def test_samples(
188
169
  "Awesome... Time to submit it to :cat: Kattis! :cat:",
189
170
  style="bold green")
190
171
  if Confirm.ask("Submit to Kattis?", default=True):
191
- kat_language = utility.LOCAL_TO_KATTIS.get(loc_language, '')
172
+ kat_language = languages.LOCAL_TO_KATTIS.get(loc_language, '')
192
173
  kattis.submit_solution(files, problemid,
193
174
  kat_language, mainclass,
194
175
  tag="", force=True)
@@ -9,7 +9,7 @@ import configparser
9
9
  from tomlkit import load
10
10
  import yaml
11
11
 
12
- from .utility import find_problem_root_folder
12
+ from kattis_cli.utils.utility import find_problem_root_folder
13
13
 
14
14
  _DEFAULT_CONFIG = Path.home().joinpath('.kattisrc')
15
15
 
@@ -1,14 +1,14 @@
1
1
  """Module for language utilities.
2
2
  """
3
3
 
4
- from typing import List, Union, Any, Dict
4
+ from typing import List, Dict, Any
5
5
  import sys
6
6
  import os
7
7
  import re
8
8
  from pathlib import Path
9
- import yaml
10
9
  from rich.console import Console
11
10
  from kattis_cli.utils import config
11
+ from kattis_cli.utils.utility import find_problem_root_folder
12
12
 
13
13
 
14
14
  LANGUAGE_GUESS = {
@@ -248,60 +248,6 @@ def valid_extension(file: str) -> bool:
248
248
  return False
249
249
 
250
250
 
251
- def find_problem_root_folder(
252
- cur_dir_path: Union[str, Path],
253
- filename: str
254
- ) -> Path:
255
- """Find the root problem folder given a directory path and filename.
256
-
257
- Args:
258
- cur_dir_path (Union[str, Path]): String or Path
259
- object of directory path
260
- filename (str): filename to search for
261
- including wildcard pattern
262
-
263
- Returns:
264
- Path: Path object of the root problem folder
265
- """
266
-
267
- def _check_file_match_folder(path: Path, filename: str) -> bool:
268
- """ Check folder is same name as the filename given
269
- filename including wildcard.
270
-
271
- Args:
272
- path (Path): Path object of directory path
273
- filename (str): filename to search for
274
- including wildcard pattern
275
- Returns:
276
- bool: True if path exists, False otherwise
277
- """
278
- for file in path.glob(filename):
279
- name, ext = os.path.splitext(file.name)
280
- folder_name = path.parts[-1]
281
- # print(f'{name} {folder_name=} {name=} {ext=}')
282
- if name == folder_name:
283
- return True
284
- # read yaml file
285
- if ext == '.yaml':
286
- with open(file, 'r', encoding='utf-8') as f:
287
- data = yaml.safe_load(f)
288
- if 'problemid' in data:
289
- return True
290
- return False
291
-
292
- # print(f'{cur_dir_path=} {filename=}')
293
- if not filename:
294
- filename = '.yaml'
295
- cur_path = Path(cur_dir_path)
296
- if _check_file_match_folder(cur_path, filename):
297
- return cur_path
298
- for parent in cur_path.parents:
299
- # print('parent', parent, file=sys.stderr)
300
- if _check_file_match_folder(parent, filename):
301
- return parent
302
- raise FileNotFoundError("Error: Problem root folder not found.")
303
-
304
-
305
251
  # flake8: noqa: C901
306
252
  def update_args(problemid: str,
307
253
  loc_language: str,
@@ -0,0 +1,86 @@
1
+ """ Utility functions. """
2
+
3
+ from pathlib import Path
4
+ import os
5
+ from typing import Union
6
+ import yaml
7
+
8
+
9
+ def find_problem_root_folder(
10
+ cur_dir_path: Union[str, Path],
11
+ filename: str
12
+ ) -> Path:
13
+ """Find the root problem folder given a directory path and filename.
14
+
15
+ Args:
16
+ cur_dir_path (Union[str, Path]): String or Path
17
+ object of directory path
18
+ filename (str): filename to search for
19
+ including wildcard pattern
20
+
21
+ Returns:
22
+ Path: Path object of the root problem folder
23
+ """
24
+
25
+ def _check_file_match_folder(path: Path, filename: str) -> bool:
26
+ """ Check folder is same name as the filename given
27
+ filename including wildcard.
28
+
29
+ Args:
30
+ path (Path): Path object of directory path
31
+ filename (str): filename to search for
32
+ including wildcard pattern
33
+ Returns:
34
+ bool: True if path exists, False otherwise
35
+ """
36
+ for file in path.glob(filename):
37
+ name, ext = os.path.splitext(file.name)
38
+ folder_name = path.parts[-1]
39
+ # print(f'{name} {folder_name=} {name=} {ext=}')
40
+ if name == folder_name:
41
+ return True
42
+ # read yaml file
43
+ if ext == '.yaml':
44
+ with open(file, 'r', encoding='utf-8') as f:
45
+ data = yaml.safe_load(f)
46
+ if 'problemid' in data:
47
+ return True
48
+ return False
49
+
50
+ # print(f'{cur_dir_path=} {filename=}')
51
+ if not filename:
52
+ filename = '.yaml'
53
+ cur_path = Path(cur_dir_path)
54
+ if _check_file_match_folder(cur_path, filename):
55
+ return cur_path
56
+ for parent in cur_path.parents:
57
+ # print('parent', parent, file=sys.stderr)
58
+ if _check_file_match_folder(parent, filename):
59
+ return parent
60
+ raise FileNotFoundError("Error: Problem root folder not found.")
61
+
62
+
63
+ def compare_floats(expected: str, ans: str, places: float) -> bool:
64
+ """Compare two floating point numbers with given accuracy.
65
+
66
+ Args:
67
+ expected (str): expected result
68
+ ans (str): actual result
69
+ places (float): decimal places for approximation
70
+
71
+ Returns:
72
+ bool: True if the two numbers are equal within the given accuracy
73
+ """
74
+ expect_ans = expected.strip().split('\n')
75
+ actual_ans = ans.strip().split('\n')
76
+ if len(expect_ans) != len(actual_ans):
77
+ return False
78
+ try:
79
+ for i, ex_ans in enumerate(expect_ans):
80
+ flt_expected = float(ex_ans)
81
+ flt_ans = float(actual_ans[i])
82
+ if abs(flt_expected - flt_ans) > 10**(-places):
83
+ return False
84
+ return True
85
+ except ValueError:
86
+ return False
@@ -1,7 +1,7 @@
1
1
  [tool.poetry]
2
2
  name = "kattis-cli"
3
- version = "1.0.2"
4
- authors = ["Ram Basnet <rambasnet@gmail.com>"]
3
+ version = "1.0.4"
4
+ authors = ["Ram Basnet <rbasnet@coloradomesa.edu>"]
5
5
  description = "A command-line tool for Kattis"
6
6
  readme = "README.md"
7
7
  repository = "https://github.com/rambasnet/kattis-cli"
File without changes
File without changes