kattis-cli 1.0.1__py3-none-any.whl → 1.0.2__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 CHANGED
@@ -1,6 +1,7 @@
1
1
  """ Main module for the kattis_cli package."""
2
- __version__ = '0.1.6'
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 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
  Metadata-Version: 2.1
2
2
  Name: kattis-cli
3
- Version: 1.0.1
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
- 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
@@ -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=PpizTV_9JDr-vgplpuwlgjJrxT62dMVLEC0zPm2R9Zo,3952
6
+ kattis_cli/main.py,sha256=LDUUdG0eqiKL_zJX9V05OaqUIXKrOOwVAWOgN4TWWQQ,4121
7
7
  kattis_cli/settings.py,sha256=d5q4dYj9VqDSqPalleh2oZWtND-1bPB0T2IwdajFrBg,591
8
- kattis_cli/test_solution.py,sha256=M_BpwQC6lhWjk-d2oum4i5a_T25tAFgjWot9JFmH6R8,5659
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=_uyPR_64_mX5EJDvdGf9fvjaAKwZKXvEcgksALQvml8,11500
14
- kattis_cli-1.0.1.dist-info/LICENSE,sha256=JmBa4SEKBCDWEgiOZcISU4tUCpli6xSpVlSYgkBXSNQ,1067
15
- kattis_cli-1.0.1.dist-info/METADATA,sha256=zpdJWccqlQ1P-qVRKui7278rMZjwBPU5mNG6KWqmFh8,5551
16
- kattis_cli-1.0.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
17
- kattis_cli-1.0.1.dist-info/entry_points.txt,sha256=kyzGN20VqUPR_H0J_jJUKT-10-cAMFLVegQ6C7tbHss,47
18
- kattis_cli-1.0.1.dist-info/RECORD,,
13
+ kattis_cli/utils/utility.py,sha256=JkypTfPOlDSxmZsh7KKcAVG2BC58t66corMBtcdvU7E,10532
14
+ kattis_cli-1.0.2.dist-info/LICENSE,sha256=JmBa4SEKBCDWEgiOZcISU4tUCpli6xSpVlSYgkBXSNQ,1067
15
+ kattis_cli-1.0.2.dist-info/METADATA,sha256=TImOazyOs7tJWBf_E-NP9x3-_InVey2bnqBxhjJMGOs,5961
16
+ kattis_cli-1.0.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
17
+ kattis_cli-1.0.2.dist-info/entry_points.txt,sha256=kyzGN20VqUPR_H0J_jJUKT-10-cAMFLVegQ6C7tbHss,47
18
+ kattis_cli-1.0.2.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.8.1
2
+ Generator: poetry-core 1.9.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any