From 90fcd265cce4def8918d32599fba97e7bacd8c9e Mon Sep 17 00:00:00 2001 From: lrcouto Date: Mon, 11 Mar 2024 19:25:31 -0300 Subject: [PATCH 01/11] First draft for telemetry consent flag on kedro new Signed-off-by: lrcouto --- kedro/framework/cli/starters.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index 5ec32af209..f9d5c5aae8 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -67,6 +67,11 @@ """ EXAMPLE_ARG_HELP = "Enter y to enable, n to disable the example pipeline." +TELEMETRY_ARG_HELP = """Allow or not allow Kedro to collect usage analytics. +We cannot see nor store information contained into a Kedro project. Opt in with "yes" +and out with "no". +""" + @define(order=True) class KedroStarterSpec: @@ -261,6 +266,7 @@ def starter() -> None: @click.option("--tools", "-t", "selected_tools", help=TOOLS_ARG_HELP) @click.option("--name", "-n", "project_name", help=NAME_ARG_HELP) @click.option("--example", "-e", "example_pipeline", help=EXAMPLE_ARG_HELP) +@click.option("--telemetry", "-tc", "telemetry_consent", help=TELEMETRY_ARG_HELP) def new( # noqa: PLR0913 config_path: str, starter_alias: str, @@ -269,6 +275,7 @@ def new( # noqa: PLR0913 checkout: str, directory: str, example_pipeline: str, # This will be True or False + telemetry_consent: str, # This will be True or False **kwargs: Any, ) -> None: """Create a new kedro project.""" @@ -280,6 +287,7 @@ def new( # noqa: PLR0913 "checkout": checkout, "directory": directory, "example": example_pipeline, + "telemetry_consent": telemetry_consent, } _validate_flag_inputs(flag_inputs) starters_dict = _get_starters_dict() @@ -343,7 +351,7 @@ def new( # noqa: PLR0913 template_path=template_path, ) - _create_project(project_template, cookiecutter_args) + _create_project(project_template, cookiecutter_args, telemetry_consent) # If not a starter, print tools and example selection if not starter_alias: @@ -876,7 +884,9 @@ def _validate_range(start: Any, end: Any) -> None: return selected -def _create_project(template_path: str, cookiecutter_args: dict[str, Any]) -> None: +def _create_project( + template_path: str, cookiecutter_args: dict[str, Any], telemetry_consent: str +) -> None: """Creates a new kedro project using cookiecutter. Args: @@ -893,6 +903,10 @@ def _create_project(template_path: str, cookiecutter_args: dict[str, Any]) -> No try: result_path = cookiecutter(template=template_path, **cookiecutter_args) + + if telemetry_consent is not None: + with open(result_path + "/.telemetry", "w") as telemetry_file: + telemetry_file.write("consent: false") except Exception as exc: raise KedroCliError( "Failed to generate project when running cookiecutter." From 8d0d13b5d2b47dbd3bbe5d73bbf57dd7df7f8277 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Tue, 12 Mar 2024 13:53:14 -0300 Subject: [PATCH 02/11] Add functioning --telemetry option to kedro new Signed-off-by: lrcouto --- kedro/framework/cli/starters.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index f9d5c5aae8..27335cd5c2 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -351,6 +351,12 @@ def new( # noqa: PLR0913 template_path=template_path, ) + if telemetry_consent is not None: + _validate_input_with_regex_pattern("yes_no", telemetry_consent) + telemetry_consent = ( + "true" if _parse_yes_no_to_bool(telemetry_consent) else "false" + ) + _create_project(project_template, cookiecutter_args, telemetry_consent) # If not a starter, print tools and example selection @@ -906,7 +912,7 @@ def _create_project( if telemetry_consent is not None: with open(result_path + "/.telemetry", "w") as telemetry_file: - telemetry_file.write("consent: false") + telemetry_file.write("consent: " + telemetry_consent) except Exception as exc: raise KedroCliError( "Failed to generate project when running cookiecutter." From 482d093fee3806b898ff3c69e9283cd9265e6cd0 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Tue, 12 Mar 2024 16:47:42 -0300 Subject: [PATCH 03/11] Update tests to acknowledge new flag Signed-off-by: lrcouto --- tests/tools/test_cli.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/tools/test_cli.py b/tests/tools/test_cli.py index ece4c7054d..58d15d5f08 100644 --- a/tests/tools/test_cli.py +++ b/tests/tools/test_cli.py @@ -106,6 +106,8 @@ def test_get_cli_structure_depth(self, mocker, fake_metadata): "-t", "--example", "-e", + "--telemetry", + "-tc", "--starter", "-s", "--name", From 6504100153b303dd300c65b554a6a14f7304ae73 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 13 Mar 2024 01:46:42 -0300 Subject: [PATCH 04/11] Add tests for kedro new --telemetry flag Signed-off-by: lrcouto --- tests/framework/cli/test_starters.py | 116 +++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/tests/framework/cli/test_starters.py b/tests/framework/cli/test_starters.py index d89270f862..a98a1c26eb 100644 --- a/tests/framework/cli/test_starters.py +++ b/tests/framework/cli/test_starters.py @@ -1562,3 +1562,119 @@ def test_convert_tool_short_names_to_numbers_with_duplicates(self): selected_tools = "lint,test,tests" result = _convert_tool_short_names_to_numbers(selected_tools) assert result == ["1", "2"] + + +@pytest.mark.usefixtures("chdir_to_tmp") +class TestTelemetryCLIFlag: + @pytest.mark.parametrize( + "input", + ["yes", "YES", "y", "Y", "yEs"], + ) + def test_flag_value_is_yes(self, fake_kedro_cli, input): + result = CliRunner().invoke( + fake_kedro_cli, + [ + "new", + "--name", + "New Kedro Project", + "--tools", + "none", + "--example", + "no", + "--telemetry", + input, + ], + ) + + repo_name = "new-kedro-project" + assert result.exit_code == 0 + + telemetry_file_path = Path(repo_name + "/.telemetry") + assert telemetry_file_path.exists() + + with open(telemetry_file_path) as file: + file_content = file.read() + target_string = "consent: true" + + assert target_string in file_content + _clean_up_project(Path("./" + repo_name)) + + @pytest.mark.parametrize( + "input", + ["no", "NO", "n", "N", "No"], + ) + def test_flag_value_is_no(self, fake_kedro_cli, input): + result = CliRunner().invoke( + fake_kedro_cli, + [ + "new", + "--name", + "New Kedro Project", + "--tools", + "none", + "--example", + "no", + "--telemetry", + input, + ], + ) + + repo_name = "new-kedro-project" + assert result.exit_code == 0 + + telemetry_file_path = Path(repo_name + "/.telemetry") + assert telemetry_file_path.exists() + + with open(telemetry_file_path) as file: + file_content = file.read() + target_string = "consent: false" + + assert target_string in file_content + _clean_up_project(Path("./" + repo_name)) + + def test_flag_value_is_invalid(self, fake_kedro_cli): + result = CliRunner().invoke( + fake_kedro_cli, + [ + "new", + "--name", + "New Kedro Project", + "--tools", + "none", + "--example", + "no", + "--telemetry", + "wrong", + ], + ) + + repo_name = "new-kedro-project" + assert result.exit_code == 1 + + assert ( + "'wrong' is an invalid value for example pipeline. It must contain only y, n, YES, or NO (case insensitive)." + in result.output + ) + + telemetry_file_path = Path(repo_name + "/.telemetry") + assert not telemetry_file_path.exists() + + def test_flag_is_absent(self, fake_kedro_cli): + result = CliRunner().invoke( + fake_kedro_cli, + [ + "new", + "--name", + "New Kedro Project", + "--tools", + "none", + "--example", + "no", + ], + ) + + repo_name = "new-kedro-project" + assert result.exit_code == 0 + + telemetry_file_path = Path(repo_name + "/.telemetry") + assert not telemetry_file_path.exists() From 09f174bfebbdcce305582bb4af363fc6be52bafa Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 13 Mar 2024 02:05:44 -0300 Subject: [PATCH 05/11] Add changes to documentation and release notes Signed-off-by: lrcouto --- RELEASE.md | 1 + docs/source/get_started/new_project.md | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/RELEASE.md b/RELEASE.md index e22d9f9a47..afbd571d9e 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -3,6 +3,7 @@ ## Major features and improvements * 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` +* Adds the `--telemetry` flag to `kedro new`, allowing the user to register consent to have user analytics collected as the project is created. ## Bug fixes and other changes * Updated `kedro pipeline create` and `kedro pipeline delete` to read the base environment from the project settings. diff --git a/docs/source/get_started/new_project.md b/docs/source/get_started/new_project.md index 984680dff8..e851e5d287 100644 --- a/docs/source/get_started/new_project.md +++ b/docs/source/get_started/new_project.md @@ -49,7 +49,7 @@ Select the tools by number, or `all` or follow the default to add `none`. ### Project examples -Finally, the CLI offers the option to include starter example code in the project: +The CLI offers the option to include starter example code in the project: ```text Would you like to include an example pipeline? : @@ -112,6 +112,11 @@ You can also enter this in a single line as follows: kedro new --name=testproject --tools=lint,docs,pyspark --example=n ``` +### Telemetry consent + +The `--telemetry` flag offers the option to register consent to have user analytics collected in the moment of the creation of the project. This option bypasses the prompt to collect analytics that would otherwise appear on the moment the `kedro` command is invoked for the first time inside the project. + +When creating your new Kedro project, use the values `yes` or `no` to register consent to have user analytics collected for this specific project. In case the `--telemetry` flag is not used, the user will be prompted to accept or reject analytics collection as usual. ## Run the new project From 8917e85d5a624a6c195e6ccf72f084a00e862014 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 13 Mar 2024 02:14:00 -0300 Subject: [PATCH 06/11] Minor change to docs Signed-off-by: lrcouto --- docs/source/get_started/new_project.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/get_started/new_project.md b/docs/source/get_started/new_project.md index e851e5d287..1367034fad 100644 --- a/docs/source/get_started/new_project.md +++ b/docs/source/get_started/new_project.md @@ -114,9 +114,9 @@ kedro new --name=testproject --tools=lint,docs,pyspark --example=n ### Telemetry consent -The `--telemetry` flag offers the option to register consent to have user analytics collected in the moment of the creation of the project. This option bypasses the prompt to collect analytics that would otherwise appear on the moment the `kedro` command is invoked for the first time inside the project. +The `--telemetry` flag offers the option to register consent to have user analytics collected in the moment of the creation of the project. This option bypasses the prompt to collect analytics that would otherwise appear on the moment the `kedro` command is invoked for the first time inside the project. In case the `--telemetry` flag is not used, the user will be prompted to accept or reject analytics collection as usual. -When creating your new Kedro project, use the values `yes` or `no` to register consent to have user analytics collected for this specific project. In case the `--telemetry` flag is not used, the user will be prompted to accept or reject analytics collection as usual. +When creating your new Kedro project, use the values `yes` or `no` to register consent to have user analytics collected for this specific project. ## Run the new project From 2b3b0462f7158978716dd8cf1052d43e4815d64b Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 13 Mar 2024 02:16:35 -0300 Subject: [PATCH 07/11] Lint Signed-off-by: lrcouto --- docs/source/get_started/new_project.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/get_started/new_project.md b/docs/source/get_started/new_project.md index 1367034fad..0dd808c04c 100644 --- a/docs/source/get_started/new_project.md +++ b/docs/source/get_started/new_project.md @@ -116,7 +116,7 @@ kedro new --name=testproject --tools=lint,docs,pyspark --example=n The `--telemetry` flag offers the option to register consent to have user analytics collected in the moment of the creation of the project. This option bypasses the prompt to collect analytics that would otherwise appear on the moment the `kedro` command is invoked for the first time inside the project. In case the `--telemetry` flag is not used, the user will be prompted to accept or reject analytics collection as usual. -When creating your new Kedro project, use the values `yes` or `no` to register consent to have user analytics collected for this specific project. +When creating your new Kedro project, use the values `yes` or `no` to register consent to have user analytics collected for this specific project. ## Run the new project From f8254d0c9243d65a49462b22000c7e16e11aa297 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Wed, 13 Mar 2024 10:24:00 -0300 Subject: [PATCH 08/11] Remove outdated comment and correct type hint Signed-off-by: lrcouto --- kedro/framework/cli/starters.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kedro/framework/cli/starters.py b/kedro/framework/cli/starters.py index 27335cd5c2..5a4b76a347 100644 --- a/kedro/framework/cli/starters.py +++ b/kedro/framework/cli/starters.py @@ -274,8 +274,8 @@ def new( # noqa: PLR0913 project_name: str, checkout: str, directory: str, - example_pipeline: str, # This will be True or False - telemetry_consent: str, # This will be True or False + example_pipeline: str, + telemetry_consent: str, **kwargs: Any, ) -> None: """Create a new kedro project.""" @@ -891,7 +891,7 @@ def _validate_range(start: Any, end: Any) -> None: def _create_project( - template_path: str, cookiecutter_args: dict[str, Any], telemetry_consent: str + template_path: str, cookiecutter_args: dict[str, Any], telemetry_consent: str | None ) -> None: """Creates a new kedro project using cookiecutter. From 650f37c7e4efa3aaeede1441c451ad6985249148 Mon Sep 17 00:00:00 2001 From: "L. R. Couto" <57910428+lrcouto@users.noreply.github.com> Date: Thu, 14 Mar 2024 10:28:15 -0300 Subject: [PATCH 09/11] Update docs/source/get_started/new_project.md Co-authored-by: Merel Theisen <49397448+merelcht@users.noreply.github.com> Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com> --- docs/source/get_started/new_project.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/get_started/new_project.md b/docs/source/get_started/new_project.md index 0dd808c04c..0342af881d 100644 --- a/docs/source/get_started/new_project.md +++ b/docs/source/get_started/new_project.md @@ -116,7 +116,7 @@ kedro new --name=testproject --tools=lint,docs,pyspark --example=n The `--telemetry` flag offers the option to register consent to have user analytics collected in the moment of the creation of the project. This option bypasses the prompt to collect analytics that would otherwise appear on the moment the `kedro` command is invoked for the first time inside the project. In case the `--telemetry` flag is not used, the user will be prompted to accept or reject analytics collection as usual. -When creating your new Kedro project, use the values `yes` or `no` to register consent to have user analytics collected for this specific project. +When creating your new Kedro project, use the values `yes` or `no` to register consent to have user analytics collected for this specific project. Selecting `yes` means you consent to your data being collected, whereas `no` means you do not consent and no data will be collected. ## Run the new project From 19ac1e74212e3bd80c640f8d2f0a3c420a2b45db Mon Sep 17 00:00:00 2001 From: lrcouto Date: Thu, 14 Mar 2024 10:38:27 -0300 Subject: [PATCH 10/11] Lint Signed-off-by: lrcouto --- docs/source/get_started/new_project.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/get_started/new_project.md b/docs/source/get_started/new_project.md index 0342af881d..85f15cbdcd 100644 --- a/docs/source/get_started/new_project.md +++ b/docs/source/get_started/new_project.md @@ -116,7 +116,7 @@ kedro new --name=testproject --tools=lint,docs,pyspark --example=n The `--telemetry` flag offers the option to register consent to have user analytics collected in the moment of the creation of the project. This option bypasses the prompt to collect analytics that would otherwise appear on the moment the `kedro` command is invoked for the first time inside the project. In case the `--telemetry` flag is not used, the user will be prompted to accept or reject analytics collection as usual. -When creating your new Kedro project, use the values `yes` or `no` to register consent to have user analytics collected for this specific project. Selecting `yes` means you consent to your data being collected, whereas `no` means you do not consent and no data will be collected. +When creating your new Kedro project, use the values `yes` or `no` to register consent to have user analytics collected for this specific project. Selecting `yes` means you consent to your data being collected, whereas `no` means you do not consent and no data will be collected. ## Run the new project From 329b05f7151739b571894f38c877791d7ce1ff95 Mon Sep 17 00:00:00 2001 From: lrcouto Date: Sat, 16 Mar 2024 18:18:49 -0300 Subject: [PATCH 11/11] Minor change on release note Signed-off-by: lrcouto --- RELEASE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE.md b/RELEASE.md index 27652de328..98e139afe6 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -4,7 +4,7 @@ * 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` -* Adds the `--telemetry` flag to `kedro new`, allowing the user to register consent to have user analytics collected as the project is created. +* Adds the `--telemetry` flag to `kedro new`, allowing the user to register consent to have user analytics collected at the same time as the project is created. ## Bug fixes and other changes * Updated `kedro pipeline create` and `kedro pipeline delete` to read the base environment from the project settings.