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

45 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:35 +0000

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. 

18""" 

19Init setup. 

20 

21Authentication is implemented using flask_login and different environments can 

22implement their own login mechanisms by providing an `airflow_login` module 

23in their PYTHONPATH. airflow_login should be based off the `airflow.www.login` 

24 

25isort:skip_file 

26""" 

27from __future__ import annotations 

28 

29__version__ = "2.7.0.dev0" 

30 

31# flake8: noqa: F401 

32 

33import os 

34import sys 

35from typing import Callable 

36 

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

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

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

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

41 from gevent.monkey import patch_all 

42 

43 patch_all() 

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 

53from airflow import settings 

54 

55__all__ = ["__version__", "login", "DAG", "PY36", "PY37", "PY38", "PY39", "PY310", "XComArg"] 

56 

57# Make `airflow` an namespace package, supporting installing 

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

59# lib.) 

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

61 

62 

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

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

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

66 settings.initialize() 

67 

68login: Callable | None = None 

69 

70PY36 = sys.version_info >= (3, 6) 

71PY37 = sys.version_info >= (3, 7) 

72PY38 = sys.version_info >= (3, 8) 

73PY39 = sys.version_info >= (3, 9) 

74PY310 = sys.version_info >= (3, 10) 

75PY311 = sys.version_info >= (3, 11) 

76 

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

78__lazy_imports: dict[str, tuple[str, str]] = { 

79 "DAG": (".models.dag", "DAG"), 

80 "Dataset": (".datasets", "Dataset"), 

81 "XComArg": (".models.xcom_arg", "XComArg"), 

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

83 "version": (".version", ""), 

84} 

85 

86 

87def __getattr__(name: str): 

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

89 module_path, attr_name = __lazy_imports.get(name, ("", "")) 

90 if not module_path: 

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

92 

93 import importlib 

94 

95 mod = importlib.import_module(module_path, __name__) 

96 if attr_name: 

97 val = getattr(mod, attr_name) 

98 else: 

99 val = mod 

100 

101 # Store for next time 

102 globals()[name] = val 

103 return val 

104 

105 

106if not settings.LAZY_LOAD_PLUGINS: 

107 from airflow import plugins_manager 

108 

109 plugins_manager.ensure_plugins_loaded() 

110 

111if not settings.LAZY_LOAD_PROVIDERS: 

112 from airflow import providers_manager 

113 

114 manager = providers_manager.ProvidersManager() 

115 manager.initialize_providers_list() 

116 manager.initialize_providers_hooks() 

117 manager.initialize_providers_extra_links() 

118 

119 

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

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

122# they contain. 

123STATICA_HACK = True 

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

125if STATICA_HACK: # pragma: no cover 

126 from airflow.models.dag import DAG 

127 from airflow.models.xcom_arg import XComArg 

128 from airflow.exceptions import AirflowException 

129 from airflow.models.dataset import Dataset