artefacts-cli 0.7.3__py3-none-any.whl → 0.9.1__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.
artefacts/cli/__init__.py CHANGED
@@ -1,13 +1,15 @@
1
+ from datetime import datetime, timezone
1
2
  from importlib.metadata import version, PackageNotFoundError
2
- import json
3
+ from typing import Optional
4
+ import copy
3
5
  import glob
4
- from datetime import datetime, timezone
5
- import os
6
+ import json
6
7
  import math
8
+ import os
7
9
  import requests
8
- import copy
9
- from typing import Optional
10
10
 
11
+ from .config import APIConf
12
+ from .i18n import localise
11
13
  from .parameters import iter_grid
12
14
  from .logger import logger
13
15
 
@@ -21,7 +23,13 @@ except PackageNotFoundError:
21
23
 
22
24
  __version__ = get_version()
23
25
  except Exception as e:
24
- logger.warning(f"Could not determine package version: {e}. Default to 0.0.0")
26
+ logger.warning(
27
+ localise(
28
+ "Could not determine package version: {error_message}. Default to 0.0.0".format(
29
+ error_message=e
30
+ )
31
+ )
32
+ )
25
33
  __version__ = "0.0.0"
26
34
 
27
35
 
@@ -35,7 +43,7 @@ class WarpJob:
35
43
  def __init__(
36
44
  self,
37
45
  project_id,
38
- api_conf,
46
+ api_conf: APIConf,
39
47
  jobname,
40
48
  jobconf,
41
49
  dryrun=False,
@@ -86,7 +94,13 @@ class WarpJob:
86
94
  msg = response.json()["message"]
87
95
  logger.warning(msg)
88
96
  raise AuthenticationError(msg)
89
- logger.warning(f"Error on job creation: {response.status_code}")
97
+ logger.warning(
98
+ localise(
99
+ "Error on job creation: {status_code}".format(
100
+ status_code=response.status_code
101
+ )
102
+ )
103
+ )
90
104
  logger.warning(response.text)
91
105
  raise AuthenticationError(str(response.status_code))
92
106
  self.job_id = response.json()["job_id"]
@@ -133,6 +147,9 @@ class WarpRun:
133
147
  self.output_path = self.params.get(
134
148
  "output_path", f"{self.job.output_path}/{self.run_n}"
135
149
  )
150
+ self.test_results = None
151
+ self.success = False
152
+ self.logger = logger
136
153
  os.makedirs(self.output_path, exist_ok=True)
137
154
  data = {
138
155
  "job_id": job.job_id,
@@ -155,10 +172,16 @@ class WarpRun:
155
172
  if response.status_code != 200:
156
173
  if response.status_code == 403:
157
174
  msg = response.json()["message"]
158
- logger.warning(msg)
175
+ self.logger.warning(msg)
159
176
  raise AuthenticationError(msg)
160
- logger.warning(f"Error on scenario creation: {response.status_code}")
161
- logger.warning(response.text)
177
+ self.logger.warning(
178
+ localise(
179
+ "Error on scenario creation: {status_code}".format(
180
+ status_code=response.status_code
181
+ )
182
+ )
183
+ )
184
+ self.logger.warning(response.text)
162
185
  raise AuthenticationError(str(response.status_code))
163
186
  return
164
187
 
@@ -235,8 +258,10 @@ class WarpRun:
235
258
 
236
259
  def stop(self):
237
260
  end = datetime.now(timezone.utc).timestamp()
261
+
238
262
  if self.job.dryrun:
239
263
  return
264
+
240
265
  # Log metadata
241
266
  data = {
242
267
  "job_id": self.job.job_id,
@@ -247,18 +272,23 @@ class WarpRun:
247
272
  "duration": math.ceil(end - self.start),
248
273
  "tests": self.test_results,
249
274
  "success": self.success,
250
- "uploads": self.uploads,
251
275
  "metrics": self.metrics,
252
276
  }
277
+ if not self.job.noupload:
278
+ data["uploads"] = self.uploads
279
+
253
280
  response = requests.put(
254
281
  f"{self.job.api_conf.api_url}/{self.job.project_id}/job/{self.job.job_id}/run/{self.run_n}",
255
282
  json=data,
256
283
  headers=self.job.api_conf.headers,
257
284
  )
285
+
258
286
  # use s3 presigned urls to upload the artifacts
259
287
  if self.job.noupload:
260
288
  print(
261
- "noupload: job artifacts are not uploaded to cloud, including the ones specified in output_dirs"
289
+ localise(
290
+ "Files generated by the job are not uploaded to Artefacts, including the ones specified in output_dirs"
291
+ )
262
292
  )
263
293
  else:
264
294
  upload_urls = response.json()["upload_urls"]
@@ -267,7 +297,13 @@ class WarpRun:
267
297
  upload_info = upload_urls[key]
268
298
  file_size_mb = os.path.getsize(file_name) / 1024 / 1024
269
299
  try:
270
- print(f"Uploading {file_name} ({file_size_mb:.2f} MB)")
300
+ print(
301
+ localise(
302
+ "Uploading {file_name} ({file_size:.2f} MB)".format(
303
+ file_name=file_name, file_size=file_size_mb
304
+ )
305
+ )
306
+ )
271
307
  # TODO: add a retry policy
272
308
  requests.post(
273
309
  upload_info["url"],
@@ -275,14 +311,26 @@ class WarpRun:
275
311
  files=files,
276
312
  )
277
313
  except OverflowError:
278
- logger.warning(f"File too large: {file_name} could not be uploaded")
314
+ self.logger.warning(
315
+ localise(
316
+ "File too large: {file_name} could not be uploaded".format(
317
+ file_name=file_name
318
+ )
319
+ )
320
+ )
279
321
  except Exception as e:
280
- logger.warning(f"Error uploading {file_name}: {e}, skipping")
322
+ self.logger.warning(
323
+ localise(
324
+ "Error uploading {file_name}: {error_message}, skipping".format(
325
+ file_name=file_name, error_message=e
326
+ )
327
+ )
328
+ )
281
329
 
282
330
 
283
331
  def init_job(
284
332
  project_id: str,
285
- api_token: str,
333
+ api_conf: APIConf,
286
334
  jobname: str,
287
335
  jobconf: dict,
288
336
  dryrun: bool = False,
@@ -294,7 +342,7 @@ def init_job(
294
342
  ):
295
343
  return WarpJob(
296
344
  project_id,
297
- api_token,
345
+ api_conf,
298
346
  jobname,
299
347
  jobconf,
300
348
  dryrun,