Skip to content

Commit 91a64db

Browse files
authored
Format all files (without excepions) by black (#12091)
1 parent fd3db77 commit 91a64db

File tree

5 files changed

+160
-155
lines changed

5 files changed

+160
-155
lines changed

β€Ž.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ repos:
159159
rev: 20.8b1
160160
hooks:
161161
- id: black
162-
exclude: .*kubernetes_pod\.py|.*google/common/hooks/base_google\.py$|^airflow/configuration.py$
163162
args: [--config=./pyproject.toml]
164163
- repo: https://github.com/pre-commit/pre-commit-hooks
165164
rev: v3.3.0

β€Žairflow/configuration.py

Lines changed: 73 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@
4545

4646
# show Airflow's deprecation warnings
4747
if not sys.warnoptions:
48-
warnings.filterwarnings(
49-
action='default', category=DeprecationWarning, module='airflow')
50-
warnings.filterwarnings(
51-
action='default', category=PendingDeprecationWarning, module='airflow')
48+
warnings.filterwarnings(action='default', category=DeprecationWarning, module='airflow')
49+
warnings.filterwarnings(action='default', category=PendingDeprecationWarning, module='airflow')
5250

5351

5452
def expand_env_var(env_var):
@@ -70,17 +68,14 @@ def expand_env_var(env_var):
7068
def run_command(command):
7169
"""Runs command and returns stdout"""
7270
process = subprocess.Popen(
73-
shlex.split(command),
74-
stdout=subprocess.PIPE,
75-
stderr=subprocess.PIPE,
76-
close_fds=True)
77-
output, stderr = [stream.decode(sys.getdefaultencoding(), 'ignore')
78-
for stream in process.communicate()]
71+
shlex.split(command), stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True
72+
)
73+
output, stderr = [stream.decode(sys.getdefaultencoding(), 'ignore') for stream in process.communicate()]
7974

8075
if process.returncode != 0:
8176
raise AirflowConfigException(
82-
"Cannot execute {}. Error code is: {}. Output: {}, Stderr: {}"
83-
.format(command, process.returncode, output, stderr)
77+
f"Cannot execute {command}. Error code is: {process.returncode}. "
78+
f"Output: {output}, Stderr: {stderr}"
8479
)
8580

8681
return output
@@ -183,9 +178,9 @@ class AirflowConfigParser(ConfigParser): # pylint: disable=too-many-ancestors
183178
'email_backend': (
184179
re.compile(r'^airflow\.contrib\.utils\.sendgrid\.send_email$'),
185180
r'airflow.providers.sendgrid.utils.emailer.send_email',
186-
'2.0'
181+
'2.0',
187182
),
188-
}
183+
},
189184
}
190185

191186
# This method transforms option names on every read, get, or set operation.
@@ -213,14 +208,14 @@ def _validate(self):
213208
current_value = self.get(section, name, fallback=None)
214209
if self._using_old_value(old, current_value):
215210
new_value = re.sub(old, new, current_value)
216-
self._update_env_var(
217-
section=section, name=name, new_value=new_value)
211+
self._update_env_var(section=section, name=name, new_value=new_value)
218212
self._create_future_warning(
219213
name=name,
220214
section=section,
221215
current_value=current_value,
222216
new_value=new_value,
223-
version=version)
217+
version=version,
218+
)
224219

225220
self.is_validated = True
226221

@@ -229,21 +224,27 @@ def _validate_config_dependencies(self):
229224
Validate that config values aren't invalid given other config values
230225
or system-level limitations and requirements.
231226
"""
232-
if (
233-
self.get("core", "executor") not in ('DebugExecutor', 'SequentialExecutor') and
234-
"sqlite" in self.get('core', 'sql_alchemy_conn')):
227+
is_executor_without_sqlite_support = self.get("core", "executor") not in (
228+
'DebugExecutor',
229+
'SequentialExecutor',
230+
)
231+
is_sqlite = "sqlite" in self.get('core', 'sql_alchemy_conn')
232+
if is_executor_without_sqlite_support and is_sqlite:
235233
raise AirflowConfigException(
236-
"error: cannot use sqlite with the {}".format(
237-
self.get('core', 'executor')))
234+
"error: cannot use sqlite with the {}".format(self.get('core', 'executor'))
235+
)
238236

239237
if self.has_option('core', 'mp_start_method'):
240238
mp_start_method = self.get('core', 'mp_start_method')
241239
start_method_options = multiprocessing.get_all_start_methods()
242240

243241
if mp_start_method not in start_method_options:
244242
raise AirflowConfigException(
245-
"mp_start_method should not be " + mp_start_method +
246-
". Possible values are " + ", ".join(start_method_options))
243+
"mp_start_method should not be "
244+
+ mp_start_method
245+
+ ". Possible values are "
246+
+ ", ".join(start_method_options)
247+
)
247248

248249
def _using_old_value(self, old, current_value): # noqa
249250
return old.search(current_value) is not None
@@ -264,7 +265,7 @@ def _create_future_warning(name, section, current_value, new_value, version):
264265
'Airflow {version}.'.format(
265266
name=name, section=section, current_value=current_value, new_value=new_value, version=version
266267
),
267-
FutureWarning
268+
FutureWarning,
268269
)
269270

270271
@staticmethod
@@ -336,17 +337,12 @@ def get(self, section, key, **kwargs):
336337
def _get_option_from_default_config(self, section, key, **kwargs):
337338
# ...then the default config
338339
if self.airflow_defaults.has_option(section, key) or 'fallback' in kwargs:
339-
return expand_env_var(
340-
self.airflow_defaults.get(section, key, **kwargs))
340+
return expand_env_var(self.airflow_defaults.get(section, key, **kwargs))
341341

342342
else:
343-
log.warning(
344-
"section/key [%s/%s] not found in config", section, key
345-
)
343+
log.warning("section/key [%s/%s] not found in config", section, key)
346344

347-
raise AirflowConfigException(
348-
"section/key [{section}/{key}] not found "
349-
"in config".format(section=section, key=key))
345+
raise AirflowConfigException(f"section/key [{section}/{key}] not found in config")
350346

351347
def _get_option_from_secrets(self, deprecated_key, deprecated_section, key, section):
352348
# ...then from secret backends
@@ -377,16 +373,11 @@ def _get_option_from_config_file(self, deprecated_key, deprecated_section, key,
377373
if super().has_option(section, key):
378374
# Use the parent's methods to get the actual config here to be able to
379375
# separate the config from default config.
380-
return expand_env_var(
381-
super().get(section, key, **kwargs))
376+
return expand_env_var(super().get(section, key, **kwargs))
382377
if deprecated_section:
383378
if super().has_option(deprecated_section, deprecated_key):
384379
self._warn_deprecate(section, key, deprecated_section, deprecated_key)
385-
return expand_env_var(super().get(
386-
deprecated_section,
387-
deprecated_key,
388-
**kwargs
389-
))
380+
return expand_env_var(super().get(deprecated_section, deprecated_key, **kwargs))
390381
return None
391382

392383
def _get_environment_variables(self, deprecated_key, deprecated_section, key, section):
@@ -543,8 +534,13 @@ def write(self, fp, space_around_delimiters=True):
543534
self._write_section(fp, section, self.getsection(section).items(), delimiter)
544535

545536
def as_dict(
546-
self, display_source=False, display_sensitive=False, raw=False,
547-
include_env=True, include_cmds=True, include_secret=True
537+
self,
538+
display_source=False,
539+
display_sensitive=False,
540+
raw=False,
541+
include_env=True,
542+
include_cmds=True,
543+
include_secret=True,
548544
) -> Dict[str, Dict[str, str]]:
549545
"""
550546
Returns the current configuration as an OrderedDict of OrderedDicts.
@@ -624,8 +620,9 @@ def _include_commands(self, config_sources, display_sensitive, display_source, r
624620
del config_sources[section][key + '_cmd']
625621

626622
def _include_envs(self, config_sources, display_sensitive, display_source, raw):
627-
for env_var in [os_environment
628-
for os_environment in os.environ if os_environment.startswith('AIRFLOW__')]:
623+
for env_var in [
624+
os_environment for os_environment in os.environ if os_environment.startswith('AIRFLOW__')
625+
]:
629626
try:
630627
_, section, key = env_var.split('__', 2)
631628
opt = self._get_env_var_option(section, key)
@@ -651,13 +648,14 @@ def _include_envs(self, config_sources, display_sensitive, display_source, raw):
651648
def _replace_config_with_display_sources(config_sources, configs, display_source, raw):
652649
for (source_name, config) in configs:
653650
for section in config.sections():
654-
AirflowConfigParser.\
655-
_replace_section_config_with_display_sources(
656-
config, config_sources, display_source, raw, section, source_name)
651+
AirflowConfigParser._replace_section_config_with_display_sources(
652+
config, config_sources, display_source, raw, section, source_name
653+
)
657654

658655
@staticmethod
659-
def _replace_section_config_with_display_sources(config, config_sources, display_source, raw, section,
660-
source_name):
656+
def _replace_section_config_with_display_sources(
657+
config, config_sources, display_source, raw, section, source_name
658+
):
661659
sect = config_sources.setdefault(section, OrderedDict())
662660
for (k, val) in config.items(section=section, raw=raw):
663661
if display_source:
@@ -730,19 +728,17 @@ def get_airflow_config(airflow_home):
730728
# Set up dags folder for unit tests
731729
# this directory won't exist if users install via pip
732730
_TEST_DAGS_FOLDER = os.path.join(
733-
os.path.dirname(os.path.dirname(os.path.realpath(__file__))),
734-
'tests',
735-
'dags')
731+
os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'tests', 'dags'
732+
)
736733
if os.path.exists(_TEST_DAGS_FOLDER):
737734
TEST_DAGS_FOLDER = _TEST_DAGS_FOLDER
738735
else:
739736
TEST_DAGS_FOLDER = os.path.join(AIRFLOW_HOME, 'dags')
740737

741738
# Set up plugins folder for unit tests
742739
_TEST_PLUGINS_FOLDER = os.path.join(
743-
os.path.dirname(os.path.dirname(os.path.realpath(__file__))),
744-
'tests',
745-
'plugins')
740+
os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'tests', 'plugins'
741+
)
746742
if os.path.exists(_TEST_PLUGINS_FOLDER):
747743
TEST_PLUGINS_FOLDER = _TEST_PLUGINS_FOLDER
748744
else:
@@ -777,20 +773,14 @@ def get_airflow_test_config(airflow_home):
777773

778774
SECRET_KEY = b64encode(os.urandom(16)).decode('utf-8')
779775

780-
TEMPLATE_START = (
781-
'# ----------------------- TEMPLATE BEGINS HERE -----------------------')
776+
TEMPLATE_START = '# ----------------------- TEMPLATE BEGINS HERE -----------------------'
782777
if not os.path.isfile(TEST_CONFIG_FILE):
783-
log.info(
784-
'Creating new Airflow config file for unit tests in: %s', TEST_CONFIG_FILE
785-
)
778+
log.info('Creating new Airflow config file for unit tests in: %s', TEST_CONFIG_FILE)
786779
with open(TEST_CONFIG_FILE, 'w') as file:
787780
cfg = parameterized_config(TEST_CONFIG)
788781
file.write(cfg.split(TEMPLATE_START)[-1].strip())
789782
if not os.path.isfile(AIRFLOW_CONFIG):
790-
log.info(
791-
'Creating new Airflow config file in: %s',
792-
AIRFLOW_CONFIG
793-
)
783+
log.info('Creating new Airflow config file in: %s', AIRFLOW_CONFIG)
794784
with open(AIRFLOW_CONFIG, 'w') as file:
795785
cfg = parameterized_config(DEFAULT_CONFIG)
796786
cfg = cfg.split(TEMPLATE_START)[-1].strip()
@@ -835,110 +825,110 @@ def get_airflow_test_config(airflow_home):
835825

836826

837827
# Historical convenience functions to access config entries
838-
def load_test_config(): # noqa: D103
828+
def load_test_config(): # noqa: D103
839829
"""Historical load_test_config"""
840830
warnings.warn(
841831
"Accessing configuration method 'load_test_config' directly from the configuration module is "
842832
"deprecated. Please access the configuration from the 'configuration.conf' object via "
843833
"'conf.load_test_config'",
844834
DeprecationWarning,
845-
stacklevel=2
835+
stacklevel=2,
846836
)
847837
conf.load_test_config()
848838

849839

850-
def get(*args, **kwargs): # noqa: D103
840+
def get(*args, **kwargs): # noqa: D103
851841
"""Historical get"""
852842
warnings.warn(
853843
"Accessing configuration method 'get' directly from the configuration module is "
854844
"deprecated. Please access the configuration from the 'configuration.conf' object via "
855845
"'conf.get'",
856846
DeprecationWarning,
857-
stacklevel=2
847+
stacklevel=2,
858848
)
859849
return conf.get(*args, **kwargs)
860850

861851

862-
def getboolean(*args, **kwargs): # noqa: D103
852+
def getboolean(*args, **kwargs): # noqa: D103
863853
"""Historical getboolean"""
864854
warnings.warn(
865855
"Accessing configuration method 'getboolean' directly from the configuration module is "
866856
"deprecated. Please access the configuration from the 'configuration.conf' object via "
867857
"'conf.getboolean'",
868858
DeprecationWarning,
869-
stacklevel=2
859+
stacklevel=2,
870860
)
871861
return conf.getboolean(*args, **kwargs)
872862

873863

874-
def getfloat(*args, **kwargs): # noqa: D103
864+
def getfloat(*args, **kwargs): # noqa: D103
875865
"""Historical getfloat"""
876866
warnings.warn(
877867
"Accessing configuration method 'getfloat' directly from the configuration module is "
878868
"deprecated. Please access the configuration from the 'configuration.conf' object via "
879869
"'conf.getfloat'",
880870
DeprecationWarning,
881-
stacklevel=2
871+
stacklevel=2,
882872
)
883873
return conf.getfloat(*args, **kwargs)
884874

885875

886-
def getint(*args, **kwargs): # noqa: D103
876+
def getint(*args, **kwargs): # noqa: D103
887877
"""Historical getint"""
888878
warnings.warn(
889879
"Accessing configuration method 'getint' directly from the configuration module is "
890880
"deprecated. Please access the configuration from the 'configuration.conf' object via "
891881
"'conf.getint'",
892882
DeprecationWarning,
893-
stacklevel=2
883+
stacklevel=2,
894884
)
895885
return conf.getint(*args, **kwargs)
896886

897887

898-
def getsection(*args, **kwargs): # noqa: D103
888+
def getsection(*args, **kwargs): # noqa: D103
899889
"""Historical getsection"""
900890
warnings.warn(
901891
"Accessing configuration method 'getsection' directly from the configuration module is "
902892
"deprecated. Please access the configuration from the 'configuration.conf' object via "
903893
"'conf.getsection'",
904894
DeprecationWarning,
905-
stacklevel=2
895+
stacklevel=2,
906896
)
907897
return conf.getint(*args, **kwargs)
908898

909899

910-
def has_option(*args, **kwargs): # noqa: D103
900+
def has_option(*args, **kwargs): # noqa: D103
911901
"""Historical has_option"""
912902
warnings.warn(
913903
"Accessing configuration method 'has_option' directly from the configuration module is "
914904
"deprecated. Please access the configuration from the 'configuration.conf' object via "
915905
"'conf.has_option'",
916906
DeprecationWarning,
917-
stacklevel=2
907+
stacklevel=2,
918908
)
919909
return conf.has_option(*args, **kwargs)
920910

921911

922-
def remove_option(*args, **kwargs): # noqa: D103
912+
def remove_option(*args, **kwargs): # noqa: D103
923913
"""Historical remove_option"""
924914
warnings.warn(
925915
"Accessing configuration method 'remove_option' directly from the configuration module is "
926916
"deprecated. Please access the configuration from the 'configuration.conf' object via "
927917
"'conf.remove_option'",
928918
DeprecationWarning,
929-
stacklevel=2
919+
stacklevel=2,
930920
)
931921
return conf.remove_option(*args, **kwargs)
932922

933923

934-
def as_dict(*args, **kwargs): # noqa: D103
924+
def as_dict(*args, **kwargs): # noqa: D103
935925
"""Historical as_dict"""
936926
warnings.warn(
937927
"Accessing configuration method 'as_dict' directly from the configuration module is "
938928
"deprecated. Please access the configuration from the 'configuration.conf' object via "
939929
"'conf.as_dict'",
940930
DeprecationWarning,
941-
stacklevel=2
931+
stacklevel=2,
942932
)
943933
return conf.as_dict(*args, **kwargs)
944934

@@ -950,7 +940,7 @@ def set(*args, **kwargs): # noqa pylint: disable=redefined-builtin
950940
"deprecated. Please access the configuration from the 'configuration.conf' object via "
951941
"'conf.set'",
952942
DeprecationWarning,
953-
stacklevel=2
943+
stacklevel=2,
954944
)
955945
return conf.set(*args, **kwargs)
956946

0 commit comments

Comments
 (0)