Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix boolean evaluation for omegaconf #31

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions kapitan/inventory/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,30 +167,34 @@ def parent_path(_parent_: Node):
return _parent_._get_flag("path")


def evaluate_bool(condition: str) -> bool:
return str(condition).lower() in ["false", "", "0", "none"]


def condition_if(condition: str, config: dict):
if bool(condition):
if evaluate_bool(condition):
return config
else:
return {}


def condition_if_else(condition: str, config_if: dict, config_else: dict):
if bool(condition):
if evaluate_bool(condition):
return config_if
else:
return config_else


def condition_not(condition: str):
return not bool(condition)
return not evaluate_bool(condition)


def condition_and(*conditions: str):
return all(conditions)
return all(map(evaluate_bool, conditions))


def condition_or(*conditions: str):
return any(conditions)
return any(map(evaluate_bool, conditions))


def condition_equal(*configs):
Expand Down
Loading