Skip to content

Commit

Permalink
reduce complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
ms32035 committed Mar 11, 2024
1 parent 2e6235b commit c76529d
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions cosmos/operators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,28 @@ def add_global_flags(self) -> list[str]:

dbt_name = f"--{global_flag.replace('_', '-')}"
global_flag_value = self.__getattribute__(global_flag)
if global_flag_value is not None:
if isinstance(global_flag_value, dict):
yaml_string = yaml.dump(global_flag_value)
flags.extend([dbt_name, yaml_string])
elif isinstance(global_flag_value, list) and global_flag_value:
flags.extend([dbt_name, " ".join(global_flag_value)])
elif isinstance(global_flag_value, list):
continue
else:
flags.extend([dbt_name, str(global_flag_value)])
flags.extend(self._process_global_flag(dbt_name, global_flag_value))

for global_boolean_flag in self.global_boolean_flags:
if self.__getattribute__(global_boolean_flag):
flags.append(f"--{global_boolean_flag.replace('_', '-')}")
return flags

@staticmethod
def _process_global_flag(flag_name: str, flag_value: Any) -> list[str]:
"""Helper method to process global flags and reduce complexity."""
if flag_value is None:
return []
elif isinstance(flag_value, dict):
yaml_string = yaml.dump(flag_value)
return [flag_name, yaml_string]
elif isinstance(flag_value, list) and flag_value:
return [flag_name, " ".join(flag_value)]
elif isinstance(flag_value, list):
return []

Check warning on line 215 in cosmos/operators/base.py

View check run for this annotation

Codecov / codecov/patch

cosmos/operators/base.py#L215

Added line #L215 was not covered by tests
else:
return [flag_name, str(flag_value)]

def add_cmd_flags(self) -> list[str]:
"""Allows subclasses to override to add flags for their dbt command"""
return []
Expand Down

0 comments on commit c76529d

Please sign in to comment.