Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/airflow/executors/executor_utils.py: 36%

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

25 statements  

1# Licensed to the Apache Software Foundation (ASF) under one 

2# or more contributor license agreements. See the NOTICE file 

3# distributed with this work for additional information 

4# regarding copyright ownership. The ASF licenses this file 

5# to you under the Apache License, Version 2.0 (the 

6# "License"); you may not use this file except in compliance 

7# with the License. You may obtain a copy of the License at 

8# 

9# http://www.apache.org/licenses/LICENSE-2.0 

10# 

11# Unless required by applicable law or agreed to in writing, 

12# software distributed under the License is distributed on an 

13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 

14# KIND, either express or implied. See the License for the 

15# specific language governing permissions and limitations 

16# under the License. 

17from __future__ import annotations 

18 

19from airflow.executors.executor_constants import CORE_EXECUTOR_NAMES, ConnectorSource 

20from airflow.utils.log.logging_mixin import LoggingMixin 

21 

22 

23class ExecutorName(LoggingMixin): 

24 """Representation of an executor config/name.""" 

25 

26 def __init__(self, module_path, alias=None): 

27 self.module_path = module_path 

28 self.alias = alias 

29 self.set_connector_source() 

30 

31 def set_connector_source(self): 

32 if self.alias in CORE_EXECUTOR_NAMES: 

33 self.connector_source = ConnectorSource.CORE 

34 # If there is only one dot, then this is likely a plugin. This is the best we can do 

35 # to determine. 

36 elif self.module_path.count(".") == 1: 

37 self.log.debug( 

38 "The executor name looks like the plugin path (executor_name=%s) due to having " 

39 "just two period delimited parts. Treating executor as a plugin", 

40 self.module_path, 

41 ) 

42 self.connector_source = ConnectorSource.PLUGIN 

43 # Executor must be a module 

44 else: 

45 self.connector_source = ConnectorSource.CUSTOM_PATH 

46 

47 def __repr__(self): 

48 """Implement repr.""" 

49 if self.alias in CORE_EXECUTOR_NAMES: 

50 return self.alias 

51 return f"{self.alias}:{self.module_path}" if self.alias else f"{self.module_path}" 

52 

53 def __eq__(self, other): 

54 """Implement eq.""" 

55 if ( 

56 self.alias == other.alias 

57 and self.module_path == other.module_path 

58 and self.connector_source == other.connector_source 

59 ): 

60 return True 

61 else: 

62 return False 

63 

64 def __hash__(self): 

65 """Implement hash.""" 

66 return hash(self.__repr__())