def checkpoint_new(checkpoint, suite, directory, datasource): """Create a new checkpoint for easy deployments. (Experimental)""" suite_name = suite usage_event = "cli.checkpoint.new" context = toolkit.load_data_context_with_error_handling(directory) _verify_checkpoint_does_not_exist(context, checkpoint, usage_event) suite: ExpectationSuite = toolkit.load_expectation_suite( context, suite_name, usage_event) datasource = toolkit.select_datasource(context, datasource_name=datasource) if datasource is None: send_usage_message(context, usage_event, success=False) sys.exit(1) _, _, _, batch_kwargs = toolkit.get_batch_kwargs(context, datasource.name) template = _load_checkpoint_yml_template() # This picky update helps template comments stay in place template["batches"][0]["batch_kwargs"] = dict(batch_kwargs) template["batches"][0]["expectation_suite_names"] = [ suite.expectation_suite_name ] checkpoint_file = _write_checkpoint_to_disk(context, template, checkpoint) cli_message( f"""<green>A checkpoint named `{checkpoint}` was added to your project!</green> - To edit this checkpoint edit the checkpoint file: {checkpoint_file} - To run this checkpoint run `great_expectations checkpoint run {checkpoint}`""" ) send_usage_message(context, usage_event, success=True)
def checkpoint_new(checkpoint, suite, directory, datasource, legacy): """Create a new checkpoint for easy deployments. (Experimental)""" if legacy: suite_name = suite usage_event = "cli.checkpoint.new" context = toolkit.load_data_context_with_error_handling(directory) ge_config_version = context.get_config().config_version if ge_config_version >= 3: cli_message( f"""<red>The `checkpoint new` CLI command is not yet implemented for GE config versions >= 3.</red>""" ) send_usage_message(context, usage_event, success=False) sys.exit(1) _verify_checkpoint_does_not_exist(context, checkpoint, usage_event) suite: ExpectationSuite = toolkit.load_expectation_suite( context, suite_name, usage_event) datasource = toolkit.select_datasource(context, datasource_name=datasource) if datasource is None: send_usage_message(context, usage_event, success=False) sys.exit(1) _, _, _, batch_kwargs = toolkit.get_batch_kwargs( context, datasource.name) _ = context.add_checkpoint( name=checkpoint, **{ "class_name": "LegacyCheckpoint", "validation_operator_name": "action_list_operator", "batches": [{ "batch_kwargs": dict(batch_kwargs), "expectation_suite_names": [suite.expectation_suite_name], }], }, ) cli_message( f"""<green>A checkpoint named `{checkpoint}` was added to your project!</green> - To run this checkpoint run `great_expectations checkpoint run {checkpoint}`""" ) send_usage_message(context, usage_event, success=True) # TODO: <Rob>Rob</Rob> Add flow for new style checkpoints else: pass