From e33556ef1b5ee0568ba17d3b8830453af51c3c96 Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Fri, 8 Mar 2024 18:40:47 +0000 Subject: [PATCH 1/7] Added cookiecutter exceptions output Signed-off-by: Elena Khaustova --- kedro/framework/cli/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kedro/framework/cli/utils.py b/kedro/framework/cli/utils.py index 46fc5bdc62..70c19ad35b 100644 --- a/kedro/framework/cli/utils.py +++ b/kedro/framework/cli/utils.py @@ -265,6 +265,7 @@ class KedroCliError(click.exceptions.ClickException): VERBOSE_ERROR = False VERBOSE_EXISTS = True + COOKIECUTTER_EXCEPTIONS_PREFIX = "cookiecutter.exceptions" def show(self, file: IO | None = None) -> None: if self.VERBOSE_ERROR: @@ -272,8 +273,13 @@ def show(self, file: IO | None = None) -> None: elif self.VERBOSE_EXISTS: etype, value, _ = sys.exc_info() formatted_exception = "".join(traceback.format_exception_only(etype, value)) + cookiecutter_exception = "" + for ex_line in traceback.format_exception(value): + if self.COOKIECUTTER_EXCEPTIONS_PREFIX in ex_line: + cookiecutter_exception = ex_line + break click.secho( - f"{formatted_exception}Run with --verbose to see the full exception", + f"{cookiecutter_exception}{formatted_exception}Run with --verbose to see the full exception", fg="yellow", ) else: From f2a9000cc07ab98f199031be8ba7a6a172fa2114 Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Fri, 8 Mar 2024 19:41:10 +0000 Subject: [PATCH 2/7] Pre-commit checks Signed-off-by: Elena Khaustova --- tests/framework/cli/test_starters.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/framework/cli/test_starters.py b/tests/framework/cli/test_starters.py index d89270f862..a8ecf14885 100644 --- a/tests/framework/cli/test_starters.py +++ b/tests/framework/cli/test_starters.py @@ -490,6 +490,15 @@ def test_fail_if_dir_exists(self, fake_kedro_cli): assert result.exit_code != 0 assert "directory already exists" in result.output + def test_cookiecutter_exception_if_no_verbose(self, fake_kedro_cli): + """Check if original cookiecutter exception present in the output if no verbose + flag provided.""" + Path("new-kedro-project").mkdir() + result = CliRunner().invoke( + fake_kedro_cli, ["new"], input=_make_cli_prompt_input() + ) + assert "cookiecutter.exceptions" in result.output + def test_prompt_no_title(self, fake_kedro_cli): shutil.copytree(TEMPLATE_PATH, "template") _write_yaml(Path("template") / "prompts.yml", {"repo_name": {}}) From 8f82253efdf4a743db7653880645b73c696016d0 Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Mon, 11 Mar 2024 13:45:47 +0000 Subject: [PATCH 3/7] Added release note Signed-off-by: Elena Khaustova --- RELEASE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE.md b/RELEASE.md index c2d3f4c211..d20475cc22 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,6 +1,7 @@ # Upcoming Release 0.19.4 ## Major features and improvements +* Cookiecutter errors are shown is short format without `--verbose` flag. * Kedro commands now work from any subdirectory within a Kedro project. * Kedro CLI now provides a better error message when project commands are run outside of a project i.e. `kedro run` From d7f071843772b28f4e858ba9b28d83ff16e1d7c1 Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Mon, 11 Mar 2024 14:10:53 +0000 Subject: [PATCH 4/7] Fixed types for python3.8 Signed-off-by: Elena Khaustova --- kedro/framework/cli/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kedro/framework/cli/utils.py b/kedro/framework/cli/utils.py index 70c19ad35b..194b244b5f 100644 --- a/kedro/framework/cli/utils.py +++ b/kedro/framework/cli/utils.py @@ -271,10 +271,10 @@ def show(self, file: IO | None = None) -> None: if self.VERBOSE_ERROR: click.secho(traceback.format_exc(), nl=False, fg="yellow") elif self.VERBOSE_EXISTS: - etype, value, _ = sys.exc_info() + etype, value, tb = sys.exc_info() formatted_exception = "".join(traceback.format_exception_only(etype, value)) cookiecutter_exception = "" - for ex_line in traceback.format_exception(value): + for ex_line in traceback.format_exception(etype, value, tb): if self.COOKIECUTTER_EXCEPTIONS_PREFIX in ex_line: cookiecutter_exception = ex_line break From b6d1eabec07c6ab816e06cdee7c5ed3b9c8d4595 Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Mon, 11 Mar 2024 19:42:00 +0000 Subject: [PATCH 5/7] Fixed VERBOSE_EXISTS redefining Signed-off-by: Elena Khaustova --- tests/framework/cli/test_starters.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/framework/cli/test_starters.py b/tests/framework/cli/test_starters.py index a8ecf14885..7480491722 100644 --- a/tests/framework/cli/test_starters.py +++ b/tests/framework/cli/test_starters.py @@ -23,6 +23,7 @@ _parse_yes_no_to_bool, _validate_tool_selection, ) +from kedro.framework.cli.utils import KedroCliError FILES_IN_TEMPLATE_WITH_NO_TOOLS = 15 @@ -493,6 +494,7 @@ def test_fail_if_dir_exists(self, fake_kedro_cli): def test_cookiecutter_exception_if_no_verbose(self, fake_kedro_cli): """Check if original cookiecutter exception present in the output if no verbose flag provided.""" + KedroCliError.VERBOSE_EXISTS = True Path("new-kedro-project").mkdir() result = CliRunner().invoke( fake_kedro_cli, ["new"], input=_make_cli_prompt_input() From 19715b1910ddc88ba03bc759ad2e2a19c53a4b0b Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Tue, 12 Mar 2024 13:32:24 +0000 Subject: [PATCH 6/7] Moved VERBOSE_EXISTS reset to end of the test that changes it Signed-off-by: Elena Khaustova --- tests/framework/cli/test_cli.py | 1 + tests/framework/cli/test_starters.py | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/framework/cli/test_cli.py b/tests/framework/cli/test_cli.py index c1e5ce51ec..d147a6a0d1 100644 --- a/tests/framework/cli/test_cli.py +++ b/tests/framework/cli/test_cli.py @@ -691,6 +691,7 @@ def test_run_with_invalid_config( "Key `node-names` in provided configuration is not valid. \n\nDid you mean one of " "these?\n node_names\n to_nodes\n namespace" in result.stdout ) + KedroCliError.VERBOSE_EXISTS = True @mark.parametrize( "fake_run_config_with_params,expected", diff --git a/tests/framework/cli/test_starters.py b/tests/framework/cli/test_starters.py index 7480491722..a8ecf14885 100644 --- a/tests/framework/cli/test_starters.py +++ b/tests/framework/cli/test_starters.py @@ -23,7 +23,6 @@ _parse_yes_no_to_bool, _validate_tool_selection, ) -from kedro.framework.cli.utils import KedroCliError FILES_IN_TEMPLATE_WITH_NO_TOOLS = 15 @@ -494,7 +493,6 @@ def test_fail_if_dir_exists(self, fake_kedro_cli): def test_cookiecutter_exception_if_no_verbose(self, fake_kedro_cli): """Check if original cookiecutter exception present in the output if no verbose flag provided.""" - KedroCliError.VERBOSE_EXISTS = True Path("new-kedro-project").mkdir() result = CliRunner().invoke( fake_kedro_cli, ["new"], input=_make_cli_prompt_input() From 683e02a97f81576aa2b5f689ecfc2088508a35da Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Tue, 12 Mar 2024 14:10:05 +0000 Subject: [PATCH 7/7] Fixed typos Signed-off-by: Elena Khaustova --- RELEASE.md | 2 +- tests/framework/cli/test_starters.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index d20475cc22..745ebbe459 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,7 +1,7 @@ # Upcoming Release 0.19.4 ## Major features and improvements -* Cookiecutter errors are shown is short format without `--verbose` flag. +* Cookiecutter errors are shown in short format without the `--verbose` flag. * Kedro commands now work from any subdirectory within a Kedro project. * Kedro CLI now provides a better error message when project commands are run outside of a project i.e. `kedro run` diff --git a/tests/framework/cli/test_starters.py b/tests/framework/cli/test_starters.py index a8ecf14885..09ae542fd3 100644 --- a/tests/framework/cli/test_starters.py +++ b/tests/framework/cli/test_starters.py @@ -491,8 +491,8 @@ def test_fail_if_dir_exists(self, fake_kedro_cli): assert "directory already exists" in result.output def test_cookiecutter_exception_if_no_verbose(self, fake_kedro_cli): - """Check if original cookiecutter exception present in the output if no verbose - flag provided.""" + """Check if the original cookiecutter exception is present in the output + if no verbose flag is provided.""" Path("new-kedro-project").mkdir() result = CliRunner().invoke( fake_kedro_cli, ["new"], input=_make_cli_prompt_input()