diff --git a/.bluish/bluish.yaml b/.bluish/bluish.yaml index 3ccdf79..888387e 100644 --- a/.bluish/bluish.yaml +++ b/.bluish/bluish.yaml @@ -1,6 +1,6 @@ var: - project_version: "0.7.2" + project_version: "0.7.3" python_version: "3.12" jobs: diff --git a/src/bluish/contexts/__init__.py b/src/bluish/contexts/__init__.py index 8798b31..686ea32 100644 --- a/src/bluish/contexts/__init__.py +++ b/src/bluish/contexts/__init__.py @@ -197,10 +197,14 @@ def prepare_value(value: Any) -> Any: member_result = _try_get_value(ctx, f".{name}", raw=raw) var_result = _try_get_value(ctx, f"var.{name}", raw=raw) - if var_result and member_result: + if var_result is not None and member_result is not None: raise ValueError(f"Ambiguous value reference: {name}") + elif var_result is not None: + return var_result + elif member_result is not None: + return member_result else: - return var_result or member_result or None + return None root, varname = name.split(".", maxsplit=1) @@ -354,7 +358,7 @@ def can_dispatch(context: InputOutputNode) -> bool: return context.attrs._if elif not isinstance(context.attrs._if, str): raise ValueError("Condition must be a bool or a string") - + print(context.expand_expr(context.attrs._if)) return bool(context.expand_expr(context.attrs._if)) diff --git a/test/test_core.py b/test/test_core.py index f6f69e3..88e9b43 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -176,6 +176,10 @@ def test_depends_on_ignored() -> None: def test_conditions() -> None: wf = create_workflow(""" +var: + true_var: true + false_var: false + jobs: # check == false at the job level job1: @@ -201,7 +205,7 @@ def test_conditions() -> None: job4: name: "Job 4" steps: - - if: ${{ true }} + - if: ${{ true_var }} shell: python run: | print("This is Job 4") @@ -210,7 +214,7 @@ def test_conditions() -> None: job5: name: "Job 5" steps: - - if: ${{ false }} + - if: ${{ false_var }} shell: python run: | print("This will not be printed")