From d7c84892a258c15b23fac3dedd2c074357595613 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 13 Mar 2025 19:26:21 +0000 Subject: [PATCH 1/2] feat(api): add endpoint to retrieve commit by id (#421) --- .stats.yml | 2 +- api.md | 10 ++ src/openlayer/resources/commits/commits.py | 93 +++++++++++++++ src/openlayer/types/__init__.py | 1 + .../types/commit_retrieve_response.py | 106 ++++++++++++++++++ tests/api_resources/test_commits.py | 98 ++++++++++++++++ 6 files changed, 309 insertions(+), 1 deletion(-) create mode 100644 src/openlayer/types/commit_retrieve_response.py create mode 100644 tests/api_resources/test_commits.py diff --git a/.stats.yml b/.stats.yml index dd473053..c2549479 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 14 +configured_endpoints: 15 diff --git a/api.md b/api.md index 3c4a9a44..6f719c19 100644 --- a/api.md +++ b/api.md @@ -39,6 +39,16 @@ Methods: # Commits +Types: + +```python +from openlayer.types import CommitRetrieveResponse +``` + +Methods: + +- client.commits.retrieve(project_version_id) -> CommitRetrieveResponse + ## TestResults Types: diff --git a/src/openlayer/resources/commits/commits.py b/src/openlayer/resources/commits/commits.py index b5382274..3e64e524 100644 --- a/src/openlayer/resources/commits/commits.py +++ b/src/openlayer/resources/commits/commits.py @@ -2,8 +2,17 @@ from __future__ import annotations +import httpx + +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource +from ..._response import ( + to_raw_response_wrapper, + to_streamed_response_wrapper, + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, +) from .test_results import ( TestResultsResource, AsyncTestResultsResource, @@ -12,6 +21,8 @@ TestResultsResourceWithStreamingResponse, AsyncTestResultsResourceWithStreamingResponse, ) +from ..._base_client import make_request_options +from ...types.commit_retrieve_response import CommitRetrieveResponse __all__ = ["CommitsResource", "AsyncCommitsResource"] @@ -40,6 +51,39 @@ def with_streaming_response(self) -> CommitsResourceWithStreamingResponse: """ return CommitsResourceWithStreamingResponse(self) + def retrieve( + self, + project_version_id: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> CommitRetrieveResponse: + """ + Retrieve a project version (commit) by its id. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not project_version_id: + raise ValueError(f"Expected a non-empty value for `project_version_id` but received {project_version_id!r}") + return self._get( + f"/versions/{project_version_id}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=CommitRetrieveResponse, + ) + class AsyncCommitsResource(AsyncAPIResource): @cached_property @@ -65,11 +109,48 @@ def with_streaming_response(self) -> AsyncCommitsResourceWithStreamingResponse: """ return AsyncCommitsResourceWithStreamingResponse(self) + async def retrieve( + self, + project_version_id: str, + *, + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. + # The extra values given here take precedence over values defined on the client or passed to this method. + extra_headers: Headers | None = None, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> CommitRetrieveResponse: + """ + Retrieve a project version (commit) by its id. + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not project_version_id: + raise ValueError(f"Expected a non-empty value for `project_version_id` but received {project_version_id!r}") + return await self._get( + f"/versions/{project_version_id}", + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + cast_to=CommitRetrieveResponse, + ) + class CommitsResourceWithRawResponse: def __init__(self, commits: CommitsResource) -> None: self._commits = commits + self.retrieve = to_raw_response_wrapper( + commits.retrieve, + ) + @cached_property def test_results(self) -> TestResultsResourceWithRawResponse: return TestResultsResourceWithRawResponse(self._commits.test_results) @@ -79,6 +160,10 @@ class AsyncCommitsResourceWithRawResponse: def __init__(self, commits: AsyncCommitsResource) -> None: self._commits = commits + self.retrieve = async_to_raw_response_wrapper( + commits.retrieve, + ) + @cached_property def test_results(self) -> AsyncTestResultsResourceWithRawResponse: return AsyncTestResultsResourceWithRawResponse(self._commits.test_results) @@ -88,6 +173,10 @@ class CommitsResourceWithStreamingResponse: def __init__(self, commits: CommitsResource) -> None: self._commits = commits + self.retrieve = to_streamed_response_wrapper( + commits.retrieve, + ) + @cached_property def test_results(self) -> TestResultsResourceWithStreamingResponse: return TestResultsResourceWithStreamingResponse(self._commits.test_results) @@ -97,6 +186,10 @@ class AsyncCommitsResourceWithStreamingResponse: def __init__(self, commits: AsyncCommitsResource) -> None: self._commits = commits + self.retrieve = async_to_streamed_response_wrapper( + commits.retrieve, + ) + @cached_property def test_results(self) -> AsyncTestResultsResourceWithStreamingResponse: return AsyncTestResultsResourceWithStreamingResponse(self._commits.test_results) diff --git a/src/openlayer/types/__init__.py b/src/openlayer/types/__init__.py index f607e733..c0333620 100644 --- a/src/openlayer/types/__init__.py +++ b/src/openlayer/types/__init__.py @@ -6,6 +6,7 @@ from .project_create_params import ProjectCreateParams as ProjectCreateParams from .project_list_response import ProjectListResponse as ProjectListResponse from .project_create_response import ProjectCreateResponse as ProjectCreateResponse +from .commit_retrieve_response import CommitRetrieveResponse as CommitRetrieveResponse from .inference_pipeline_update_params import InferencePipelineUpdateParams as InferencePipelineUpdateParams from .inference_pipeline_retrieve_params import InferencePipelineRetrieveParams as InferencePipelineRetrieveParams from .inference_pipeline_update_response import InferencePipelineUpdateResponse as InferencePipelineUpdateResponse diff --git a/src/openlayer/types/commit_retrieve_response.py b/src/openlayer/types/commit_retrieve_response.py new file mode 100644 index 00000000..6347a9a6 --- /dev/null +++ b/src/openlayer/types/commit_retrieve_response.py @@ -0,0 +1,106 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional +from datetime import datetime +from typing_extensions import Literal + +from pydantic import Field as FieldInfo + +from .._models import BaseModel + +__all__ = ["CommitRetrieveResponse", "Commit", "Links"] + + +class Commit(BaseModel): + id: str + """The commit id.""" + + author_id: str = FieldInfo(alias="authorId") + """The author id of the commit.""" + + file_size: Optional[int] = FieldInfo(alias="fileSize", default=None) + """The size of the commit bundle in bytes.""" + + message: str + """The commit message.""" + + ml_model_id: Optional[str] = FieldInfo(alias="mlModelId", default=None) + """The model id.""" + + storage_uri: str = FieldInfo(alias="storageUri") + """The storage URI where the commit bundle is stored.""" + + training_dataset_id: Optional[str] = FieldInfo(alias="trainingDatasetId", default=None) + """The training dataset id.""" + + validation_dataset_id: Optional[str] = FieldInfo(alias="validationDatasetId", default=None) + """The validation dataset id.""" + + date_created: Optional[datetime] = FieldInfo(alias="dateCreated", default=None) + """The commit creation date.""" + + git_commit_ref: Optional[str] = FieldInfo(alias="gitCommitRef", default=None) + """The ref of the corresponding git commit.""" + + git_commit_sha: Optional[int] = FieldInfo(alias="gitCommitSha", default=None) + """The SHA of the corresponding git commit.""" + + git_commit_url: Optional[str] = FieldInfo(alias="gitCommitUrl", default=None) + """The URL of the corresponding git commit.""" + + +class Links(BaseModel): + app: str + + +class CommitRetrieveResponse(BaseModel): + id: str + """The project version (commit) id.""" + + commit: Commit + """The details of a commit (project version).""" + + date_archived: Optional[datetime] = FieldInfo(alias="dateArchived", default=None) + """The commit archive date.""" + + date_created: datetime = FieldInfo(alias="dateCreated") + """The project version (commit) creation date.""" + + failing_goal_count: int = FieldInfo(alias="failingGoalCount") + """The number of tests that are failing for the commit.""" + + ml_model_id: Optional[str] = FieldInfo(alias="mlModelId", default=None) + """The model id.""" + + passing_goal_count: int = FieldInfo(alias="passingGoalCount") + """The number of tests that are passing for the commit.""" + + project_id: str = FieldInfo(alias="projectId") + """The project id.""" + + status: Literal["queued", "running", "paused", "failed", "completed", "unknown"] + """The commit status. + + Initially, the commit is `queued`, then, it switches to `running`. Finally, it + can be `paused`, `failed`, or `completed`. + """ + + status_message: Optional[str] = FieldInfo(alias="statusMessage", default=None) + """The commit status message.""" + + total_goal_count: int = FieldInfo(alias="totalGoalCount") + """The total number of tests for the commit.""" + + training_dataset_id: Optional[str] = FieldInfo(alias="trainingDatasetId", default=None) + """The training dataset id.""" + + validation_dataset_id: Optional[str] = FieldInfo(alias="validationDatasetId", default=None) + """The validation dataset id.""" + + archived: Optional[bool] = None + """Whether the commit is archived.""" + + deployment_status: Optional[str] = FieldInfo(alias="deploymentStatus", default=None) + """The deployment status associated with the commit's model.""" + + links: Optional[Links] = None diff --git a/tests/api_resources/test_commits.py b/tests/api_resources/test_commits.py new file mode 100644 index 00000000..07a33f5f --- /dev/null +++ b/tests/api_resources/test_commits.py @@ -0,0 +1,98 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from openlayer import Openlayer, AsyncOpenlayer +from tests.utils import assert_matches_type +from openlayer.types import CommitRetrieveResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestCommits: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + def test_method_retrieve(self, client: Openlayer) -> None: + commit = client.commits.retrieve( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) + assert_matches_type(CommitRetrieveResponse, commit, path=["response"]) + + @parametrize + def test_raw_response_retrieve(self, client: Openlayer) -> None: + response = client.commits.with_raw_response.retrieve( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + commit = response.parse() + assert_matches_type(CommitRetrieveResponse, commit, path=["response"]) + + @parametrize + def test_streaming_response_retrieve(self, client: Openlayer) -> None: + with client.commits.with_streaming_response.retrieve( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + commit = response.parse() + assert_matches_type(CommitRetrieveResponse, commit, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + def test_path_params_retrieve(self, client: Openlayer) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_version_id` but received ''"): + client.commits.with_raw_response.retrieve( + "", + ) + + +class TestAsyncCommits: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + async def test_method_retrieve(self, async_client: AsyncOpenlayer) -> None: + commit = await async_client.commits.retrieve( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) + assert_matches_type(CommitRetrieveResponse, commit, path=["response"]) + + @parametrize + async def test_raw_response_retrieve(self, async_client: AsyncOpenlayer) -> None: + response = await async_client.commits.with_raw_response.retrieve( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + commit = await response.parse() + assert_matches_type(CommitRetrieveResponse, commit, path=["response"]) + + @parametrize + async def test_streaming_response_retrieve(self, async_client: AsyncOpenlayer) -> None: + async with async_client.commits.with_streaming_response.retrieve( + "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + commit = await response.parse() + assert_matches_type(CommitRetrieveResponse, commit, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + async def test_path_params_retrieve(self, async_client: AsyncOpenlayer) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_version_id` but received ''"): + await async_client.commits.with_raw_response.retrieve( + "", + ) From 872081737bbbceff9200aa4852961178de7dad42 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 13 Mar 2025 19:26:58 +0000 Subject: [PATCH 2/2] release: 0.2.0-alpha.45 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 8 ++++++++ pyproject.toml | 2 +- src/openlayer/_version.py | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index ce266685..6b8327a3 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.2.0-alpha.44" + ".": "0.2.0-alpha.45" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b791912..49e52506 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ 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.45 (2025-03-13) + +Full Changelog: [v0.2.0-alpha.44...v0.2.0-alpha.45](https://github.com/openlayer-ai/openlayer-python/compare/v0.2.0-alpha.44...v0.2.0-alpha.45) + +### Features + +* **api:** add endpoint to retrieve commit by id ([#421](https://github.com/openlayer-ai/openlayer-python/issues/421)) ([d7c8489](https://github.com/openlayer-ai/openlayer-python/commit/d7c84892a258c15b23fac3dedd2c074357595613)) + ## 0.2.0-alpha.44 (2025-02-26) Full Changelog: [v0.2.0-alpha.43...v0.2.0-alpha.44](https://github.com/openlayer-ai/openlayer-python/compare/v0.2.0-alpha.43...v0.2.0-alpha.44) diff --git a/pyproject.toml b/pyproject.toml index d4becc59..3a4b252a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openlayer" -version = "0.2.0-alpha.44" +version = "0.2.0-alpha.45" 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 e2408930..6a778d14 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.44" # x-release-please-version +__version__ = "0.2.0-alpha.45" # x-release-please-version