-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ENHANCEMENT] CLI init
command implemented for v3 api
#2626
Merged
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b172238
First pass messaging and flow changes
anthonyburdi 7cc4000
Fix project with missing files code path
anthonyburdi 5d298ee
Test complete project
anthonyburdi 54ca1c7
Remove --no-view option
anthonyburdi c229644
Test --assume-yes for new project
anthonyburdi b238ffb
Move warning message after checking for config
anthonyburdi ddd0d10
Add test_cancelled_cli_init_on_new_project and cleanup
anthonyburdi 1470262
Remove todo
anthonyburdi 025b75a
Rename test after adding path with no to prompt
anthonyburdi b3309d4
Remove unused messages
anthonyburdi a2f0106
Add changelog entry
anthonyburdi 2967170
Merge branch 'develop' into anthony/cli-update/init
anthonyburdi 925a83a
Remove unused data fixtures
anthonyburdi 2081836
Check msg with --assume-yes flag
anthonyburdi a939c29
Remove mock webbrowser
anthonyburdi File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
import os | ||
import sys | ||
import warnings | ||
|
||
import click | ||
|
||
from great_expectations import DataContext | ||
from great_expectations import exceptions as ge_exceptions | ||
from great_expectations.cli import toolkit | ||
from great_expectations.cli.build_docs import build_docs | ||
from great_expectations.cli.cli_messages import ( | ||
BUILD_DOCS_PROMPT, | ||
COMPLETE_ONBOARDING_PROMPT, | ||
GREETING, | ||
HOW_TO_CUSTOMIZE, | ||
LETS_BEGIN_PROMPT, | ||
ONBOARDING_COMPLETE, | ||
PROJECT_IS_COMPLETE, | ||
READY_FOR_CUSTOMIZATION, | ||
RUN_INIT_AGAIN, | ||
SECTION_SEPARATOR, | ||
SETUP_SUCCESS, | ||
SLACK_LATER, | ||
SLACK_SETUP_COMPLETE, | ||
SLACK_SETUP_INTRO, | ||
SLACK_SETUP_PROMPT, | ||
SLACK_WEBHOOK_PROMPT, | ||
) | ||
from great_expectations.cli.pretty_printing import ( | ||
cli_message, | ||
display_not_implemented_message_and_exit, | ||
) | ||
from great_expectations.cli.pretty_printing import cli_message | ||
from great_expectations.exceptions import ( | ||
DataContextError, | ||
DatasourceInitializationError, | ||
|
@@ -41,19 +39,13 @@ | |
|
||
|
||
@click.command() | ||
@click.option( | ||
# Note this --no-view option is mostly here for tests | ||
"--view/--no-view", | ||
help="By default open in browser unless you specify the --no-view flag.", | ||
default=True, | ||
) | ||
@click.option( | ||
"--usage-stats/--no-usage-stats", | ||
help="By default, usage statistics are enabled unless you specify the --no-usage-stats flag.", | ||
default=True, | ||
) | ||
@click.pass_context | ||
def init(ctx, view, usage_stats): | ||
def init(ctx, usage_stats): | ||
""" | ||
Initialize a new Great Expectations project. | ||
|
||
|
@@ -63,7 +55,6 @@ def init(ctx, view, usage_stats): | |
It scaffolds directories, sets up notebooks, creates a project file, and | ||
appends to a `.gitignore` file. | ||
""" | ||
display_not_implemented_message_and_exit() | ||
directory = toolkit.parse_cli_config_file_location( | ||
config_file_location=ctx.obj.config_file_location | ||
).get("directory") | ||
|
@@ -74,22 +65,34 @@ def init(ctx, view, usage_stats): | |
cli_message(GREETING) | ||
|
||
if DataContext.does_config_exist_on_disk(ge_dir): | ||
message = ( | ||
f"""Warning. An existing `{DataContext.GE_YML}` was found here: {ge_dir}.""" | ||
) | ||
warnings.warn(message) | ||
try: | ||
if DataContext.is_project_initialized(ge_dir): | ||
# Ensure the context can be instantiated | ||
project_file_structure_exists = ( | ||
DataContext.does_config_exist_on_disk(ge_dir) | ||
and DataContext.all_uncommitted_directories_exist(ge_dir) | ||
and DataContext.config_variables_yml_exist(ge_dir) | ||
) | ||
if project_file_structure_exists: | ||
cli_message(PROJECT_IS_COMPLETE) | ||
sys.exit(0) | ||
else: | ||
# Prompt to modify the project to add missing files | ||
if not ctx.obj.assume_yes: | ||
if not click.confirm(COMPLETE_ONBOARDING_PROMPT, default=True): | ||
cli_message(RUN_INIT_AGAIN) | ||
exit(0) | ||
|
||
except (DataContextError, DatasourceInitializationError) as e: | ||
cli_message("<red>{}</red>".format(e.message)) | ||
sys.exit(1) | ||
|
||
try: | ||
context = DataContext.create( | ||
target_directory, usage_statistics_enabled=usage_stats | ||
) | ||
DataContext.create(target_directory, usage_statistics_enabled=usage_stats) | ||
cli_message(ONBOARDING_COMPLETE) | ||
# TODO if this is correct, ensure this is covered by a test | ||
# cli_message(SETUP_SUCCESS) | ||
# exit(0) | ||
|
||
except DataContextError as e: | ||
cli_message("<red>{}</red>".format(e.message)) | ||
# TODO ensure this is covered by a test | ||
|
@@ -98,7 +101,6 @@ def init(ctx, view, usage_stats): | |
if not ctx.obj.assume_yes: | ||
if not click.confirm(LETS_BEGIN_PROMPT, default=True): | ||
cli_message(RUN_INIT_AGAIN) | ||
# TODO ensure this is covered by a test | ||
exit(0) | ||
|
||
try: | ||
|
@@ -112,94 +114,10 @@ def init(ctx, view, usage_stats): | |
# TODO ensure this is covered by a test | ||
cli_message("<red>{}</red>".format(e)) | ||
|
||
# Skip the rest of setup if --assume-yes flag is passed | ||
if ctx.obj.assume_yes: | ||
cli_message(SECTION_SEPARATOR) | ||
cli_message(SETUP_SUCCESS) | ||
sys.exit(0) | ||
|
||
try: | ||
# if expectations exist, offer to build docs | ||
context = DataContext(ge_dir) | ||
if context.list_expectation_suites(): | ||
if click.confirm(BUILD_DOCS_PROMPT, default=True): | ||
build_docs(context, view=view) | ||
|
||
else: | ||
datasources = context.list_datasources() | ||
if len(datasources) == 0: | ||
cli_message(SECTION_SEPARATOR) | ||
if not click.confirm( | ||
"Would you like to configure a Datasource?", default=True | ||
): | ||
cli_message("Okay, bye!") | ||
sys.exit(1) | ||
datasource_name, data_source_type = add_datasource_impl( | ||
context, choose_one_data_asset=False | ||
) | ||
if not datasource_name: # no datasource was created | ||
sys.exit(1) | ||
|
||
datasources = context.list_datasources() | ||
if len(datasources) == 1: | ||
datasource_name = datasources[0]["name"] | ||
|
||
cli_message(SECTION_SEPARATOR) | ||
if not click.confirm( | ||
"Would you like to profile new Expectations for a single data asset within your new Datasource?", | ||
default=True, | ||
): | ||
cli_message( | ||
"Okay, exiting now. To learn more about Profilers, run great_expectations profile --help or visit docs.greatexpectations.io!" | ||
) | ||
sys.exit(1) | ||
|
||
( | ||
success, | ||
suite_name, | ||
profiling_results, | ||
) = toolkit.create_expectation_suite( | ||
context, | ||
datasource_name=datasource_name, | ||
additional_batch_kwargs={"limit": 1000}, | ||
flag_build_docs=False, | ||
open_docs=False, | ||
) | ||
|
||
cli_message(SECTION_SEPARATOR) | ||
if not click.confirm( | ||
"Would you like to build Data Docs?", default=True | ||
): | ||
cli_message( | ||
"Okay, exiting now. To learn more about Data Docs, run great_expectations docs --help or visit docs.greatexpectations.io!" | ||
) | ||
sys.exit(1) | ||
|
||
build_docs(context, view=False) | ||
|
||
if not click.confirm( | ||
"\nWould you like to view your new Expectations in Data Docs? This will open a new browser window.", | ||
default=True, | ||
): | ||
cli_message( | ||
"Okay, exiting now. You can view the site that has been created in a browser, or visit docs.greatexpectations.io for more information!" | ||
) | ||
sys.exit(1) | ||
toolkit.attempt_to_open_validation_results_in_data_docs( | ||
context, profiling_results | ||
) | ||
|
||
cli_message(SECTION_SEPARATOR) | ||
cli_message(SETUP_SUCCESS) | ||
sys.exit(0) | ||
except ( | ||
DataContextError, | ||
ge_exceptions.ProfilerError, | ||
OSError, | ||
SQLAlchemyError, | ||
) as e: | ||
cli_message("<red>{}</red>".format(e)) | ||
sys.exit(1) | ||
Comment on lines
-115
to
-202
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👋 Bye! |
||
cli_message(SECTION_SEPARATOR) | ||
cli_message(READY_FOR_CUSTOMIZATION) | ||
cli_message(HOW_TO_CUSTOMIZE) | ||
sys.exit(0) | ||
|
||
|
||
def _slack_setup(context): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YAY