From ff4bbb5454b1de6c22784cb182e9da5e49fb1abb Mon Sep 17 00:00:00 2001 From: ElenaKhaustova <157851531+ElenaKhaustova@users.noreply.github.com> Date: Tue, 9 Jul 2024 16:27:01 +0100 Subject: [PATCH] Make `kedro-telemetry` a core dependency (#3976) * Added kedro-telemetry as a core dependency Signed-off-by: Elena Khaustova * Fixed typo Signed-off-by: Elena Khaustova * Keep dependencies in alphabetical order Signed-off-by: Elena Khaustova * Updates TestKedroSession unit tests Signed-off-by: Elena Khaustova * Updated TestCliCommands unit tests Signed-off-by: Elena Khaustova * Updated kedro info command Signed-off-by: Elena Khaustova * Reverted info command changes Signed-off-by: Elena Khaustova * Excluded no plugins installed case from coverage Signed-off-by: Elena Khaustova * Updated kedro-telemetry version Signed-off-by: Elena Khaustova * Updated release notes Signed-off-by: Elena Khaustova --------- Signed-off-by: Elena Khaustova --- RELEASE.md | 2 +- .../requirements.txt | 1 - kedro/framework/cli/cli.py | 2 +- .../requirements.txt | 1 - pyproject.toml | 1 + tests/framework/cli/test_cli.py | 7 +++++-- tests/framework/session/test_session.py | 20 ++++++++++++++++++- 7 files changed, 27 insertions(+), 7 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 04de728c30..8584725fb4 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -7,7 +7,7 @@ * Updated error message for catalog entries when the dataset class is not found with hints on how to resolve the issue. * Fixed a bug in the `DataCatalog` `shallow_copy()` method to ensure it returns the type of the used catalog and doesn't cast it to `DataCatalog`. * Implemented key completion support for accessing datasets in the `DataCatalog`. - +* Made [kedro-telemetry](https://github.com/kedro-org/kedro-plugins/tree/main/kedro-telemetry) a core dependency. ## Breaking changes to the API diff --git a/features/steps/test_starter/{{ cookiecutter.repo_name }}/requirements.txt b/features/steps/test_starter/{{ cookiecutter.repo_name }}/requirements.txt index 826097e88d..8da5d60851 100644 --- a/features/steps/test_starter/{{ cookiecutter.repo_name }}/requirements.txt +++ b/features/steps/test_starter/{{ cookiecutter.repo_name }}/requirements.txt @@ -5,7 +5,6 @@ notebook kedro~={{ cookiecutter.kedro_version}} kedro-datasets[pandas-csvdataset]; python_version >= "3.9" kedro-datasets[pandas.CSVDataset]<2.0.0; python_version < '3.9' -kedro-telemetry>=0.3.1 pytest-cov~=3.0 pytest-mock>=1.7.1, <2.0 pytest~=7.2 diff --git a/kedro/framework/cli/cli.py b/kedro/framework/cli/cli.py index 14a633a6cd..addbbfbf54 100644 --- a/kedro/framework/cli/cli.py +++ b/kedro/framework/cli/cli.py @@ -81,7 +81,7 @@ def info() -> None: click.echo( f"{plugin_name}: {plugin_version} (entry points:{entrypoints_str})" ) - else: + else: # pragma: no cover click.echo("No plugins installed") diff --git a/kedro/templates/project/{{ cookiecutter.repo_name }}/requirements.txt b/kedro/templates/project/{{ cookiecutter.repo_name }}/requirements.txt index 871b096c44..9301f4e3f3 100644 --- a/kedro/templates/project/{{ cookiecutter.repo_name }}/requirements.txt +++ b/kedro/templates/project/{{ cookiecutter.repo_name }}/requirements.txt @@ -2,7 +2,6 @@ ipython>=8.10 jupyterlab>=3.0 notebook kedro~={{ cookiecutter.kedro_version }} -kedro-telemetry>=0.3.1 pytest-cov~=3.0 pytest-mock>=1.7.1, <2.0 pytest~=7.2 diff --git a/pyproject.toml b/pyproject.toml index cb145e5e30..e798d9eab8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,7 @@ dependencies = [ "gitpython>=3.0", "importlib-metadata>=3.6,<9.0", "importlib_resources>=1.3,<7.0", # The `files()` API was introduced in `importlib_resources` 1.3 and Python 3.9. + "kedro-telemetry>=0.5.0", "more_itertools>=8.14.0", "omegaconf>=2.1.1", "parse>=1.19.0", diff --git a/tests/framework/cli/test_cli.py b/tests/framework/cli/test_cli.py index 857e71a859..e1a0e4c9dd 100644 --- a/tests/framework/cli/test_cli.py +++ b/tests/framework/cli/test_cli.py @@ -104,10 +104,13 @@ def test_info_contains_plugin_versions(self, entry_point): entry_point.load.assert_not_called() - def test_info_no_plugins(self): + def test_info_only_kedro_telemetry_plugin_installed(self): result = CliRunner().invoke(cli, ["info"]) assert result.exit_code == 0 - assert "No plugins installed" in result.output + + split_result = result.output.strip().split("\n") + assert "Installed plugins" in split_result[-2] + assert "kedro_telemetry" in split_result[-1] def test_help(self): """Check that `kedro --help` returns a valid help message.""" diff --git a/tests/framework/session/test_session.py b/tests/framework/session/test_session.py index a04deb6b30..02d1bcdaa8 100644 --- a/tests/framework/session/test_session.py +++ b/tests/framework/session/test_session.py @@ -325,6 +325,11 @@ def test_create( expected_store["username"] = fake_username + mocker.patch( + "kedro_telemetry.plugin._check_for_telemetry_consent", + return_value=False, + ) + assert session.store == expected_store assert session.load_context() is mock_context_class.return_value assert isinstance(session._get_config_loader(), OmegaConfigLoader) @@ -362,6 +367,11 @@ def test_create_no_env_extra_params( expected_store["username"] = fake_username + mocker.patch( + "kedro_telemetry.plugin._check_for_telemetry_consent", + return_value=False, + ) + assert session.store == expected_store assert session.load_context() is mock_context_class.return_value assert isinstance(session._get_config_loader(), OmegaConfigLoader) @@ -754,12 +764,16 @@ def test_run_multiple_times( ) @pytest.mark.usefixtures("mock_settings_context_class") - def test_run_non_existent_pipeline(self, fake_project, mock_runner): + def test_run_non_existent_pipeline(self, fake_project, mock_runner, mocker): pattern = ( "Failed to find the pipeline named 'doesnotexist'. " "It needs to be generated and returned " "by the 'register_pipelines' function." ) + mocker.patch( + "kedro_telemetry.plugin._check_for_telemetry_consent", + return_value=False, + ) with pytest.raises(ValueError, match=re.escape(pattern)): with KedroSession.create(fake_project) as session: session.run(runner=mock_runner, pipeline_name="doesnotexist") @@ -922,6 +936,10 @@ def test_session_raise_error_with_invalid_runner_instance( }, ) mock_runner_class = mocker.patch("kedro.runner.SequentialRunner") + mocker.patch( + "kedro_telemetry.plugin._check_for_telemetry_consent", + return_value=False, + ) session = KedroSession.create(fake_project) with pytest.raises(