diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 3a59076c..ba6351db 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.2.0-alpha.47" + ".": "0.2.0-alpha.48" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c7e8fa0..f4e93dec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 0.2.0-alpha.48 (2025-03-18) + +Full Changelog: [v0.2.0-alpha.47...v0.2.0-alpha.48](https://github.com/openlayer-ai/openlayer-python/compare/v0.2.0-alpha.47...v0.2.0-alpha.48) + +### Features + +* feat: add option to wait for commit completion to push function ([b3b4afd](https://github.com/openlayer-ai/openlayer-python/commit/b3b4afd998c28df816f4223fc0eebc2ab0882b8b)) +* feat: add wait_for_commit_completion convenience method ([f71e29a](https://github.com/openlayer-ai/openlayer-python/commit/f71e29af2602d5eb08a88de02f834a5f654aeec8)) + ## 0.2.0-alpha.47 (2025-03-17) Full Changelog: [v0.2.0-alpha.46...v0.2.0-alpha.47](https://github.com/openlayer-ai/openlayer-python/compare/v0.2.0-alpha.46...v0.2.0-alpha.47) diff --git a/pyproject.toml b/pyproject.toml index e2d4a592..53947155 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openlayer" -version = "0.2.0-alpha.47" +version = "0.2.0-alpha.48" description = "The official Python library for the openlayer API" dynamic = ["readme"] license = "Apache-2.0" diff --git a/src/openlayer/_version.py b/src/openlayer/_version.py index e4de22de..17ba4a64 100644 --- a/src/openlayer/_version.py +++ b/src/openlayer/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. __title__ = "openlayer" -__version__ = "0.2.0-alpha.47" # x-release-please-version +__version__ = "0.2.0-alpha.48" # x-release-please-version diff --git a/src/openlayer/lib/data/commit.py b/src/openlayer/lib/data/commit.py index e94e8ff7..b46ced99 100644 --- a/src/openlayer/lib/data/commit.py +++ b/src/openlayer/lib/data/commit.py @@ -3,11 +3,13 @@ import os import tarfile import tempfile +import time from typing import Optional from ... import Openlayer from . import StorageType, _upload +from ...types.commit_retrieve_response import CommitRetrieveResponse def push( @@ -16,10 +18,28 @@ def push( project_id: str, message: str = "New commit", storage_type: Optional[StorageType] = None, -) -> None: + wait_for_completion: bool = False, + verbose: bool = False, +) -> Optional[CommitRetrieveResponse]: """Push a new commit to the Openlayer platform. - This is equivalent to running `openlayer push` from the Openlayer CLI.""" + This is equivalent to running `openlayer push` from the Openlayer CLI. + + If `wait_for_completion` is True, the function will wait for the commit to be + completed and return the commit object. + + Args: + client: The Openlayer client. + directory: The directory to push. + project_id: The id of the project to push to. + message: The commit message. + storage_type: The storage type to use. + wait_for_completion: Whether to wait for the commit to be completed. + verbose: Whether to print verbose output. + + Returns: + The commit object if `wait_for_completion` is True, otherwise None. + """ if not os.path.exists(directory): raise ValueError(f"Directory {directory} does not exist.") @@ -41,8 +61,52 @@ def push( ) # Create the project version (commit) - client.projects.commits.create( + commit = client.projects.commits.create( project_id=project_id, commit={"message": message, "source": "cli"}, storage_uri=presigned_url_response.storage_uri, ) + + if wait_for_completion: + return wait_for_commit_completion( + client=client, + project_version_id=commit.id, + verbose=verbose, + ) + + return None + + +def wait_for_commit_completion( + client: Openlayer, project_version_id: str, verbose: bool = True +) -> CommitRetrieveResponse: + """Wait for a commit to be processed by the Openlayer platform. + + Waits until the commit status is "completed" or "failed". + + Args: + client: The Openlayer client. + project_version_id: The id of the project version (commit) to wait for. + verbose: Whether to print verbose output. + + Returns: + The commit object. + """ + while True: + commit = client.commits.retrieve(project_version_id=project_version_id) + if commit.status == "completed": + if verbose: + print(f"Commit {project_version_id} completed successfully.") + return commit + elif commit.status == "failed": + raise Exception( + f"Commit {project_version_id} failed with status message:" + f" {commit.status_message}" + ) + else: + if verbose: + print( + f"Commit {project_version_id} is still processing (status:" + f" {commit.status})..." + ) + time.sleep(1)