clerk-sdk 0.2.7__py3-none-any.whl → 0.3.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.
- clerk/decorator/task_decorator.py +7 -1
- clerk/exceptions/__init__.py +0 -0
- clerk/exceptions/exceptions.py +13 -0
- clerk/exceptions/remote_device.py +4 -0
- clerk/gui_automation/ui_actions/support.py +42 -1
- clerk/utils/logger.py +3 -3
- clerk/utils/save_artifact.py +3 -3
- {clerk_sdk-0.2.7.dist-info → clerk_sdk-0.3.0.dist-info}/METADATA +1 -1
- {clerk_sdk-0.2.7.dist-info → clerk_sdk-0.3.0.dist-info}/RECORD +12 -9
- {clerk_sdk-0.2.7.dist-info → clerk_sdk-0.3.0.dist-info}/WHEEL +0 -0
- {clerk_sdk-0.2.7.dist-info → clerk_sdk-0.3.0.dist-info}/licenses/LICENSE +0 -0
- {clerk_sdk-0.2.7.dist-info → clerk_sdk-0.3.0.dist-info}/top_level.txt +0 -0
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import pickle
|
|
3
|
+
import traceback
|
|
3
4
|
from typing import Callable, Optional
|
|
4
5
|
from functools import wraps
|
|
6
|
+
|
|
7
|
+
from clerk.exceptions.exceptions import ApplicationException
|
|
5
8
|
from .models import ClerkCodePayload
|
|
6
9
|
|
|
7
10
|
input_pkl: str = "/app/data/input/input.pkl"
|
|
@@ -35,7 +38,10 @@ def clerk_code():
|
|
|
35
38
|
if not isinstance(output, ClerkCodePayload):
|
|
36
39
|
raise TypeError("Function must return a ClerkCodePayload instance.")
|
|
37
40
|
except Exception as e:
|
|
38
|
-
|
|
41
|
+
# parse no standard errors into the standard Application Error
|
|
42
|
+
output = ApplicationException(
|
|
43
|
+
type=str(type(e)), message=str(e), traceback=traceback.format_exc()
|
|
44
|
+
)
|
|
39
45
|
|
|
40
46
|
# 3. write to output.pkl
|
|
41
47
|
try:
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class AppBaseException(Exception):
|
|
5
|
+
def __init__(self, type_: str, message: str, traceback: Optional[str] = None):
|
|
6
|
+
super().__init__(message)
|
|
7
|
+
self.type = type_
|
|
8
|
+
self.message = message
|
|
9
|
+
self.traceback = traceback
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ApplicationException(AppBaseException):
|
|
13
|
+
pass
|
|
@@ -2,7 +2,7 @@ from datetime import timedelta, datetime
|
|
|
2
2
|
import os
|
|
3
3
|
import base64
|
|
4
4
|
import time
|
|
5
|
-
from typing import Optional
|
|
5
|
+
from typing import List, Optional
|
|
6
6
|
from backoff._typing import Details
|
|
7
7
|
|
|
8
8
|
from clerk.models.ui_operator import TaskStatuses, UiOperatorTask
|
|
@@ -60,6 +60,47 @@ def save_screenshot(filename: str, sub_folder: Optional[str] = None) -> str:
|
|
|
60
60
|
)
|
|
61
61
|
|
|
62
62
|
|
|
63
|
+
def try_actions(actions: List[BaseAction]):
|
|
64
|
+
"""
|
|
65
|
+
Executes a list of UI actions and handles any errors that occur.
|
|
66
|
+
|
|
67
|
+
This function takes a list of UI actions as input and executes them one by one.
|
|
68
|
+
If an action fails with a RuntimeError, it logs a warning message and moves on to the next action.
|
|
69
|
+
If all actions fail, it logs an error message and raises a RuntimeError.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
actions (List[BaseAction]): A list of UI actions to be executed.
|
|
73
|
+
|
|
74
|
+
Raises:
|
|
75
|
+
TypeError: If any of the actions in the list is not an instance of BaseAction.
|
|
76
|
+
RuntimeError: If all actions fail.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
None
|
|
80
|
+
|
|
81
|
+
Example Usage:
|
|
82
|
+
actions = [action1, action2, action3]
|
|
83
|
+
try_actions(actions)
|
|
84
|
+
"""
|
|
85
|
+
try:
|
|
86
|
+
assert all(isinstance(action, BaseAction) for action in actions)
|
|
87
|
+
for action in actions:
|
|
88
|
+
try:
|
|
89
|
+
action.do()
|
|
90
|
+
return
|
|
91
|
+
except RuntimeError as e:
|
|
92
|
+
logger.warning(
|
|
93
|
+
f"The action {action} was not performed successfully.\nDetails: {str(e)}",
|
|
94
|
+
)
|
|
95
|
+
# all the actions have failed. log an error and raise a runtime error
|
|
96
|
+
logger.error("All actions have failed.")
|
|
97
|
+
raise RuntimeError("All actions have failed")
|
|
98
|
+
except AssertionError as e:
|
|
99
|
+
raise TypeError(
|
|
100
|
+
f"All actions must be valid. Encountered invalid action: {str(e)}"
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
63
104
|
def _format_action_string(action: BaseAction) -> str:
|
|
64
105
|
"""
|
|
65
106
|
Formats action in the same format as the one used in task modules.
|
clerk/utils/logger.py
CHANGED
|
@@ -79,11 +79,11 @@ def _log(level: str, message: str):
|
|
|
79
79
|
_log_to_console("INFO", "module_name", "This is an info message")
|
|
80
80
|
|
|
81
81
|
"""
|
|
82
|
-
# Get
|
|
83
|
-
|
|
82
|
+
# Get artifact folder from environment variable or default to "unknown"
|
|
83
|
+
_artifacts_folder = os.getenv("_artifacts_folder", "unknown")
|
|
84
84
|
|
|
85
85
|
# Create the base path for artifacts
|
|
86
|
-
logs_path = os.path.join(base_path,
|
|
86
|
+
logs_path = os.path.join(base_path, _artifacts_folder)
|
|
87
87
|
os.makedirs(logs_path, exist_ok=True)
|
|
88
88
|
# Define the log file path
|
|
89
89
|
log_file_path = os.path.join(logs_path, "logs.txt")
|
clerk/utils/save_artifact.py
CHANGED
|
@@ -18,11 +18,11 @@ def save_artifact(
|
|
|
18
18
|
str: The path to the saved artifact.
|
|
19
19
|
"""
|
|
20
20
|
|
|
21
|
-
# get the
|
|
22
|
-
|
|
21
|
+
# get the artifact folder from environment variable or default to "unknown"
|
|
22
|
+
_artifacts_folder = os.getenv("_artifacts_folder", "unknown")
|
|
23
23
|
|
|
24
24
|
# create the base path for artifacts
|
|
25
|
-
base_path = os.path.join(os.getcwd(), "data", "artifacts",
|
|
25
|
+
base_path = os.path.join(os.getcwd(), "data", "artifacts", _artifacts_folder)
|
|
26
26
|
if subfolder:
|
|
27
27
|
base_path = os.path.join(base_path, subfolder)
|
|
28
28
|
|
|
@@ -3,7 +3,10 @@ clerk/base.py,sha256=Ayb2zCQr8fqKZM_Qh3nVxVJOQkkYt-eD5VtpPXd1TLs,2669
|
|
|
3
3
|
clerk/client.py,sha256=6nWWWjGB7a6FNUWsZRM-IoBb_mshRi6g5KX8meMiJ2E,576
|
|
4
4
|
clerk/decorator/__init__.py,sha256=4VCGOFNq7pA7iJS410V_R9eWfjxP7mwxwa4thwaUTf8,39
|
|
5
5
|
clerk/decorator/models.py,sha256=JWFOJuUh3F40iOL0aoNgUC9GRHU3Fcq3GOjSXA7Gwng,394
|
|
6
|
-
clerk/decorator/task_decorator.py,sha256=
|
|
6
|
+
clerk/decorator/task_decorator.py,sha256=RNFQBcRcvolAomAKw2XsSEA5C4W1Ttv_qSfwcmybJAM,2453
|
|
7
|
+
clerk/exceptions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
clerk/exceptions/exceptions.py,sha256=pCG_KwJ8nwtfnljeqWXchd-qNgTeEfD8KQPXeUkN81A,331
|
|
9
|
+
clerk/exceptions/remote_device.py,sha256=R0Vfmk8ejibEFeV29A8Vqst2YA6yxdqEX9lP5wWubgM,134
|
|
7
10
|
clerk/gui_automation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
11
|
clerk/gui_automation/client.py,sha256=LqrUQtC-4pjUJYDDn_s3t073K066j_p0vf4kXLChBc0,4891
|
|
9
12
|
clerk/gui_automation/action_model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -23,7 +26,7 @@ clerk/gui_automation/exceptions/modality/exc.py,sha256=P-dMuCTyVZYD3pbGpCf_1SYEg
|
|
|
23
26
|
clerk/gui_automation/ui_actions/__init__.py,sha256=-EDQ5375HXrvG3sfFY7zOPC405YcBL6xXRACm2p-YyI,23
|
|
24
27
|
clerk/gui_automation/ui_actions/actions.py,sha256=hhxl5VMDNSXdqm2L0tZqs6IhJHVXtlSVSdwsiz2BbDI,27449
|
|
25
28
|
clerk/gui_automation/ui_actions/base.py,sha256=4CjOkMZNLt8W0tLO91tOkz8CCea0m2IRBIOpWNMOZUA,7230
|
|
26
|
-
clerk/gui_automation/ui_actions/support.py,sha256=
|
|
29
|
+
clerk/gui_automation/ui_actions/support.py,sha256=Ulb8DBfwnrBMaYoMLDgldEy9V--NDUSdhIYXpuODZoU,5772
|
|
27
30
|
clerk/gui_automation/ui_state_inspector/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
28
31
|
clerk/gui_automation/ui_state_inspector/gui_vision.py,sha256=lRnF3IMLViOB-UE447A4kc8BO7NKqqLV1NZKRswRKWg,7707
|
|
29
32
|
clerk/gui_automation/ui_state_inspector/models.py,sha256=uuzYhE9is4Z-TmsVMA1mwf0mQGs_PDLqdSZKbe8dHSs,5691
|
|
@@ -41,10 +44,10 @@ clerk/models/remote_device.py,sha256=2jijS-9WWq7y6xIbAaDaPnzZo3-tjp2-dCQvNKP8YSU
|
|
|
41
44
|
clerk/models/response_model.py,sha256=R62daUN1YVOwgnrh_epvFRsQcOwT7R4u97l73egvm-c,232
|
|
42
45
|
clerk/models/ui_operator.py,sha256=mKTJUFZgv7PeEt5oys28HVZxHOJsofmRQOcRpqj0dbU,293
|
|
43
46
|
clerk/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
44
|
-
clerk/utils/logger.py,sha256=
|
|
45
|
-
clerk/utils/save_artifact.py,sha256=
|
|
46
|
-
clerk_sdk-0.
|
|
47
|
-
clerk_sdk-0.
|
|
48
|
-
clerk_sdk-0.
|
|
49
|
-
clerk_sdk-0.
|
|
50
|
-
clerk_sdk-0.
|
|
47
|
+
clerk/utils/logger.py,sha256=vHbp-lUK3W3c5fhyPsp05p9LGyDHj95v8XM_XQ_FlLc,3691
|
|
48
|
+
clerk/utils/save_artifact.py,sha256=94aYkYNVGcSUaSWZmdjiY6Oc-3yCKb2XWCZ56IAXQqk,1158
|
|
49
|
+
clerk_sdk-0.3.0.dist-info/licenses/LICENSE,sha256=GTVQl3vH6ht70wJXKC0yMT8CmXKHxv_YyO_utAgm7EA,1065
|
|
50
|
+
clerk_sdk-0.3.0.dist-info/METADATA,sha256=lNfPCGTunwV4EXk-uZiWLfPB2OlwPor_fwwkXA_5gs0,3508
|
|
51
|
+
clerk_sdk-0.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
52
|
+
clerk_sdk-0.3.0.dist-info/top_level.txt,sha256=99eQiU6d05_-f41tmSFanfI_SIJeAdh7u9m3LNSfcv4,6
|
|
53
|
+
clerk_sdk-0.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|