Skip to content

Instantly share code, notes, and snippets.

@WaylonWalker
Last active May 27, 2020 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WaylonWalker/2f1da8d47e511d188c50b8cccb7e3856 to your computer and use it in GitHub Desktop.
Save WaylonWalker/2f1da8d47e511d188c50b8cccb7e3856 to your computer and use it in GitHub Desktop.
# full article https://waylonwalker.com/blog/creating-the-kedro-preflight-hook/
from kedro.hooks import hook_impl
from kedro.io.core import DataSetNotFoundError
from colorama import Fore
import textwrap
@hook_impl
def before_pipeline_run(run_params, pipeline, catalog):
missing_input = [i for i in pipeline.inputs() if not getattr(catalog.datasets, i)._exists()]
if len(missing_input) != 0:
raise DataSetNotFoundError(textwrap.dedent(f'''
{Fore.LIGHTBLACK_EX}―――――――― {Fore.RED}PREFLIGHT ERROR {Fore.LIGHTBLACK_EX}―――――――――
{Fore.RESET} preflight of pipeline failed due to {Fore.YELLOW}missing datasets
{Fore.BLUE} {missing_input}{Fore.RESET}
'''))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment