Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/airflow/__init__.py: 24%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
19# We do not use "from __future__ import annotations" here because it is not supported
20# by Pycharm when we want to make sure all imports in airflow work from namespace packages
21# Adding it automatically is excluded in pyproject.toml via I002 ruff rule exclusion
23# Make `airflow` a namespace package, supporting installing
24# airflow.providers.* in different locations (i.e. one in site, and one in user
25# lib.) This is required by some IDEs to resolve the import paths.
26__path__ = __import__("pkgutil").extend_path(__path__, __name__)
28__version__ = "3.4.0"
31import os
32import sys
33import warnings
34from typing import TYPE_CHECKING
36from airflow.utils.deprecation_tools import DeprecatedImportWarning
38if os.environ.get("_AIRFLOW_PATCH_GEVENT"):
39 # If you are using gevents and start airflow webserver, you might want to run gevent monkeypatching
40 # as one of the first thing when Airflow is started. This allows gevent to patch networking and other
41 # system libraries to make them gevent-compatible before anything else patches them (for example boto)
42 from gevent.monkey import patch_all
44 patch_all()
46if sys.platform == "win32":
47 warnings.warn(
48 "Airflow currently can be run on POSIX-compliant Operating Systems. For development, "
49 "it is regularly tested on fairly modern Linux Distros and recent versions of macOS. "
50 "On Windows you can run it via WSL2 (Windows Subsystem for Linux 2) or via Linux Containers. "
51 "The work to add Windows support is tracked via https://github.com/apache/airflow/issues/10388, "
52 "but it is not a high priority.",
53 category=RuntimeWarning,
54 stacklevel=1,
55 )
57# The configuration module initializes and validates the conf object as a side effect the first
58# time it is imported. If it is not imported before importing the settings module, the conf
59# object will then be initted/validated as a side effect of it being imported in settings,
60# however this can cause issues since those modules are very tightly coupled and can
61# very easily cause import cycles in the conf init/validate code (since downstream code from
62# those functions likely import settings).
63# configuration is therefore initted early here, simply by importing it.
64from airflow import configuration, settings
66__all__ = [
67 "__version__",
68 "DAG",
69 "Asset",
70 "XComArg",
71]
73# Perform side-effects unless someone has explicitly opted out before import
74# WARNING: DO NOT USE THIS UNLESS YOU REALLY KNOW WHAT YOU'RE DOING.
75# This environment variable prevents proper initialization, and things like
76# configs, logging, the ORM, etc. will be broken. It is only useful if you only
77# access certain trivial constants and free functions (e.g. `__version__`).
78if not os.environ.get("_AIRFLOW__AS_LIBRARY", None):
79 settings.initialize()
81# Things to lazy import in form {local_name: ('target_module', 'target_name', 'deprecated')}
82__lazy_imports: dict[str, tuple[str, str, bool]] = {
83 "DAG": (".sdk", "DAG", False),
84 "Asset": (".sdk", "Asset", False),
85 "XComArg": (".sdk", "XComArg", False),
86 "version": (".version", "", False),
87 # Deprecated lazy imports
88 "AirflowException": (".exceptions", "AirflowException", True),
89 "Trace": (".observability.trace", "Trace", True),
90 "metrics": (".observability.metrics", "", True),
91 "traces": ("._shared.observability.traces", "", True),
92}
93if TYPE_CHECKING:
94 # These objects are imported by PEP-562, however, static analyzers and IDE's
95 # have no idea about typing of these objects.
96 # Add it under TYPE_CHECKING block should help with it.
97 from airflow.sdk import DAG, Asset, XComArg
100def __getattr__(name: str):
101 # PEP-562: Lazy loaded attributes on python modules
102 module_path, attr_name, deprecated = __lazy_imports.get(name, ("", "", False))
103 if not module_path:
104 raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
105 if deprecated:
106 warnings.warn(
107 f"Import {name!r} directly from the airflow module is deprecated and "
108 f"will be removed in the future. Please import it from 'airflow{module_path}.{attr_name}'.",
109 DeprecatedImportWarning,
110 stacklevel=2,
111 )
113 import importlib
115 mod = importlib.import_module(module_path, __name__)
116 if attr_name:
117 val = getattr(mod, attr_name)
118 else:
119 val = mod
121 # Store for next time
122 globals()[name] = val
123 return val
126if not settings.LAZY_LOAD_PROVIDERS:
127 from airflow.providers_manager import ProvidersManager
129 manager = ProvidersManager()
130 manager.initialize_providers_list()
131 manager.initialize_providers_hooks()
132 manager.initialize_providers_extra_links()
133if not settings.LAZY_LOAD_PLUGINS:
134 from airflow import plugins_manager
136 plugins_manager.ensure_plugins_loaded()