code-battles-cli 1.2.0__py3-none-any.whl → 1.2.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.
code_battles_cli/api.py CHANGED
@@ -28,6 +28,18 @@ SIMULATION_FINISHED_MARK = b"--- SIMULATION FINISHED ---"
28
28
  SIMULATION_STEP_MARK = b"__CODE_BATTLES_ADVANCE_STEP"
29
29
 
30
30
 
31
+ def normalize(url: str):
32
+ if url.startswith("https"):
33
+ url = url[5:]
34
+
35
+ try:
36
+ url = url[: url.index(".web.app")]
37
+ except ValueError:
38
+ pass
39
+
40
+ return url
41
+
42
+
31
43
  class SimulationException(Exception):
32
44
  def __init__(self, stderr: bytes, exit_code: int):
33
45
  self.stderr = stderr
@@ -213,11 +225,7 @@ class Client:
213
225
 
214
226
  def _possibly_download(self, force_download=False):
215
227
  directory_name = "".join(
216
- [
217
- c
218
- for c in self.url.removeprefix("https").removesuffix(".web.app")
219
- if c.isalnum() or c == "-"
220
- ]
228
+ [c for c in normalize(self.url) if c.isalnum() or c == "-"]
221
229
  )
222
230
  code_directory = os.path.expanduser(f"~/.cache/code-battles/{directory_name}")
223
231
 
@@ -242,6 +250,9 @@ class Client:
242
250
  on_step: Optional[Callable[[], None]] = None,
243
251
  ) -> Union[SimulationResults, str]:
244
252
  while True:
253
+ if p.poll() is not None and p.returncode != 0:
254
+ raise SimulationException(p.stderr.read(), p.returncode)
255
+
245
256
  line: bytes = p.stdout.readline()
246
257
  line = line.strip()
247
258
  if line == SIMULATION_FINISHED_MARK:
@@ -310,7 +321,11 @@ class Client:
310
321
  os.path.join(code_directory, "packed.py"),
311
322
  "simulate",
312
323
  str(seed),
313
- str(os.path.abspath(output_file)),
324
+ str(
325
+ os.path.abspath(output_file)
326
+ if output_file is not None
327
+ else output_file
328
+ ),
314
329
  json.dumps(parameters),
315
330
  "-".join(bot_names),
316
331
  ]
@@ -45,4 +45,5 @@ def upload(
45
45
 
46
46
  client = Client(url, username, password, dump_credentials)
47
47
  client.set_bots({bot_name: bot_code})
48
- log.info(f"{bot_code.count('\n') + 1} lines of code were uploaded as '{bot_name}'.")
48
+ line_count = bot_code.count("\n") + 1
49
+ log.info(f"{line_count} lines of code were uploaded as '{bot_name}'.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: code-battles-cli
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary: A CLI for competitors in any Code Battles event!
5
5
  Requires-Python: >=3.8
6
6
  Requires-Dist: click>=8.1.7
@@ -1,14 +1,14 @@
1
1
  code_battles_cli/__init__.py,sha256=BST1iXWs0ner82h-LTYTgVNjLtOpVZnvBMiCEiBkOXE,38
2
2
  code_battles_cli/__main__.py,sha256=HguVXadDv5QVywZWoB-BETvX1WV4VPYxclfnKhvOrZc,67
3
- code_battles_cli/api.py,sha256=_2Ldfd6IM-q5IbMYeiffb09KsZfWjSspizDjlv3VTHA,11713
3
+ code_battles_cli/api.py,sha256=iv7peRbTsjL29lU5XjrjfFo9cZ3QUubA5Q4kziz2SAo,12056
4
4
  code_battles_cli/cli.py,sha256=yfUAlU85FBykU_pHB6HHQCc7_ZN0KiPbc8ssB4TOgIc,515
5
5
  code_battles_cli/log.py,sha256=Ume7UPFdKNqu-DI2hpc6cefyMZQeFavc_cWizKooq98,860
6
6
  code_battles_cli/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  code_battles_cli/commands/download.py,sha256=ZLwbHdcqak6uuXEMb1Mp4fXW7QxkdbIlpKxSUR-WQDA,1600
8
8
  code_battles_cli/commands/run.py,sha256=J3IFVVoUAJWLa7ZtDvDhrFYt7Yx3aQYbVo9Z2SomeWQ,3872
9
- code_battles_cli/commands/upload.py,sha256=Un3QxCK4v3xhiBPXYc-6JYw3KdZn9K2j476gShIKEOo,1361
10
- code_battles_cli-1.2.0.dist-info/METADATA,sha256=6VF_JS4-I4FmIbXtkR9NOFyIUfPZcxMj63gWlWrta3g,2523
11
- code_battles_cli-1.2.0.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
12
- code_battles_cli-1.2.0.dist-info/entry_points.txt,sha256=U_iQUEDK-9L09jXd_sJg0IgKLWeN3rccCyNVUeJuQxw,55
13
- code_battles_cli-1.2.0.dist-info/licenses/LICENSE.md,sha256=eYDByTiNbk3_TPH_i-FU-bHnfNb6VidN57zMO2dfaUM,1087
14
- code_battles_cli-1.2.0.dist-info/RECORD,,
9
+ code_battles_cli/commands/upload.py,sha256=8Y6kKS4ynnmsmfM0IqtljF6gT7PUcrcJz9ilzrKUuTk,1389
10
+ code_battles_cli-1.2.2.dist-info/METADATA,sha256=S5v0En-U7awBMja-F0AbF8p7HfWsBjRZNb4NDWRL8vE,2523
11
+ code_battles_cli-1.2.2.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
12
+ code_battles_cli-1.2.2.dist-info/entry_points.txt,sha256=U_iQUEDK-9L09jXd_sJg0IgKLWeN3rccCyNVUeJuQxw,55
13
+ code_battles_cli-1.2.2.dist-info/licenses/LICENSE.md,sha256=eYDByTiNbk3_TPH_i-FU-bHnfNb6VidN57zMO2dfaUM,1087
14
+ code_battles_cli-1.2.2.dist-info/RECORD,,