Skip to content

Commit

Permalink
Enforce deprecation message format with EOL for google provider packa…
Browse files Browse the repository at this point in the history
…ge (#41637)

* Enforce deprecation message format with EOL for google provider package

* A custom @deprecated decorator for Google prvider package.
  • Loading branch information
moiseenkov authored Sep 1, 2024
1 parent b1e4f37 commit 86e3d29
Show file tree
Hide file tree
Showing 45 changed files with 928 additions and 774 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,7 @@ repos:
pass_filenames: true
files: ^airflow/.*\.py$
exclude: ^.*/.*_vendor/
additional_dependencies: ["rich>=12.4.4", "python-dateutil"]
- id: lint-chart-schema
name: Lint chart/values.schema.json file
entry: ./scripts/ci/pre_commit/chart_schema.py
Expand Down
132 changes: 79 additions & 53 deletions airflow/providers/google/cloud/hooks/bigquery.py

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions airflow/providers/google/cloud/hooks/cloud_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

from typing import TYPE_CHECKING, Sequence

from deprecated import deprecated
from google.api_core.client_options import ClientOptions
from google.api_core.exceptions import AlreadyExists
from google.api_core.gapic_v1.method import DEFAULT, _MethodDefault
from google.cloud.devtools.cloudbuild_v1 import CloudBuildAsyncClient, CloudBuildClient, GetBuildRequest

from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.providers.google.common.consts import CLIENT_INFO
from airflow.providers.google.common.deprecated import deprecated
from airflow.providers.google.common.hooks.base_google import PROVIDE_PROJECT_ID, GoogleBaseHook

if TYPE_CHECKING:
Expand Down Expand Up @@ -191,7 +191,8 @@ def create_build_without_waiting_for_result(

@GoogleBaseHook.fallback_to_default_project_id
@deprecated(
reason="Please use `create_build_without_waiting_for_result`",
planned_removal_date="March 01, 2025",
use_instead="create_build_without_waiting_for_result",
category=AirflowProviderDeprecationWarning,
)
def create_build(
Expand Down
26 changes: 13 additions & 13 deletions airflow/providers/google/cloud/hooks/dataflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from copy import deepcopy
from typing import TYPE_CHECKING, Any, Callable, Generator, Sequence, TypeVar, cast

from deprecated import deprecated
from google.cloud.dataflow_v1beta3 import (
GetJobRequest,
Job,
Expand All @@ -51,6 +50,7 @@

from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.providers.apache.beam.hooks.beam import BeamHook, BeamRunnerType, beam_options_to_args
from airflow.providers.google.common.deprecated import deprecated
from airflow.providers.google.common.hooks.base_google import (
PROVIDE_PROJECT_ID,
GoogleBaseAsyncHook,
Expand Down Expand Up @@ -594,12 +594,12 @@ def get_pipelines_conn(self) -> build:
@_fallback_to_project_id_from_variables
@GoogleBaseHook.fallback_to_default_project_id
@deprecated(
reason=(
"This method is deprecated. "
"Please use `airflow.providers.apache.beam.hooks.beam.start.start_java_pipeline` "
"to start pipeline and `providers.google.cloud.hooks.dataflow.DataflowHook.wait_for_done` "
"to wait for the required pipeline state."
),
planned_removal_date="March 01, 2025",
use_instead="airflow.providers.apache.beam.hooks.beam.start.start_java_pipeline, "
"providers.google.cloud.hooks.dataflow.DataflowHook.wait_for_done",
instructions="Please use airflow.providers.apache.beam.hooks.beam.start.start_java_pipeline "
"to start pipeline and providers.google.cloud.hooks.dataflow.DataflowHook.wait_for_done method "
"to wait for the required pipeline state instead.",
category=AirflowProviderDeprecationWarning,
)
def start_java_dataflow(
Expand Down Expand Up @@ -951,12 +951,12 @@ def extract_job_id(job: dict) -> str:
@_fallback_to_project_id_from_variables
@GoogleBaseHook.fallback_to_default_project_id
@deprecated(
reason=(
"This method is deprecated. "
"Please use `airflow.providers.apache.beam.hooks.beam.start.start_python_pipeline` "
"to start pipeline and `providers.google.cloud.hooks.dataflow.DataflowHook.wait_for_done` "
"to wait for the required pipeline state."
),
planned_removal_date="March 01, 2025",
use_instead="airflow.providers.apache.beam.hooks.beam.start.start_python_pipeline method, "
"providers.google.cloud.hooks.dataflow.DataflowHook.wait_for_done",
instructions="Please use airflow.providers.apache.beam.hooks.beam.start.start_python_pipeline method "
"to start pipeline and providers.google.cloud.hooks.dataflow.DataflowHook.wait_for_done method "
"to wait for the required pipeline state instead.",
category=AirflowProviderDeprecationWarning,
)
def start_python_dataflow(
Expand Down
6 changes: 3 additions & 3 deletions airflow/providers/google/cloud/hooks/datapipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@

from typing import TYPE_CHECKING

from deprecated import deprecated

from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.providers.google.cloud.hooks.dataflow import DataflowHook
from airflow.providers.google.common.deprecated import deprecated
from airflow.providers.google.common.hooks.base_google import GoogleBaseHook

if TYPE_CHECKING:
Expand All @@ -34,7 +33,8 @@


@deprecated(
reason="This hook is deprecated and will be removed after 01.12.2024. Please use `DataflowHook`.",
planned_removal_date="December 01, 2024",
use_instead="DataflowHook",
category=AirflowProviderDeprecationWarning,
)
class DataPipelineHook(DataflowHook):
Expand Down
41 changes: 15 additions & 26 deletions airflow/providers/google/cloud/hooks/kubernetes_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import time
from typing import TYPE_CHECKING, Sequence

from deprecated import deprecated
from google.api_core.exceptions import NotFound
from google.api_core.gapic_v1.method import DEFAULT, _MethodDefault
from google.auth.transport import requests as google_requests
Expand All @@ -43,6 +42,7 @@
from airflow.providers.cncf.kubernetes.hooks.kubernetes import AsyncKubernetesHook, KubernetesHook
from airflow.providers.cncf.kubernetes.kube_client import _enable_tcp_keepalive
from airflow.providers.google.common.consts import CLIENT_INFO
from airflow.providers.google.common.deprecated import deprecated
from airflow.providers.google.common.hooks.base_google import (
PROVIDE_PROJECT_ID,
GoogleBaseAsyncHook,
Expand Down Expand Up @@ -139,10 +139,8 @@ def get_cluster_manager_client(self) -> ClusterManagerClient:
# To preserve backward compatibility
# TODO: remove one day
@deprecated(
reason=(
"The get_conn method has been deprecated. "
"You should use the get_cluster_manager_client method."
),
planned_removal_date="November 01, 2024",
use_instead="get_cluster_manager_client",
category=AirflowProviderDeprecationWarning,
)
def get_conn(self) -> container_v1.ClusterManagerClient:
Expand All @@ -151,7 +149,8 @@ def get_conn(self) -> container_v1.ClusterManagerClient:
# To preserve backward compatibility
# TODO: remove one day
@deprecated(
reason="The get_client method has been deprecated. You should use the get_conn method.",
planned_removal_date="November 01, 2024",
use_instead="get_cluster_manager_client",
category=AirflowProviderDeprecationWarning,
)
def get_client(self) -> ClusterManagerClient:
Expand Down Expand Up @@ -580,32 +579,26 @@ def _get_config(self) -> async_client.configuration.Configuration:


@deprecated(
reason=(
"The `GKEDeploymentHook` class is deprecated and will be removed after 01.10.2024, please use "
"`GKEKubernetesHook` instead."
),
planned_removal_date="October 01, 2024",
use_instead="GKEKubernetesHook",
category=AirflowProviderDeprecationWarning,
)
class GKEDeploymentHook(GKEKubernetesHook):
"""Google Kubernetes Engine Deployment APIs."""


@deprecated(
reason=(
"The `GKECustomResourceHook` class is deprecated and will be removed after 01.10.2024, please use "
"`GKEKubernetesHook` instead."
),
planned_removal_date="October 01, 2024",
use_instead="GKEKubernetesHook",
category=AirflowProviderDeprecationWarning,
)
class GKECustomResourceHook(GKEKubernetesHook):
"""Google Kubernetes Engine Custom Resource APIs."""


@deprecated(
reason=(
"The `GKEPodHook` class is deprecated and will be removed after 01.10.2024, please use "
"`GKEKubernetesHook` instead."
),
planned_removal_date="October 01, 2024",
use_instead="GKEKubernetesHook",
category=AirflowProviderDeprecationWarning,
)
class GKEPodHook(GKEKubernetesHook):
Expand All @@ -631,21 +624,17 @@ def __init__(


@deprecated(
reason=(
"The `GKEJobHook` class is deprecated and will be removed after 01.10.2024, please use "
"`GKEKubernetesHook` instead."
),
planned_removal_date="October 01, 2024",
use_instead="GKEKubernetesHook",
category=AirflowProviderDeprecationWarning,
)
class GKEJobHook(GKEKubernetesHook):
"""Google Kubernetes Engine Job APIs."""


@deprecated(
reason=(
"The `GKEPodAsyncHook` class is deprecated and will be removed after 01.10.2024, please use "
"`GKEKubernetesAsyncHook` instead."
),
planned_removal_date="October 01, 2024",
use_instead="GKEKubernetesAsyncHook",
category=AirflowProviderDeprecationWarning,
)
class GKEPodAsyncHook(GKEKubernetesAsyncHook):
Expand Down
12 changes: 5 additions & 7 deletions airflow/providers/google/cloud/hooks/life_sciences.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,21 @@
from typing import Sequence

import google.api_core.path_template
from deprecated import deprecated
from googleapiclient.discovery import build

from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.providers.google.common.deprecated import deprecated
from airflow.providers.google.common.hooks.base_google import GoogleBaseHook

# Time to sleep between active checks of the operation results
TIME_TO_SLEEP_IN_SECONDS = 5


@deprecated(
reason=(
"This hook is deprecated. Consider using "
"Google Cloud Batch Operators' hook instead. "
"The Life Sciences API (beta) will be discontinued "
"on July 8, 2025 in favor of Google Cloud Batch."
),
planned_removal_date="March 01, 2025",
use_instead="Google Cloud Batch Operators' hook",
reason="The Life Sciences API (beta) will be discontinued on July 8, 2025 "
"in favor of Google Cloud Batch.",
category=AirflowProviderDeprecationWarning,
)
class LifeSciencesHook(GoogleBaseHook):
Expand Down
6 changes: 3 additions & 3 deletions airflow/providers/google/cloud/hooks/secret_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from functools import cached_property
from typing import TYPE_CHECKING, Sequence

from deprecated import deprecated
from google.api_core.gapic_v1.method import DEFAULT, _MethodDefault
from google.cloud.secretmanager_v1 import (
AccessSecretVersionResponse,
Expand All @@ -35,6 +34,7 @@
from airflow.exceptions import AirflowProviderDeprecationWarning
from airflow.providers.google.cloud._internal_client.secret_manager_client import _SecretManagerClient
from airflow.providers.google.common.consts import CLIENT_INFO
from airflow.providers.google.common.deprecated import deprecated
from airflow.providers.google.common.hooks.base_google import PROVIDE_PROJECT_ID, GoogleBaseHook

if TYPE_CHECKING:
Expand All @@ -43,8 +43,8 @@


@deprecated(
reason="The SecretsManagerHook is deprecated and will be removed after 01.11.2024. "
"Please use GoogleCloudSecretManagerHook instead.",
planned_removal_date="November 01, 2024",
use_instead="GoogleCloudSecretManagerHook",
category=AirflowProviderDeprecationWarning,
)
class SecretsManagerHook(GoogleBaseHook):
Expand Down
17 changes: 11 additions & 6 deletions airflow/providers/google/cloud/hooks/vertex_ai/custom_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import asyncio
from typing import TYPE_CHECKING, Any, Sequence

from deprecated import deprecated
from google.api_core.client_options import ClientOptions
from google.api_core.gapic_v1.method import DEFAULT, _MethodDefault
from google.cloud.aiplatform import (
Expand All @@ -44,6 +43,7 @@

from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
from airflow.providers.google.common.consts import CLIENT_INFO
from airflow.providers.google.common.deprecated import deprecated
from airflow.providers.google.common.hooks.base_google import GoogleBaseAsyncHook, GoogleBaseHook

if TYPE_CHECKING:
Expand Down Expand Up @@ -380,7 +380,8 @@ def _run_job(

@GoogleBaseHook.fallback_to_default_project_id
@deprecated(
reason="Please use `PipelineJobHook.cancel_pipeline_job`",
planned_removal_date="March 01, 2025",
use_instead="PipelineJobHook.cancel_pipeline_job",
category=AirflowProviderDeprecationWarning,
)
def cancel_pipeline_job(
Expand Down Expand Up @@ -509,7 +510,8 @@ def cancel_custom_job(

@GoogleBaseHook.fallback_to_default_project_id
@deprecated(
reason="Please use `PipelineJobHook.create_pipeline_job`",
planned_removal_date="March 01, 2025",
use_instead="PipelineJobHook.create_pipeline_job",
category=AirflowProviderDeprecationWarning,
)
def create_pipeline_job(
Expand Down Expand Up @@ -2980,7 +2982,8 @@ def delete_custom_job(

@GoogleBaseHook.fallback_to_default_project_id
@deprecated(
reason="Please use `PipelineJobHook.get_pipeline_job`",
planned_removal_date="March 01, 2025",
use_instead="PipelineJobHook.get_pipeline_job",
category=AirflowProviderDeprecationWarning,
)
def get_pipeline_job(
Expand Down Expand Up @@ -3085,7 +3088,8 @@ def get_custom_job(

@GoogleBaseHook.fallback_to_default_project_id
@deprecated(
reason="Please use `PipelineJobHook.list_pipeline_jobs`",
planned_removal_date="March 01, 2025",
use_instead="PipelineJobHook.list_pipeline_jobs",
category=AirflowProviderDeprecationWarning,
)
def list_pipeline_jobs(
Expand Down Expand Up @@ -3301,7 +3305,8 @@ def list_custom_jobs(

@GoogleBaseHook.fallback_to_default_project_id
@deprecated(
reason="Please use `PipelineJobHook.delete_pipeline_job`",
planned_removal_date="March 01, 2025",
use_instead="PipelineJobHook.delete_pipeline_job",
category=AirflowProviderDeprecationWarning,
)
def delete_pipeline_job(
Expand Down
Loading

0 comments on commit 86e3d29

Please sign in to comment.