def suite_delete(suite, directory): """ Delete an expectation suite from the expectation store. """ usage_event = "cli.suite.delete" context = toolkit.load_data_context_with_error_handling(directory) suite_names = context.list_expectation_suite_names() if not suite_names: toolkit.exit_with_failure_message_and_stats( context, usage_event, "</red>No expectation suites found in the project.</red>", ) if suite not in suite_names: toolkit.exit_with_failure_message_and_stats( context, usage_event, f"No expectation suite named {suite} found." ) context.delete_expectation_suite(suite) cli_message(f"Deleted the expectation suite named: {suite}") send_usage_message( data_context=context, event=usage_event, api_version="v2", success=True, )
def checkpoint_script(checkpoint, directory): """ Create a python script to run a checkpoint. (Experimental) Checkpoints can be run directly without this script using the `great_expectations checkpoint run` command. This script is provided for those who wish to run checkpoints via python. """ context = toolkit.load_data_context_with_error_handling(directory) usage_event = "cli.checkpoint.script" # Attempt to load the checkpoint and deal with errors _ = toolkit.load_checkpoint(context, checkpoint, usage_event) script_name = f"run_{checkpoint}.py" script_path = os.path.join( context.root_directory, context.GE_UNCOMMITTED_DIR, script_name ) if os.path.isfile(script_path): toolkit.exit_with_failure_message_and_stats( context, usage_event, f"""<red>Warning! A script named {script_name} already exists and this command will not overwrite it.</red> - Existing file path: {script_path}""", ) _write_checkpoint_script_to_disk(context.root_directory, checkpoint, script_path) cli_message( f"""<green>A python script was created that runs the checkpoint named: `{checkpoint}`</green> - The script is located in `great_expectations/uncommitted/run_{checkpoint}.py` - The script can be run with `python great_expectations/uncommitted/run_{checkpoint}.py`""" ) toolkit.send_usage_message(context, event=usage_event, success=True)
def checkpoint_run(checkpoint, directory): """Run a checkpoint. (Experimental)""" usage_event = "cli.checkpoint.run" context = toolkit.load_data_context_with_error_handling( directory=directory, from_cli_upgrade_command=False ) checkpoint: Checkpoint = toolkit.load_checkpoint( context, checkpoint, usage_event, ) try: results = checkpoint.run() except Exception as e: toolkit.exit_with_failure_message_and_stats( context, usage_event, f"<red>{e}</red>" ) if not results["success"]: cli_message("Validation failed!") toolkit.send_usage_message(context, event=usage_event, success=True) print_validation_operator_results_details(results) sys.exit(1) cli_message("Validation succeeded!") toolkit.send_usage_message(context, event=usage_event, success=True) print_validation_operator_results_details(results) sys.exit(0)
def _verify_checkpoint_does_not_exist(context: DataContext, checkpoint: str, usage_event: str) -> None: try: if checkpoint in context.list_checkpoints(): toolkit.exit_with_failure_message_and_stats( context, usage_event, f"A checkpoint named `{checkpoint}` already exists. Please choose a new name.", ) except InvalidTopLevelConfigKeyError as e: toolkit.exit_with_failure_message_and_stats(context, usage_event, f"<red>{e}</red>")
def checkpoint_run(checkpoint, directory): """Run a checkpoint. (Experimental)""" usage_event = "cli.checkpoint.run" context = toolkit.load_data_context_with_error_handling( directory=directory, from_cli_upgrade_command=False) ge_config_version = context.get_config().config_version if ge_config_version >= 3: cli_message( f"""<red>The `checkpoint run` CLI command is not yet implemented for Great Expectations config versions >= 3.</red>""" ) toolkit.send_usage_message(context, usage_event, success=False) sys.exit(1) checkpoint: Checkpoint = toolkit.load_checkpoint( context, checkpoint, usage_event, ) try: results = checkpoint.run() except Exception as e: toolkit.exit_with_failure_message_and_stats(context, usage_event, f"<red>{e}</red>") if not results["success"]: cli_message("Validation failed!") toolkit.send_usage_message(context, event=usage_event, success=True) print_validation_operator_results_details(results) sys.exit(1) cli_message("Validation succeeded!") toolkit.send_usage_message(context, event=usage_event, success=True) print_validation_operator_results_details(results) sys.exit(0)