Coverage for /pythoncovmergedfiles/medio/medio/src/airflow/airflow/__init__.py: 63%

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

43 statements  

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. 

18from __future__ import annotations 

19 

20__version__ = "2.10.0.dev0" 

21 

22import os 

23import sys 

24import warnings 

25 

26if os.environ.get("_AIRFLOW_PATCH_GEVENT"): 

27 # If you are using gevents and start airflow webserver, you might want to run gevent monkeypatching 

28 # as one of the first thing when Airflow is started. This allows gevent to patch networking and other 

29 # system libraries to make them gevent-compatible before anything else patches them (for example boto) 

30 from gevent.monkey import patch_all 

31 

32 patch_all() 

33 

34if sys.platform == "win32": 

35 warnings.warn( 

36 "Airflow currently can be run on POSIX-compliant Operating Systems. For development, " 

37 "it is regularly tested on fairly modern Linux Distros and recent versions of macOS. " 

38 "On Windows you can run it via WSL2 (Windows Subsystem for Linux 2) or via Linux Containers. " 

39 "The work to add Windows support is tracked via https://github.com/apache/airflow/issues/10388, " 

40 "but it is not a high priority.", 

41 category=RuntimeWarning, 

42 stacklevel=1, 

43 ) 

44 

45# The configuration module initializes and validates the conf object as a side effect the first 

46# time it is imported. If it is not imported before importing the settings module, the conf 

47# object will then be initted/validated as a side effect of it being imported in settings, 

48# however this can cause issues since those modules are very tightly coupled and can 

49# very easily cause import cycles in the conf init/validate code (since downstream code from 

50# those functions likely import settings). 

51# configuration is therefore initted early here, simply by importing it. 

52from airflow import configuration, settings 

53 

54__all__ = [ 

55 "__version__", 

56 "DAG", 

57 "Dataset", 

58 "XComArg", 

59] 

60 

61# Make `airflow` a namespace package, supporting installing 

62# airflow.providers.* in different locations (i.e. one in site, and one in user 

63# lib.) 

64__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore 

65 

66 

67# Perform side-effects unless someone has explicitly opted out before import 

68# WARNING: DO NOT USE THIS UNLESS YOU REALLY KNOW WHAT YOU'RE DOING. 

69# This environment variable prevents proper initialization, and things like 

70# configs, logging, the ORM, etc. will be broken. It is only useful if you only 

71# access certain trivial constants and free functions (e.g. `__version__`). 

72if not os.environ.get("_AIRFLOW__AS_LIBRARY", None): 

73 settings.initialize() 

74 

75# Things to lazy import in form {local_name: ('target_module', 'target_name', 'deprecated')} 

76__lazy_imports: dict[str, tuple[str, str, bool]] = { 

77 "DAG": (".models.dag", "DAG", False), 

78 "Dataset": (".datasets", "Dataset", False), 

79 "XComArg": (".models.xcom_arg", "XComArg", False), 

80 "version": (".version", "", False), 

81 # Deprecated lazy imports 

82 "AirflowException": (".exceptions", "AirflowException", True), 

83} 

84 

85 

86def __getattr__(name: str): 

87 # PEP-562: Lazy loaded attributes on python modules 

88 module_path, attr_name, deprecated = __lazy_imports.get(name, ("", "", False)) 

89 if not module_path: 

90 if name.startswith("PY3") and (py_minor := name[3:]) in ("6", "7", "8", "9", "10", "11", "12"): 

91 warnings.warn( 

92 f"Python version constraint {name!r} is deprecated and will be removed in the future. " 

93 f"Please get version info from the 'sys.version_info'.", 

94 DeprecationWarning, 

95 stacklevel=2, 

96 ) 

97 return sys.version_info >= (3, int(py_minor)) 

98 

99 raise AttributeError(f"module {__name__!r} has no attribute {name!r}") 

100 elif deprecated: 

101 warnings.warn( 

102 f"Import {name!r} directly from the airflow module is deprecated and " 

103 f"will be removed in the future. Please import it from 'airflow{module_path}.{attr_name}'.", 

104 DeprecationWarning, 

105 stacklevel=2, 

106 ) 

107 

108 import importlib 

109 

110 mod = importlib.import_module(module_path, __name__) 

111 if attr_name: 

112 val = getattr(mod, attr_name) 

113 else: 

114 val = mod 

115 

116 # Store for next time 

117 globals()[name] = val 

118 return val 

119 

120 

121if not settings.LAZY_LOAD_PROVIDERS: 

122 from airflow import providers_manager 

123 

124 manager = providers_manager.ProvidersManager() 

125 manager.initialize_providers_list() 

126 manager.initialize_providers_hooks() 

127 manager.initialize_providers_extra_links() 

128if not settings.LAZY_LOAD_PLUGINS: 

129 from airflow import plugins_manager 

130 

131 plugins_manager.ensure_plugins_loaded() 

132 

133 

134# This is never executed, but tricks static analyzers (PyDev, PyCharm,) 

135# into knowing the types of these symbols, and what 

136# they contain. 

137STATICA_HACK = True 

138globals()["kcah_acitats"[::-1].upper()] = False 

139if STATICA_HACK: # pragma: no cover 

140 from airflow.models.dag import DAG 

141 from airflow.models.dataset import Dataset 

142 from airflow.models.xcom_arg import XComArg