@@ -18,10 +18,28 @@ def push(
18
18
project_id : str ,
19
19
message : str = "New commit" ,
20
20
storage_type : Optional [StorageType ] = None ,
21
- ) -> None :
21
+ wait_for_completion : bool = False ,
22
+ verbose : bool = False ,
23
+ ) -> Optional [CommitRetrieveResponse ]:
22
24
"""Push a new commit to the Openlayer platform.
23
25
24
- This is equivalent to running `openlayer push` from the Openlayer CLI."""
26
+ This is equivalent to running `openlayer push` from the Openlayer CLI.
27
+
28
+ If `wait_for_completion` is True, the function will wait for the commit to be
29
+ completed and return the commit object.
30
+
31
+ Args:
32
+ client: The Openlayer client.
33
+ directory: The directory to push.
34
+ project_id: The id of the project to push to.
35
+ message: The commit message.
36
+ storage_type: The storage type to use.
37
+ wait_for_completion: Whether to wait for the commit to be completed.
38
+ verbose: Whether to print verbose output.
39
+
40
+ Returns:
41
+ The commit object if `wait_for_completion` is True, otherwise None.
42
+ """
25
43
if not os .path .exists (directory ):
26
44
raise ValueError (f"Directory { directory } does not exist." )
27
45
@@ -43,19 +61,36 @@ def push(
43
61
)
44
62
45
63
# Create the project version (commit)
46
- client .projects .commits .create (
64
+ commit = client .projects .commits .create (
47
65
project_id = project_id ,
48
66
commit = {"message" : message , "source" : "cli" },
49
67
storage_uri = presigned_url_response .storage_uri ,
50
68
)
51
69
70
+ if wait_for_completion :
71
+ return wait_for_commit_completion (
72
+ client = client ,
73
+ project_version_id = commit .id ,
74
+ verbose = verbose ,
75
+ )
76
+
77
+ return None
78
+
52
79
53
80
def wait_for_commit_completion (
54
81
client : Openlayer , project_version_id : str , verbose : bool = True
55
82
) -> CommitRetrieveResponse :
56
83
"""Wait for a commit to be processed by the Openlayer platform.
57
84
58
85
Waits until the commit status is "completed" or "failed".
86
+
87
+ Args:
88
+ client: The Openlayer client.
89
+ project_version_id: The id of the project version (commit) to wait for.
90
+ verbose: Whether to print verbose output.
91
+
92
+ Returns:
93
+ The commit object.
59
94
"""
60
95
while True :
61
96
commit = client .commits .retrieve (project_version_id = project_version_id )
0 commit comments