Skip to content

Commit

Permalink
Use pipeline default tasks for task include/exclude check
Browse files Browse the repository at this point in the history
  • Loading branch information
ghukill committed Jul 16, 2024
1 parent bdc9859 commit 22a1171
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
6 changes: 5 additions & 1 deletion hrqb/base/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,12 @@ def requires(self) -> Iterator[luigi.Task]:
def verify_include_and_exclude_tasks_exist(self) -> None:
"""Verify that included and excluded tasks exist in the pipeline."""
filter_tasks = (self.include_tasks or ()) + (self.exclude_tasks or ())
all_pipeline_tasks = {
task.name: task
for _, task in self.pipeline_tasks_iter(use_default_requires=True)
}
for task_name in filter_tasks:
if self.get_task(task_name) is None:
if task_name not in all_pipeline_tasks:
raise TaskNotInPipelineScopeError(task_name)

@staticmethod
Expand Down
6 changes: 3 additions & 3 deletions hrqb/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def pipeline(
pipeline_parameters=pipeline_parameters,
)
except TaskNotInPipelineScopeError as exc:
message = f"--include-tasks or --exclude-task are invalid: {exc}, exiting"
message = f"CLI options --include or --exclude are invalid: {exc} Exiting."
raise click.ClickException(message) from exc

ctx.obj["PIPELINE_TASK"] = pipeline_task
Expand All @@ -161,6 +161,8 @@ def remove_data(ctx: click.Context) -> None:
pipeline_task = ctx.obj["PIPELINE_TASK"]
pipeline_task.remove_pipeline_targets()
logger.info("Successfully removed target data(s).")
logger.info("Updated status after data cleanup:")
logger.info(pipeline_task.pipeline_as_ascii())


@pipeline.command()
Expand All @@ -183,5 +185,3 @@ def run(

if cleanup:
ctx.invoke(remove_data)
logger.info("Updated status after data cleanup:")
logger.info(pipeline_task.pipeline_as_ascii())
8 changes: 4 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def test_cli_pipeline_remove_data_task_not_found(
result = runner.invoke(cli.main, args)
assert result.exit_code == ERROR_RESULT_CODE
assert (
"--include-tasks or --exclude-task are invalid: Task 'BadTask' not found in "
"pipeline" in result.output
"CLI options --include or --exclude are invalid: Task 'BadTask' not found in "
"pipeline. Exiting." in result.output
)


Expand Down Expand Up @@ -211,8 +211,8 @@ def test_cli_pipeline_run_start_task_not_found_error(caplog, runner):
result = runner.invoke(cli.main, args)
assert result.exit_code == ERROR_RESULT_CODE
assert (
"--include-tasks or --exclude-task are invalid: Task 'BadTask' not found in "
"pipeline" in result.output
"CLI options --include or --exclude are invalid: Task 'BadTask' not found in "
"pipeline. Exiting." in result.output
)


Expand Down
16 changes: 16 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from hrqb.exceptions import ExcludedTaskRequiredError, TaskNotInPipelineScopeError

TASK_NAME = "TaskFoo"


def test_excluded_task_required_exception_message():
exc = ExcludedTaskRequiredError("TaskFoo")
assert str(exc) == (
f"Task '{TASK_NAME}' was required by pipeline but is explicitly "
"excluded and does not have pre-existing target data."
)


def test_task_not_in_pipeline_scope_exception_message():
exc = TaskNotInPipelineScopeError("TaskFoo")
assert str(exc) == f"Task '{TASK_NAME}' not found in pipeline."

0 comments on commit 22a1171

Please sign in to comment.