From d59dfe023b6d6e164c6e272cc410dc6b5f4bcec8 Mon Sep 17 00:00:00 2001 From: Gustavo Cid Ornelas Date: Fri, 25 Apr 2025 18:00:11 +0000 Subject: [PATCH 1/2] feat: feat: add convenience function that copies tests from one project to another --- src/openlayer/lib/core/tests.py | 76 +++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/openlayer/lib/core/tests.py diff --git a/src/openlayer/lib/core/tests.py b/src/openlayer/lib/core/tests.py new file mode 100644 index 00000000..68633b13 --- /dev/null +++ b/src/openlayer/lib/core/tests.py @@ -0,0 +1,76 @@ +"""Module containing convenience functions for the tests API.""" + +from typing import Optional, List +from openlayer import Openlayer + + +def copy_tests( + client: Openlayer, + origin_project_id: str, + target_project_id: str, + verbose: bool = False, + test_ids: Optional[List[str]] = None, +) -> None: + """Copy tests from one project to another. + + Args: + client (Openlayer): The Openlayer client. + origin_project_id (str): The ID of the origin project (where the tests + are). + target_project_id (str): The ID of the target project (where the tests + will be copied to). + verbose (bool): Whether to print verbose output. + test_ids (List[str]): The IDs of the tests to copy. If not provided, all + tests will be copied. + """ + tests = client.projects.tests.list(project_id=origin_project_id) + + if test_ids is None and verbose: + print("Copying all tests from the origin project to the target project.") + else: + print( + "Copying the following tests from the origin project to" + f" the target project: {test_ids}" + ) + + for test in tests.items: + if test.id in test_ids: + thresholds = _parse_thresholds(test.thresholds) + client.projects.tests.create( + project_id=target_project_id, + name=test.name, + description=test.description, + type=test.type, + subtype=test.subtype, + thresholds=thresholds, + uses_production_data=test.uses_production_data, + evaluation_window=test.evaluation_window, + delay_window=test.delay_window, + uses_training_dataset=test.uses_training_dataset, + uses_validation_dataset=test.uses_validation_dataset, + uses_ml_model=test.uses_ml_model, + ) + if verbose: + print( + f"Copied test '{test.id}' - '{test.name}' from the" + " origin project to the target project." + ) + + +def _parse_thresholds(thresholds: List[dict]) -> List[dict]: + """Parse the thresholds from the test to the format required by the create + test endpoint.""" + thresholds = [] + for threshold in thresholds: + current_threshold = { + "insightName": threshold.insight_name, + "measurement": threshold.measurement, + "operator": threshold.operator, + "value": threshold.value, + } + + if threshold.get("insightParameters"): + current_threshold["insightParameters"] = threshold["insightParameters"] + thresholds.append(current_threshold) + + return thresholds From b96de56b7c3ebef3b08bd74abc0108f8b06f5a5b Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 25 Apr 2025 18:00:32 +0000 Subject: [PATCH 2/2] release: 0.2.0-alpha.61 --- .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 39e98787..579b50b0 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.2.0-alpha.60" + ".": "0.2.0-alpha.61" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 72e6d93f..e38837c9 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.61 (2025-04-25) + +Full Changelog: [v0.2.0-alpha.60...v0.2.0-alpha.61](https://github.com/openlayer-ai/openlayer-python/compare/v0.2.0-alpha.60...v0.2.0-alpha.61) + +### Features + +* feat: add convenience function that copies tests from one project to another ([d59dfe0](https://github.com/openlayer-ai/openlayer-python/commit/d59dfe023b6d6e164c6e272cc410dc6b5f4bcec8)) + ## 0.2.0-alpha.60 (2025-04-25) Full Changelog: [v0.2.0-alpha.59...v0.2.0-alpha.60](https://github.com/openlayer-ai/openlayer-python/compare/v0.2.0-alpha.59...v0.2.0-alpha.60) diff --git a/pyproject.toml b/pyproject.toml index 329aebc1..c4c668eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openlayer" -version = "0.2.0-alpha.60" +version = "0.2.0-alpha.61" 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 7826373b..2b3f4a02 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.60" # x-release-please-version +__version__ = "0.2.0-alpha.61" # x-release-please-version