Source code for airflow.decorators

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations

from typing import Any, Callable

from airflow.decorators.base import TaskDecorator
from airflow.decorators.branch_python import branch_task
from airflow.decorators.external_python import external_python_task
from airflow.decorators.python import python_task
from airflow.decorators.python_virtualenv import virtualenv_task
from airflow.decorators.sensor import sensor_task
from airflow.decorators.setup_teardown import setup_task, teardown_task
from airflow.decorators.short_circuit import short_circuit_task
from airflow.decorators.task_group import task_group
from airflow.models.dag import dag
from airflow.providers_manager import ProvidersManager

# Please keep this in sync with the .pyi's __all__.
__all__ = [

[docs]class TaskDecoratorCollection: """Implementation to provide the ``@task`` syntax."""
[docs] python = staticmethod(python_task)
[docs] virtualenv = staticmethod(virtualenv_task)
[docs] external_python = staticmethod(external_python_task)
[docs] branch = staticmethod(branch_task)
[docs] short_circuit = staticmethod(short_circuit_task)
[docs] sensor = staticmethod(sensor_task)
[docs] __call__: Any = python # Alias '@task' to '@task.python'.
[docs] def __getattr__(self, name: str) -> TaskDecorator: """Dynamically get provider-registered task decorators, e.g. ``@task.docker``.""" if name.startswith("__"): raise AttributeError(f"{type(self).__name__} has no attribute {name!r}") decorators = ProvidersManager().taskflow_decorators if name not in decorators: raise AttributeError(f"task decorator {name!r} not found") return decorators[name]
[docs]task = TaskDecoratorCollection()
[docs]setup: Callable = setup_task
[docs]teardown: Callable = teardown_task

Was this entry helpful?