wmill 1.468.0__py3-none-any.whl → 1.469.0__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.
wmill/client.py
CHANGED
|
@@ -8,6 +8,7 @@ import logging
|
|
|
8
8
|
import os
|
|
9
9
|
import random
|
|
10
10
|
import time
|
|
11
|
+
from typing_extensions import Optional
|
|
11
12
|
import warnings
|
|
12
13
|
import json
|
|
13
14
|
from json import JSONDecodeError
|
|
@@ -40,8 +41,25 @@ class Windmill:
|
|
|
40
41
|
self.workspace = workspace or os.environ.get("WM_WORKSPACE")
|
|
41
42
|
self.path = os.environ.get("WM_JOB_PATH")
|
|
42
43
|
|
|
44
|
+
self.mocked_api = self.get_mocked_api()
|
|
45
|
+
|
|
43
46
|
assert self.workspace, f"workspace required as an argument or as WM_WORKSPACE environment variable"
|
|
44
47
|
|
|
48
|
+
def get_mocked_api(self) -> Optional[dict]:
|
|
49
|
+
mocked_path = os.environ.get("WM_MOCKED_API_FILE")
|
|
50
|
+
if not mocked_path:
|
|
51
|
+
return None
|
|
52
|
+
logger.info("Using mocked API from %s", mocked_path)
|
|
53
|
+
mocked_api = {"variables": {}, "resources": {}}
|
|
54
|
+
try:
|
|
55
|
+
with open(mocked_path, "r") as f:
|
|
56
|
+
incoming_mocked_api = json.load(f)
|
|
57
|
+
mocked_api = {**mocked_api, **incoming_mocked_api}
|
|
58
|
+
except Exception as e:
|
|
59
|
+
logger.warning("Error parsing mocked API file at path %s Using empty mocked API.", mocked_path)
|
|
60
|
+
logger.debug(e)
|
|
61
|
+
return mocked_api
|
|
62
|
+
|
|
45
63
|
def get_client(self) -> httpx.Client:
|
|
46
64
|
return httpx.Client(
|
|
47
65
|
base_url=self.base_url,
|
|
@@ -277,10 +295,22 @@ class Windmill:
|
|
|
277
295
|
return result_text
|
|
278
296
|
|
|
279
297
|
def get_variable(self, path: str) -> str:
|
|
298
|
+
if self.mocked_api is not None:
|
|
299
|
+
variables = self.mocked_api["variables"]
|
|
300
|
+
try:
|
|
301
|
+
result = variables[path]
|
|
302
|
+
return result
|
|
303
|
+
except KeyError:
|
|
304
|
+
logger.info(f"MockedAPI present, but variable not found at {path}, falling back to real API")
|
|
305
|
+
|
|
280
306
|
"""Get variable from Windmill"""
|
|
281
307
|
return self.get(f"/w/{self.workspace}/variables/get_value/{path}").json()
|
|
282
308
|
|
|
283
309
|
def set_variable(self, path: str, value: str, is_secret: bool = False) -> None:
|
|
310
|
+
if self.mocked_api is not None:
|
|
311
|
+
self.mocked_api["variables"][path] = value
|
|
312
|
+
return
|
|
313
|
+
|
|
284
314
|
"""Set variable from Windmill"""
|
|
285
315
|
# check if variable exists
|
|
286
316
|
r = self.get(f"/w/{self.workspace}/variables/get/{path}", raise_for_status=False)
|
|
@@ -307,6 +337,18 @@ class Windmill:
|
|
|
307
337
|
path: str,
|
|
308
338
|
none_if_undefined: bool = False,
|
|
309
339
|
) -> dict | None:
|
|
340
|
+
if self.mocked_api is not None:
|
|
341
|
+
resources = self.mocked_api["resources"]
|
|
342
|
+
try:
|
|
343
|
+
result = resources[path]
|
|
344
|
+
return result
|
|
345
|
+
except KeyError:
|
|
346
|
+
# NOTE: should mocked_api respect `none_if_undefined`?
|
|
347
|
+
if none_if_undefined:
|
|
348
|
+
logger.info(f"resource not found at ${path}, but none_if_undefined is True, so returning None")
|
|
349
|
+
return None
|
|
350
|
+
logger.info(f"MockedAPI present, but resource not found at ${path}, falling back to real API")
|
|
351
|
+
|
|
310
352
|
"""Get resource from Windmill"""
|
|
311
353
|
try:
|
|
312
354
|
return self.get(f"/w/{self.workspace}/resources/get_value_interpolated/{path}").json()
|
|
@@ -322,6 +364,10 @@ class Windmill:
|
|
|
322
364
|
path: str,
|
|
323
365
|
resource_type: str,
|
|
324
366
|
):
|
|
367
|
+
if self.mocked_api is not None:
|
|
368
|
+
self.mocked_api["resources"][path] = value
|
|
369
|
+
return
|
|
370
|
+
|
|
325
371
|
# check if resource exists
|
|
326
372
|
r = self.get(f"/w/{self.workspace}/resources/get/{path}", raise_for_status=False)
|
|
327
373
|
if r.status_code == 404:
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
wmill/__init__.py,sha256=nGZnQPezTdrBnBW1D0JqUtm75Gdf_xi3tAcPGwHRZ5A,46
|
|
2
|
-
wmill/client.py,sha256=
|
|
2
|
+
wmill/client.py,sha256=NIkxFCMtwl_wDsebV-zmabithB6xrEJ6-ZhfTcE9i0I,41557
|
|
3
3
|
wmill/py.typed,sha256=8PjyZ1aVoQpRVvt71muvuq5qE-jTFZkK-GLHkhdebmc,26
|
|
4
4
|
wmill/s3_reader.py,sha256=izHlg2Xsg0Sr_LkDDEC35VuEijJcuPBDIm-xj21KsgU,1668
|
|
5
5
|
wmill/s3_types.py,sha256=XVjPyc5sjWesTy6nnRReojhyPgPsaT0EY3X57mWUaJ4,1173
|
|
6
|
-
wmill-1.
|
|
7
|
-
wmill-1.
|
|
8
|
-
wmill-1.
|
|
6
|
+
wmill-1.469.0.dist-info/METADATA,sha256=NbPyTyyleZvjpJGVODZtpG4L3aO5ChCbAyRMgh44T4A,2693
|
|
7
|
+
wmill-1.469.0.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
|
|
8
|
+
wmill-1.469.0.dist-info/RECORD,,
|
|
File without changes
|