From 354cc2959454864f7e81a805731d7a9e13fc775e Mon Sep 17 00:00:00 2001 From: Alex Streed Date: Thu, 14 Mar 2024 11:21:27 -0500 Subject: [PATCH 1/3] Deprecate `CloudRunJob` and `VertexAICustomTrainingJob` infrastructure blocks --- prefect_gcp/aiplatform.py | 18 ++++++++++++++++-- prefect_gcp/cloud_run.py | 18 ++++++++++++++++-- tests/test_deprecation.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 tests/test_deprecation.py diff --git a/prefect_gcp/aiplatform.py b/prefect_gcp/aiplatform.py index ff02c10..06f5e99 100644 --- a/prefect_gcp/aiplatform.py +++ b/prefect_gcp/aiplatform.py @@ -1,5 +1,10 @@ """ - +DEPRECATION WARNING: + +This module is deprecated as of March 2024 and will not be available after September 2024. +It has been replaced by the Vertex AI worker, which offers enhanced functionality and better performance. + +For upgrade instructions, see https://docs.prefect.io/latest/guides/upgrade-guide-agents-to-workers/. Integrations with Google AI Platform. @@ -50,7 +55,7 @@ ) job.preview() ``` -""" +""" # noqa import datetime import re @@ -60,6 +65,7 @@ from uuid import uuid4 from anyio.abc import TaskStatus +from prefect._internal.compatibility.deprecated import deprecated_class from prefect.exceptions import InfrastructureNotFound from prefect.infrastructure import Infrastructure, InfrastructureResult from prefect.utilities.asyncutils import run_sync_in_worker_thread, sync_compatible @@ -107,6 +113,14 @@ class VertexAICustomTrainingJobResult(InfrastructureResult): """Result from a Vertex AI custom training job.""" +@deprecated_class( + start_date="Mar 2024", + help=( + "Use the Vertex AI worker instead." + " Refer to the upgrade guide for more information:" + " https://docs.prefect.io/latest/guides/upgrade-guide-agents-to-workers/." + ), +) class VertexAICustomTrainingJob(Infrastructure): """ Infrastructure block used to run Vertex AI custom training jobs. diff --git a/prefect_gcp/cloud_run.py b/prefect_gcp/cloud_run.py index b16989e..667e182 100644 --- a/prefect_gcp/cloud_run.py +++ b/prefect_gcp/cloud_run.py @@ -1,5 +1,10 @@ """ - +DEPRECATION WARNING: + +This module is deprecated as of March 2024 and will not be available after September 2024. +It has been replaced by the Cloud Run and Cloud Run V2 workers, which offer enhanced functionality and better performance. + +For upgrade instructions, see https://docs.prefect.io/latest/guides/upgrade-guide-agents-to-workers/. Integrations with Google Cloud Run Job. @@ -26,7 +31,7 @@ ).run() ``` -""" +""" # noqa from __future__ import annotations @@ -42,6 +47,7 @@ from google.api_core.client_options import ClientOptions from googleapiclient import discovery from googleapiclient.discovery import Resource +from prefect._internal.compatibility.deprecated import deprecated_class from prefect.exceptions import InfrastructureNotFound from prefect.infrastructure.base import Infrastructure, InfrastructureResult from prefect.utilities.asyncutils import run_sync_in_worker_thread, sync_compatible @@ -210,6 +216,14 @@ class CloudRunJobResult(InfrastructureResult): """Result from a Cloud Run Job.""" +@deprecated_class( + start_date="Mar 2024", + help=( + "Use the Cloud Run or Cloud Run v2 worker instead." + " Refer to the upgrade guide for more information:" + " https://docs.prefect.io/latest/guides/upgrade-guide-agents-to-workers/." + ), +) class CloudRunJob(Infrastructure): """ diff --git a/tests/test_deprecation.py b/tests/test_deprecation.py new file mode 100644 index 0000000..1213922 --- /dev/null +++ b/tests/test_deprecation.py @@ -0,0 +1,29 @@ +import pytest +from prefect._internal.compatibility.deprecated import PrefectDeprecationWarning + +from prefect_gcp.aiplatform import VertexAICustomTrainingJob +from prefect_gcp.cloud_run import CloudRunJob + + +@pytest.mark.parametrize( + "InfraBlock, expected_message", + [ + ( + CloudRunJob, + "prefect_gcp.cloud_run.CloudRunJob has been deprecated." + " It will not be available after Sep 2024." + " Use the Vertex AI worker instead." + " Refer to the upgrade guide for more information", + ), + ( + VertexAICustomTrainingJob, + "prefect_gcp.aiplaform.VertexAICustomTrainingJob has been deprecated." + " It will not be available after Sep 2024." + " Use the Cloud Run or Cloud Run v2 worker instead." + " Refer to the upgrade guide for more information", + ), + ], +) +def test_infra_blocks_emit_a_deprecation_warning(InfraBlock, expected_message): + with pytest.warns(PrefectDeprecationWarning, match=expected_message): + InfraBlock() From 320e3e7a3a89dc5c54df46444c5a71088115590c Mon Sep 17 00:00:00 2001 From: Alex Streed Date: Thu, 14 Mar 2024 18:52:30 -0500 Subject: [PATCH 2/3] Bump minimum prefect version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 5294c93..1628658 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -prefect>=2.14.10 +prefect>=2.16.4 google-api-python-client>=2.20.0 google-cloud-storage>=2.0.0 tenacity>=8.0.0 From 845e3970cc37eb4a205de2926066023453ff3116 Mon Sep 17 00:00:00 2001 From: Alex Streed Date: Fri, 15 Mar 2024 08:34:30 -0500 Subject: [PATCH 3/3] Fixes tests --- tests/test_deprecation.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/test_deprecation.py b/tests/test_deprecation.py index 1213922..479861f 100644 --- a/tests/test_deprecation.py +++ b/tests/test_deprecation.py @@ -6,24 +6,31 @@ @pytest.mark.parametrize( - "InfraBlock, expected_message", + "InfraBlock, kwargs, expected_message", [ ( CloudRunJob, + {"image": "foo", "region": "us-central1"}, "prefect_gcp.cloud_run.CloudRunJob has been deprecated." " It will not be available after Sep 2024." - " Use the Vertex AI worker instead." + " Use the Cloud Run or Cloud Run v2 worker instead." " Refer to the upgrade guide for more information", ), ( VertexAICustomTrainingJob, - "prefect_gcp.aiplaform.VertexAICustomTrainingJob has been deprecated." + {"image": "foo", "region": "us-central1"}, + "prefect_gcp.aiplatform.VertexAICustomTrainingJob has been deprecated." " It will not be available after Sep 2024." - " Use the Cloud Run or Cloud Run v2 worker instead." + " Use the Vertex AI worker instead." " Refer to the upgrade guide for more information", ), ], ) -def test_infra_blocks_emit_a_deprecation_warning(InfraBlock, expected_message): +def test_infra_blocks_emit_a_deprecation_warning( + InfraBlock, kwargs, expected_message, gcp_credentials +): with pytest.warns(PrefectDeprecationWarning, match=expected_message): - InfraBlock() + if InfraBlock == CloudRunJob: + InfraBlock(**kwargs, credentials=gcp_credentials) + else: + InfraBlock(**kwargs, gcp_credentials=gcp_credentials)