From bccb6137fe63ea29dcc05fe72b0d25a43be35eb7 Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Mon, 1 Jul 2024 15:46:39 +0100 Subject: [PATCH 01/10] Removed consent confirmation Signed-off-by: Elena Khaustova --- kedro-telemetry/kedro_telemetry/plugin.py | 47 +++++------------------ 1 file changed, 10 insertions(+), 37 deletions(-) diff --git a/kedro-telemetry/kedro_telemetry/plugin.py b/kedro-telemetry/kedro_telemetry/plugin.py index f0b2485ee..3a0f8db98 100644 --- a/kedro-telemetry/kedro_telemetry/plugin.py +++ b/kedro-telemetry/kedro_telemetry/plugin.py @@ -347,14 +347,17 @@ def _send_heap_event( def _check_for_telemetry_consent(project_path: Path) -> bool: + """ + Use a telemetry consent from ".telemetry" file if it exists and has a valid format. + Telemetry is considered as opt-in otherwise. + """ telemetry_file_path = project_path / ".telemetry" - if not telemetry_file_path.exists(): - return _confirm_consent(telemetry_file_path) - with open(telemetry_file_path, encoding="utf-8") as telemetry_file: - telemetry = yaml.safe_load(telemetry_file) - if _is_valid_syntax(telemetry): - return telemetry["consent"] - return _confirm_consent(telemetry_file_path) + if telemetry_file_path.exists(): + with open(telemetry_file_path, encoding="utf-8") as telemetry_file: + telemetry = yaml.safe_load(telemetry_file) + if _is_valid_syntax(telemetry): + return telemetry["consent"] + return True def _is_valid_syntax(telemetry: Any) -> bool: @@ -363,35 +366,5 @@ def _is_valid_syntax(telemetry: Any) -> bool: ) -def _confirm_consent(telemetry_file_path: Path) -> bool: - try: - with telemetry_file_path.open("w") as telemetry_file: - confirm_msg = ( - "As an open-source project, we collect usage analytics. \n" - "We cannot see nor store information contained in " - "a Kedro project. \nYou can find out more by reading our " - "privacy notice: \n" - "https://github.com/kedro-org/kedro-plugins/tree/main/kedro-telemetry#" - "privacy-notice \n" - "Do you opt into usage analytics? " - ) - if click.confirm(confirm_msg): - yaml.dump({"consent": True}, telemetry_file) - click.secho("You have opted into product usage analytics.", fg="green") - return True - click.secho( - "You have opted out of product usage analytics, so none will be collected.", - fg="green", - ) - yaml.dump({"consent": False}, telemetry_file) - return False - except Exception as exc: - logger.warning( - "Failed to confirm consent. No data was sent to Heap. Exception: %s", - exc, - ) - return False - - cli_hooks = KedroTelemetryCLIHooks() project_hooks = KedroTelemetryProjectHooks() From b3a01ade6ad3442c1fadcb3c19a8b5291072650d Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Mon, 1 Jul 2024 15:47:05 +0100 Subject: [PATCH 02/10] Updated tests Signed-off-by: Elena Khaustova --- kedro-telemetry/tests/test_plugin.py | 45 ++-------------------------- 1 file changed, 3 insertions(+), 42 deletions(-) diff --git a/kedro-telemetry/tests/test_plugin.py b/kedro-telemetry/tests/test_plugin.py index 7348d63f4..f43718b70 100644 --- a/kedro-telemetry/tests/test_plugin.py +++ b/kedro-telemetry/tests/test_plugin.py @@ -17,7 +17,6 @@ KedroTelemetryCLIHooks, KedroTelemetryProjectHooks, _check_for_telemetry_consent, - _confirm_consent, _is_known_ci_env, ) @@ -371,8 +370,6 @@ def test_check_for_telemetry_consent_given(self, mocker, fake_metadata): with open(telemetry_file_path, "w", encoding="utf-8") as telemetry_file: yaml.dump({"consent": True}, telemetry_file) - mock_create_file = mocker.patch("kedro_telemetry.plugin._confirm_consent") - mock_create_file.assert_not_called() assert _check_for_telemetry_consent(fake_metadata.project_path) def test_check_for_telemetry_consent_not_given(self, mocker, fake_metadata): @@ -381,29 +378,16 @@ def test_check_for_telemetry_consent_not_given(self, mocker, fake_metadata): with open(telemetry_file_path, "w", encoding="utf-8") as telemetry_file: yaml.dump({"consent": False}, telemetry_file) - mock_create_file = mocker.patch("kedro_telemetry.plugin._confirm_consent") - mock_create_file.assert_not_called() assert not _check_for_telemetry_consent(fake_metadata.project_path) def test_check_for_telemetry_consent_empty_file(self, mocker, fake_metadata): Path(fake_metadata.project_path, "conf").mkdir(parents=True) telemetry_file_path = fake_metadata.project_path / ".telemetry" - mock_create_file = mocker.patch( - "kedro_telemetry.plugin._confirm_consent", return_value=True - ) - - assert _check_for_telemetry_consent(fake_metadata.project_path) - mock_create_file.assert_called_once_with(telemetry_file_path) - def test_check_for_telemetry_no_consent_empty_file(self, mocker, fake_metadata): - Path(fake_metadata.project_path, "conf").mkdir(parents=True) - telemetry_file_path = fake_metadata.project_path / ".telemetry" - mock_create_file = mocker.patch( - "kedro_telemetry.plugin._confirm_consent", return_value=False - ) + with open(telemetry_file_path, "w", encoding="utf-8") as telemetry_file: + yaml.dump({}, telemetry_file) - assert not _check_for_telemetry_consent(fake_metadata.project_path) - mock_create_file.assert_called_once_with(telemetry_file_path) + assert _check_for_telemetry_consent(fake_metadata.project_path) def test_check_for_telemetry_consent_file_no_consent_field( self, mocker, fake_metadata @@ -413,37 +397,14 @@ def test_check_for_telemetry_consent_file_no_consent_field( with open(telemetry_file_path, "w", encoding="utf8") as telemetry_file: yaml.dump({"nonsense": "bla"}, telemetry_file) - mock_create_file = mocker.patch( - "kedro_telemetry.plugin._confirm_consent", return_value=True - ) - assert _check_for_telemetry_consent(fake_metadata.project_path) - mock_create_file.assert_called_once_with(telemetry_file_path) def test_check_for_telemetry_consent_file_invalid_yaml(self, mocker, fake_metadata): Path(fake_metadata.project_path, "conf").mkdir(parents=True) telemetry_file_path = fake_metadata.project_path / ".telemetry" telemetry_file_path.write_text("invalid_ yaml") - mock_create_file = mocker.patch( - "kedro_telemetry.plugin._confirm_consent", return_value=True - ) - assert _check_for_telemetry_consent(fake_metadata.project_path) - mock_create_file.assert_called_once_with(telemetry_file_path) - - def test_confirm_consent_yaml_dump_error(self, mocker, fake_metadata, caplog): - Path(fake_metadata.project_path, "conf").mkdir(parents=True) - telemetry_file_path = fake_metadata.project_path / ".telemetry" - mocker.patch("yaml.dump", side_efyfect=Exception) - - assert not _confirm_consent(telemetry_file_path) - - msg = ( - "Failed to confirm consent. No data was sent to Heap. Exception: " - "pytest: reading from stdin while output is captured! Consider using `-s`." - ) - assert msg in caplog.messages[-1] @mark.parametrize( "env_vars,result", From abfcdb159ac0c0a054d6cabbd4def1b39c1dee43 Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Mon, 1 Jul 2024 15:59:35 +0100 Subject: [PATCH 03/10] Fixed ruff Signed-off-by: Elena Khaustova --- kedro-telemetry/kedro_telemetry/plugin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/kedro-telemetry/kedro_telemetry/plugin.py b/kedro-telemetry/kedro_telemetry/plugin.py index 3a0f8db98..152797d62 100644 --- a/kedro-telemetry/kedro_telemetry/plugin.py +++ b/kedro-telemetry/kedro_telemetry/plugin.py @@ -13,7 +13,6 @@ from pathlib import Path from typing import Any -import click import requests import toml import yaml From 425abf07531470ce168a0810f55d6d8a20346d2d Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Thu, 4 Jul 2024 13:54:32 +0100 Subject: [PATCH 04/10] Fixed docstring Signed-off-by: Elena Khaustova --- kedro-telemetry/kedro_telemetry/plugin.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kedro-telemetry/kedro_telemetry/plugin.py b/kedro-telemetry/kedro_telemetry/plugin.py index 152797d62..0580aaaad 100644 --- a/kedro-telemetry/kedro_telemetry/plugin.py +++ b/kedro-telemetry/kedro_telemetry/plugin.py @@ -338,6 +338,9 @@ def _send_heap_event( resp.status_code, resp.reason, ) + + print(resp.status_code, resp.reason) + print(data) except requests.exceptions.RequestException as exc: logger.warning( "Failed to send data to Heap. Exception of type '%s' was raised.", @@ -347,7 +350,7 @@ def _send_heap_event( def _check_for_telemetry_consent(project_path: Path) -> bool: """ - Use a telemetry consent from ".telemetry" file if it exists and has a valid format. + Use telemetry consent from ".telemetry" file if it exists and has a valid format. Telemetry is considered as opt-in otherwise. """ telemetry_file_path = project_path / ".telemetry" From e60cd2b1f5b1cdd6fe453379f1fa179f3985c22a Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Thu, 4 Jul 2024 13:56:31 +0100 Subject: [PATCH 05/10] Removed debug output Signed-off-by: Elena Khaustova --- kedro-telemetry/kedro_telemetry/plugin.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/kedro-telemetry/kedro_telemetry/plugin.py b/kedro-telemetry/kedro_telemetry/plugin.py index 0580aaaad..c903411fd 100644 --- a/kedro-telemetry/kedro_telemetry/plugin.py +++ b/kedro-telemetry/kedro_telemetry/plugin.py @@ -338,9 +338,6 @@ def _send_heap_event( resp.status_code, resp.reason, ) - - print(resp.status_code, resp.reason) - print(data) except requests.exceptions.RequestException as exc: logger.warning( "Failed to send data to Heap. Exception of type '%s' was raised.", From 1fbda46d0cd7878198eb0d097338a8fcacde086d Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Thu, 4 Jul 2024 15:40:14 +0100 Subject: [PATCH 06/10] Dummy commit Signed-off-by: Elena Khaustova --- kedro-telemetry/kedro_telemetry/plugin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/kedro-telemetry/kedro_telemetry/plugin.py b/kedro-telemetry/kedro_telemetry/plugin.py index c903411fd..a73b71356 100644 --- a/kedro-telemetry/kedro_telemetry/plugin.py +++ b/kedro-telemetry/kedro_telemetry/plugin.py @@ -349,6 +349,7 @@ def _check_for_telemetry_consent(project_path: Path) -> bool: """ Use telemetry consent from ".telemetry" file if it exists and has a valid format. Telemetry is considered as opt-in otherwise. + """ telemetry_file_path = project_path / ".telemetry" if telemetry_file_path.exists(): From 070b165be62dcebb0844bc3b4ef51df8d5b6e0dd Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Thu, 4 Jul 2024 15:41:35 +0100 Subject: [PATCH 07/10] Dummy commit Signed-off-by: Elena Khaustova --- kedro-telemetry/kedro_telemetry/plugin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/kedro-telemetry/kedro_telemetry/plugin.py b/kedro-telemetry/kedro_telemetry/plugin.py index a73b71356..c903411fd 100644 --- a/kedro-telemetry/kedro_telemetry/plugin.py +++ b/kedro-telemetry/kedro_telemetry/plugin.py @@ -349,7 +349,6 @@ def _check_for_telemetry_consent(project_path: Path) -> bool: """ Use telemetry consent from ".telemetry" file if it exists and has a valid format. Telemetry is considered as opt-in otherwise. - """ telemetry_file_path = project_path / ".telemetry" if telemetry_file_path.exists(): From daece61db4de558bfcb99d71fc667c0eec5e7667 Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Thu, 4 Jul 2024 16:32:39 +0100 Subject: [PATCH 08/10] Updated huggingface-hub version Signed-off-by: Elena Khaustova --- kedro-datasets/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kedro-datasets/pyproject.toml b/kedro-datasets/pyproject.toml index d9eede037..21ea2275f 100644 --- a/kedro-datasets/pyproject.toml +++ b/kedro-datasets/pyproject.toml @@ -249,7 +249,7 @@ test = [ "xlsxwriter~=1.0", # huggingface "datasets", - "huggingface_hub", + "huggingface_hub~=0.23.0", "transformers[torch]", # mypy related dependencies "types-cachetools", From ca1aaa0cd378d952f038c88ee6603d236ec4d691 Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Thu, 4 Jul 2024 16:36:44 +0100 Subject: [PATCH 09/10] Updated huggingface-hub version Signed-off-by: Elena Khaustova --- kedro-datasets/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kedro-datasets/pyproject.toml b/kedro-datasets/pyproject.toml index 21ea2275f..8a1a927e6 100644 --- a/kedro-datasets/pyproject.toml +++ b/kedro-datasets/pyproject.toml @@ -249,7 +249,7 @@ test = [ "xlsxwriter~=1.0", # huggingface "datasets", - "huggingface_hub~=0.23.0", + "huggingface_hub~=0.23.4", "transformers[torch]", # mypy related dependencies "types-cachetools", From 56528d421dc8af2e5560335b100bfd2ba3433944 Mon Sep 17 00:00:00 2001 From: Elena Khaustova Date: Thu, 4 Jul 2024 18:55:55 +0100 Subject: [PATCH 10/10] CI fix Signed-off-by: Elena Khaustova --- kedro-datasets/pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kedro-datasets/pyproject.toml b/kedro-datasets/pyproject.toml index 8a1a927e6..38fc6099f 100644 --- a/kedro-datasets/pyproject.toml +++ b/kedro-datasets/pyproject.toml @@ -179,6 +179,7 @@ docs = [ # Test requirements test = [ + "accelerate<0.32", "adlfs~=2023.1", "bandit>=1.6.2, <2.0", "behave==1.2.6", @@ -249,7 +250,7 @@ test = [ "xlsxwriter~=1.0", # huggingface "datasets", - "huggingface_hub~=0.23.4", + "huggingface_hub", "transformers[torch]", # mypy related dependencies "types-cachetools",