<commit_before>import glob
import json
import shutil
import sys
import os
import argparse
import logging
from pyfiglet import figlet_format
import six
import click
# from clint.textui import prompt, validators
# from clint.textui import colored as clint_colored, puts, indent

try:
    from termcolor import colored
except ImportError:
    colored = None

from great_expectations import read_csv, script_relative_path
from great_expectations import __version__
from great_expectations.dataset import Dataset, PandasDataset
from great_expectations.data_asset import FileDataAsset
from great_expectations.data_context import DataContext

from .supporting_methods import (
    _scaffold_directories_and_notebooks,
    _yml_template,
)

logger = logging.getLogger(__name__)


def log_message(string, color, font="big", figlet=False):
    if colored:
        if not figlet:
            six.print_(colored(string, color))
        else:
            six.print_(colored(figlet_format(
                string, font=font), color))
    else:
        six.print_(string)


def dispatch(args):
    parser = argparse.ArgumentParser(
        description='great_expectations command-line interface')

    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True

    validate_parser = subparsers.add_parser(
        'validate', description='Validate expectations for your dataset.')
    validate_parser.set_defaults(func=validate)

    validate_parser.add_argument('dataset',
                                 help='Path to a file containing a CSV file to validate using the provided expectations_config_file.')
    validate_parser.add_argument('expectations_config_file',
                                 help='Path to a file containing a valid great_expectations expectations config to use to validate the data.')

    validate_parser.add_argument('--evaluation_parameters', '-p', default=None,
                                 help='Path to a file containing JSON object used to evaluate parameters in expectations config.')
    validate_parser.add_argument('--result_format', '-o', default="SUMMARY",
                                 help='Result format to use when building evaluation responses.')
    validate_parser.add_argument('--catch_exceptions', '-e', default=True, type=bool,
                                 help='Specify whether to catch exceptions raised during evaluation of expectations (defaults to True).')
    validate_parser.add_argument('--only_return_failures', '-f', default=False, type=bool,
                                 help='Specify whether to only return expectations that are not met during evaluation (defaults to False).')
    # validate_parser.add_argument('--no_catch_exceptions', '-e', default=True, action='store_false')
    # validate_parser.add_argument('--only_return_failures', '-f', default=False, action='store_true')
    custom_dataset_group = validate_parser.add_argument_group(
        'custom_dataset', description='Arguments defining a custom dataset to use for validation.')
    custom_dataset_group.add_argument('--custom_dataset_module', '-m', default=None,
                                      help='Path to a python module containing a custom dataset class.')
    custom_dataset_group.add_argument('--custom_dataset_class', '-c', default=None,
                                      help='Name of the custom dataset class to use during evaluation.')

    version_parser = subparsers.add_parser('version')
    version_parser.set_defaults(func=version)

    scaffold_parser = subparsers.add_parser('init')
    scaffold_parser.set_defaults(func=initialize_project)
    scaffold_parser.add_argument('--target_directory', '-d', default="./",
                                 help='The root of the project directory where you want to initialize Great Expectations.')
    parsed_args = parser.parse_args(args)

    return parsed_args.func(parsed_args)


def initialize_project(parsed_args):
    """
    This guided input walks the user through setting up a project.

    It scaffolds directories, sets up notebooks, creates a project file, and
    appends to a `.gitignore` file.
    """

    greeting_1 = """
Welcome to Great Expectations! Always know what to expect from your data.

When you develop data pipelines, ML models, ETLs and other data products, 
Great Expectations helps you express what you expect your data to look like 
(e.g., "column X should not have more than 5% null values"). 
It produces tests and documentation.

When your data product runs in production, 
Great Expectations uses the tests that you created to validate data and protect 
your code against data that it was not written to deal with.

    """

    msg_prompt_lets_begin = """
Let's add Great Expectations to your project. 
We will add great_expectations directory that will look like that: 

    great_expectations
        ├── great_expectations.yml        
        ├── datasources
        ├── expectations
        ├── fixtures
        ├── notebooks
        ├── plugins
        ├── uncommitted
        |   └── validations        
        |   └── credentials        
        |   └── samples        
        ├── .gitignore
    
OK to proceed?    
    """

    msg_prompt_choose_data_source = """
Time to create expectations for your data. This is done in Jupyter Notebook/Jupyter Lab. 

Before we point you to the right notebook, what data does your project work with?    
    1. Directory on local filesystem
    2. Relational database (SQL)
    3. DBT (data build tool) models
    4. None of the above
    """

    msg_prompt_dbt_choose_profile = """
Please specify the name of the dbt profile (from your ~/.dbt/profiles.yml file Great Expectations should use to connect to the database    <commit_msg>Fix tree elbow<commit_after>import glob
import json
import shutil
import sys
import os
import argparse
import logging
from pyfiglet import figlet_format
import six
import click
# from clint.textui import prompt, validators
# from clint.textui import colored as clint_colored, puts, indent

try:
    from termcolor import colored
except ImportError:
    colored = None

from great_expectations import read_csv, script_relative_path
from great_expectations import __version__
from great_expectations.dataset import Dataset, PandasDataset
from great_expectations.data_asset import FileDataAsset
from great_expectations.data_context import DataContext

from .supporting_methods import (
    _scaffold_directories_and_notebooks,
    _yml_template,
)

logger = logging.getLogger(__name__)


def log_message(string, color, font="big", figlet=False):
    if colored:
        if not figlet:
            six.print_(colored(string, color))
        else:
            six.print_(colored(figlet_format(
                string, font=font), color))
    else:
        six.print_(string)


def dispatch(args):
    parser = argparse.ArgumentParser(
        description='great_expectations command-line interface')

    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True

    validate_parser = subparsers.add_parser(
        'validate', description='Validate expectations for your dataset.')
    validate_parser.set_defaults(func=validate)

    validate_parser.add_argument('dataset',
                                 help='Path to a file containing a CSV file to validate using the provided expectations_config_file.')
    validate_parser.add_argument('expectations_config_file',
                                 help='Path to a file containing a valid great_expectations expectations config to use to validate the data.')

    validate_parser.add_argument('--evaluation_parameters', '-p', default=None,
                                 help='Path to a file containing JSON object used to evaluate parameters in expectations config.')
    validate_parser.add_argument('--result_format', '-o', default="SUMMARY",
                                 help='Result format to use when building evaluation responses.')
    validate_parser.add_argument('--catch_exceptions', '-e', default=True, type=bool,
                                 help='Specify whether to catch exceptions raised during evaluation of expectations (defaults to True).')
    validate_parser.add_argument('--only_return_failures', '-f', default=False, type=bool,
                                 help='Specify whether to only return expectations that are not met during evaluation (defaults to False).')
    # validate_parser.add_argument('--no_catch_exceptions', '-e', default=True, action='store_false')
    # validate_parser.add_argument('--only_return_failures', '-f', default=False, action='store_true')
    custom_dataset_group = validate_parser.add_argument_group(
        'custom_dataset', description='Arguments defining a custom dataset to use for validation.')
    custom_dataset_group.add_argument('--custom_dataset_module', '-m', default=None,
                                      help='Path to a python module containing a custom dataset class.')
    custom_dataset_group.add_argument('--custom_dataset_class', '-c', default=None,
                                      help='Name of the custom dataset class to use during evaluation.')

    version_parser = subparsers.add_parser('version')
    version_parser.set_defaults(func=version)

    scaffold_parser = subparsers.add_parser('init')
    scaffold_parser.set_defaults(func=initialize_project)
    scaffold_parser.add_argument('--target_directory', '-d', default="./",
                                 help='The root of the project directory where you want to initialize Great Expectations.')
    parsed_args = parser.parse_args(args)

    return parsed_args.func(parsed_args)


def initialize_project(parsed_args):
    """
    This guided input walks the user through setting up a project.

    It scaffolds directories, sets up notebooks, creates a project file, and
    appends to a `.gitignore` file.
    """

    greeting_1 = """
Welcome to Great Expectations! Always know what to expect from your data.

When you develop data pipelines, ML models, ETLs and other data products, 
Great Expectations helps you express what you expect your data to look like 
(e.g., "column X should not have more than 5% null values"). 
It produces tests and documentation.

When your data product runs in production, 
Great Expectations uses the tests that you created to validate data and protect 
your code against data that it was not written to deal with.

    """

    msg_prompt_lets_begin = """
Let's add Great Expectations to your project. 
We will add great_expectations directory that will look like that: 

    great_expectations
        ├── great_expectations.yml        
        ├── datasources
        ├── expectations
        ├── fixtures
        ├── notebooks
        ├── plugins
        ├── uncommitted
        |   └── validations        
        |   └── credentials        
        |   └── samples        
        └── .gitignore
    
OK to proceed?    
    """

    msg_prompt_choose_data_source = """
Time to create expectations for your data. This is done in Jupyter Notebook/Jupyter Lab. 

Before we point you to the right notebook, what data does your project work with?    
    1. Directory on local filesystem
    2. Relational database (SQL)
    3. DBT (data build tool) models
    4. None of the above
    """

    msg_prompt_dbt_choose_profile = """
Please specify the name of the dbt profile (from your ~/.dbt/profiles.yml file Great Expectations should use to connect to the database    
{'fraction_non_alphanumeric': 0.07813451666231619, 'fraction_numerical': 0.0010441138084051162, 'mean_word_length': 3.1123434704830055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5430508', 'n_tokens_mistral': 3009, 'n_tokens_neox': 2952, 'n_words': 1024}