Skip to content

Commit 86d5b27

Browse files
authored
Make @task import from airflow.sdk (#48896)
closes #48811
1 parent 6f8480c commit 86d5b27

File tree

116 files changed

+1023
-694
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+1023
-694
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ repos:
646646
language: python
647647
entry: ./scripts/ci/pre_commit/check_init_decorator_arguments.py
648648
pass_filenames: false
649-
files: ^airflow-core/src/airflow/models/dag\.py$|^airflow-core/src/airflow/(?:decorators|utils)/task_group\.py$
649+
files: ^task-sdk/src/airflow/sdk/definitions/dag\.py$|^task-sdk/src/airflow/sdk/definitions/decorators/task_group\.py$
650650
additional_dependencies: ['rich>=12.4.4']
651651
- id: check-template-context-variable-in-sync
652652
name: Sync template context variable refs

airflow-core/docs/authoring-and-scheduling/dynamic-task-mapping.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ In this example, you have a regular data delivery to an S3 bucket and want to ap
254254
from datetime import datetime
255255
256256
from airflow.sdk import DAG
257-
from airflow.decorators import task
257+
from airflow.sdk import task
258258
from airflow.providers.amazon.aws.hooks.s3 import S3Hook
259259
from airflow.providers.amazon.aws.operators.s3 import S3ListOperator
260260

airflow-core/docs/best-practices.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Not avoiding top-level DAG code:
125125
import pendulum
126126
127127
from airflow.sdk import DAG
128-
from airflow.decorators import task
128+
from airflow.sdk import task
129129
130130
131131
def expensive_api_call():
@@ -154,7 +154,7 @@ Avoiding top-level DAG code:
154154
import pendulum
155155
156156
from airflow.sdk import DAG
157-
from airflow.decorators import task
157+
from airflow.sdk import task
158158
159159
160160
def expensive_api_call():
@@ -536,7 +536,7 @@ It's easier to grab the concept with an example. Let's say that we have the foll
536536
from datetime import datetime
537537
538538
from airflow.sdk import DAG
539-
from airflow.decorators import task
539+
from airflow.sdk import task
540540
from airflow.exceptions import AirflowException
541541
from airflow.providers.standard.operators.bash import BashOperator
542542
from airflow.utils.trigger_rule import TriggerRule

airflow-core/docs/core-concepts/dags.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Or, you can use the ``@dag`` decorator to :ref:`turn a function into a DAG gener
8383
8484
import datetime
8585
86-
from airflow.decorators import dag
86+
from airflow.sdk import dag
8787
from airflow.providers.standard.operators.empty import EmptyOperator
8888
8989
@@ -458,7 +458,7 @@ You can also combine this with the :ref:`concepts:depends-on-past` functionality
458458
# dags/branch_without_trigger.py
459459
import pendulum
460460
461-
from airflow.decorators import task
461+
from airflow.sdk import task
462462
from airflow.sdk import DAG
463463
from airflow.providers.standard.operators.empty import EmptyOperator
464464
@@ -557,7 +557,7 @@ Dependency relationships can be applied across all tasks in a TaskGroup with the
557557
.. code-block:: python
558558
:emphasize-lines: 4,12
559559
560-
from airflow.decorators import task_group
560+
from airflow.sdk import task_group
561561
562562
563563
@task_group()
@@ -578,7 +578,7 @@ TaskGroup also supports ``default_args`` like DAG, it will overwrite the ``defau
578578
import datetime
579579
580580
from airflow.sdk import DAG
581-
from airflow.decorators import task_group
581+
from airflow.sdk import task_group
582582
from airflow.providers.standard.operators.bash import BashOperator
583583
from airflow.providers.standard.operators.empty import EmptyOperator
584584

airflow-core/docs/core-concepts/params.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Use a dictionary that maps Param names to either a :class:`~airflow.sdk.definiti
3939
:emphasize-lines: 7-10
4040
4141
from airflow.sdk import DAG
42-
from airflow.decorators import task
42+
from airflow.sdk import task
4343
from airflow.sdk import Param
4444
4545
with DAG(

airflow-core/docs/core-concepts/taskflow.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ If you write most of your dags using plain Python code rather than Operators, th
2424

2525
TaskFlow takes care of moving inputs and outputs between your Tasks using XComs for you, as well as automatically calculating dependencies - when you call a TaskFlow function in your DAG file, rather than executing it, you will get an object representing the XCom for the result (an ``XComArg``), that you can then use as inputs to downstream tasks or operators. For example::
2626

27-
from airflow.decorators import task
27+
from airflow.sdk import task
2828
from airflow.providers.email import EmailOperator
2929

3030
@task
@@ -112,7 +112,7 @@ a ``Asset``, which is ``@attr.define`` decorated, together with TaskFlow.
112112
import requests
113113
114114
from airflow import Asset
115-
from airflow.decorators import dag, task
115+
from airflow.sdk import dag, task
116116
117117
SRC = Asset(
118118
"https://www.ncei.noaa.gov/access/monitoring/climate-at-a-glance/global/time-series/globe/land_ocean/ytd/12/1880-2022.json"

airflow-core/docs/core-concepts/tasks.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ If you'd like to reproduce task instance heartbeat timeouts for development/test
200200

201201
.. code-block:: python
202202
203-
from airflow.decorators import dag
203+
from airflow.sdk import dag
204204
from airflow.providers.standard.operators.bash import BashOperator
205205
from datetime import datetime
206206

airflow-core/docs/faq.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ until ``min_file_process_interval`` is reached since DAG Parser will look for mo
182182
:name: dag_loader.py
183183
184184
from airflow.sdk import DAG
185-
from airflow.decorators import task
185+
from airflow.sdk import task
186186
187187
import pendulum
188188
@@ -413,7 +413,7 @@ upstream task.
413413
414414
import pendulum
415415
416-
from airflow.decorators import dag, task
416+
from airflow.sdk import dag, task
417417
from airflow.exceptions import AirflowException
418418
from airflow.utils.trigger_rule import TriggerRule
419419

airflow-core/docs/howto/create-custom-decorator.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ tasks. The steps to create and register ``@task.foo`` are:
4343
.. code-block:: python
4444
4545
from typing import TYPE_CHECKING
46-
from airflow.decorators.base import task_decorator_factory
46+
from airflow.sdk.bases.decorator import task_decorator_factory
4747
4848
if TYPE_CHECKING:
49-
from airflow.decorators.base import TaskDecorator
49+
from airflow.sdk.bases.decorator import TaskDecorator
5050
5151
5252
def foo_task(
@@ -96,11 +96,11 @@ tasks. The steps to create and register ``@task.foo`` are:
9696
For better or worse, Python IDEs can not auto-complete dynamically
9797
generated methods (see `JetBrain's write up on the subject <https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000665110-auto-completion-for-dynamic-module-attributes-in-python>`_).
9898

99-
To hack around this problem, a type stub ``airflow/decorators/__init__.pyi`` is provided to statically declare
99+
To hack around this problem, a type stub ``airflow/sdk/definitions/decorators/__init__.pyi`` is provided to statically declare
100100
the type signature of each task decorator. A newly added task decorator should declare its signature stub
101101
like this:
102102

103-
.. exampleinclude:: /../src/airflow/decorators/__init__.pyi
103+
.. exampleinclude:: ../../../task-sdk/src/airflow/sdk/definitions/decorators/__init__.pyi
104104
:language: python
105105
:start-after: [START decorator_signature]
106106
:end-before: [END decorator_signature]
@@ -114,7 +114,7 @@ If the new decorator can be used without arguments (e.g. ``@task.python`` instea
114114
You should also add an overload that takes a single callable immediately after the "real" definition so mypy
115115
can recognize the function as a "bare decorator":
116116

117-
.. exampleinclude:: /../src/airflow/decorators/__init__.pyi
117+
.. exampleinclude:: ../../../task-sdk/src/airflow/sdk/definitions/decorators/__init__.pyi
118118
:language: python
119119
:start-after: [START mixin_for_typing]
120120
:end-before: [END mixin_for_typing]

airflow-core/docs/howto/dynamic-dag-generation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ and Airflow will automatically register them.
127127
.. code-block:: python
128128
129129
from datetime import datetime
130-
from airflow.decorators import dag, task
130+
from airflow.sdk import dag, task
131131
132132
configs = {
133133
"config1": {"message": "first DAG will receive this message"},

0 commit comments

Comments
 (0)