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

42 statements  

« prev     ^ index     » next       coverage.py v7.0.1, created at 2022-12-25 06:11 +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# flake8: noqa: F401 

30 

31import os 

32import sys 

33from typing import Callable 

34 

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

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

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

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

39 from gevent.monkey import patch_all 

40 

41 patch_all() 

42 

43from airflow import settings 

44 

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

46 

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

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

49# lib.) 

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

51 

52 

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

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

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

56 settings.initialize() 

57 

58login: Callable | None = None 

59 

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

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

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

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

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

65 

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

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

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

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

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

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

72 "version": (".version", ""), 

73 "__version__": (".version", "version"), 

74} 

75 

76 

77def __getattr__(name: str): 

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

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

80 if not module_path: 

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

82 

83 import importlib 

84 

85 mod = importlib.import_module(module_path, __name__) 

86 if attr_name: 

87 val = getattr(mod, attr_name) 

88 else: 

89 val = mod 

90 

91 # Store for next time 

92 globals()[name] = val 

93 return val 

94 

95 

96if not settings.LAZY_LOAD_PLUGINS: 

97 from airflow import plugins_manager 

98 

99 plugins_manager.ensure_plugins_loaded() 

100 

101if not settings.LAZY_LOAD_PROVIDERS: 

102 from airflow import providers_manager 

103 

104 manager = providers_manager.ProvidersManager() 

105 manager.initialize_providers_list() 

106 manager.initialize_providers_hooks() 

107 manager.initialize_providers_extra_links() 

108 

109 

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

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

112# they contain. 

113STATICA_HACK = True 

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

115if STATICA_HACK: # pragma: no cover 

116 from airflow.models.dag import DAG 

117 from airflow.models.xcom_arg import XComArg 

118 from airflow.exceptions import AirflowException