Skip to content

Commit

Permalink
Replace deprecated module and operator in example_tasks.py (#13527)
Browse files Browse the repository at this point in the history
- `from airflow.utils.helpers import chain` to `from airflow.models.baseoperator import chain`

This commit also adds Bowler refactor for backport packages
  • Loading branch information
kaxil authored Jan 7, 2021
1 parent 8ab964e commit 2fb6834
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from google.protobuf import timestamp_pb2

from airflow import models
from airflow.models.baseoperator import chain
from airflow.operators.bash import BashOperator
from airflow.providers.google.cloud.operators.tasks import (
CloudTasksQueueCreateOperator,
Expand All @@ -46,7 +47,6 @@
CloudTasksTasksListOperator,
)
from airflow.utils.dates import days_ago
from airflow.utils.helpers import chain

timestamp = timestamp_pb2.Timestamp()
timestamp.FromDatetime(datetime.now() + timedelta(hours=12)) # pylint: disable=no-member
Expand Down
13 changes: 13 additions & 0 deletions dev/provider_packages/refactor_provider_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,13 @@ def pure_airflow_models_filter(node: LN, capture: Capture, filename: Filename) -
"""Check if select is exactly [airflow, . , models]"""
return len(list(node.children[1].leaves())) == 3

def _contains_chain_in_import_filter(node: LN, capture: Capture, filename: Filename) -> bool:
if "module_import" in capture:
return bool("chain" in capture["module_import"].value) and filename.startswith(
"./airflow/providers/google/"
)
return False

os.makedirs(
os.path.join(get_target_providers_package_folder("google"), "common", "utils"), exist_ok=True
)
Expand Down Expand Up @@ -668,6 +675,12 @@ def pure_airflow_models_filter(node: LN, capture: Capture, filename: Filename) -
.rename("airflow.providers.google.common.utils.process_utils")
)

(
self.qry.select_module("airflow.models.baseoperator")
.filter(callback=_contains_chain_in_import_filter)
.rename("airflow.providers.google.common.utils.helpers")
)

(
self.qry.select_module("airflow.utils.helpers")
.filter(callback=google_package_filter)
Expand Down

0 comments on commit 2fb6834

Please sign in to comment.