From 81fceff46f58c2875e25a2f3c876f2cef0b77ea4 Mon Sep 17 00:00:00 2001 From: Renaud <38732257+renaudjester@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:29:50 +0100 Subject: [PATCH] feat: force download has no effect but does not raise (#253) force download for v2 will be deprecated to help user transitioning, it won't have any effect but it won't raise if the argument is passed --- .../command_line_interface/group_get.py | 3 ++ .../command_line_interface/group_subset.py | 3 ++ .../command_line_interface/utils.py | 12 +++++ .../core_functions/deprecated_options.py | 6 +++ tests/test_deprecated_options.py | 48 ++++++++++++++++++- 5 files changed, 71 insertions(+), 1 deletion(-) diff --git a/copernicusmarine/command_line_interface/group_get.py b/copernicusmarine/command_line_interface/group_get.py index 0a5bfe92..39c6222d 100644 --- a/copernicusmarine/command_line_interface/group_get.py +++ b/copernicusmarine/command_line_interface/group_get.py @@ -13,6 +13,7 @@ credentials_file_option, force_dataset_part_option, force_dataset_version_option, + force_download_option, tqdm_disable_option, ) from copernicusmarine.core_functions import documentation_utils @@ -208,6 +209,7 @@ def cli_get() -> None: is_flag=True, hidden=True, ) +@force_download_option @log_exception_and_exit def get( dataset_id: Optional[str], @@ -235,6 +237,7 @@ def get( disable_progress_bar: bool, log_level: str, staging: bool, + force_download: bool, ): if log_level == "QUIET": logger.disabled = True diff --git a/copernicusmarine/command_line_interface/group_subset.py b/copernicusmarine/command_line_interface/group_subset.py index d0f98a26..2d130e4d 100644 --- a/copernicusmarine/command_line_interface/group_subset.py +++ b/copernicusmarine/command_line_interface/group_subset.py @@ -13,6 +13,7 @@ credentials_file_option, force_dataset_part_option, force_dataset_version_option, + force_download_option, tqdm_disable_option, ) from copernicusmarine.core_functions import documentation_utils @@ -285,6 +286,7 @@ def cli_subset() -> None: default="INFO", help=documentation_utils.SUBSET["LOG_LEVEL_HELP"], ) +@force_download_option @log_exception_and_exit def subset( dataset_id: str, @@ -321,6 +323,7 @@ def subset( log_level: str, chunk_size_limit: int, staging: bool, + force_download: bool, ): if log_level == "QUIET": logger.disabled = True diff --git a/copernicusmarine/command_line_interface/utils.py b/copernicusmarine/command_line_interface/utils.py index 54949afc..709d77f8 100644 --- a/copernicusmarine/command_line_interface/utils.py +++ b/copernicusmarine/command_line_interface/utils.py @@ -5,6 +5,9 @@ from click.core import ParameterSource from copernicusmarine.core_functions import documentation_utils +from copernicusmarine.core_functions.click_custom_class import ( + DeprecatedClickOption, +) class MutuallyExclusiveOption(Option): @@ -88,3 +91,12 @@ def assert_cli_args_are_not_set_except_create_template( type=click.Path(path_type=pathlib.Path), help=documentation_utils.SHARED["CREDENTIALS_FILE_HELP"], ) + +force_download_option = click.option( + "--force-download", + is_flag=True, + default=False, + hidden=True, + cls=DeprecatedClickOption, + deprecated=["--force-download"], +) diff --git a/copernicusmarine/core_functions/deprecated_options.py b/copernicusmarine/core_functions/deprecated_options.py index 95727b32..37330dd0 100644 --- a/copernicusmarine/core_functions/deprecated_options.py +++ b/copernicusmarine/core_functions/deprecated_options.py @@ -40,6 +40,12 @@ def __len__(self) -> int: new_name="motu_api_request", replace=False, ), + DeprecatedOption( + old_name="force_download", + new_name="force_download", + replace=False, + do_not_pass=True, + ), ] ) diff --git a/tests/test_deprecated_options.py b/tests/test_deprecated_options.py index be78ca2b..32d1df94 100644 --- a/tests/test_deprecated_options.py +++ b/tests/test_deprecated_options.py @@ -1,4 +1,4 @@ -from copernicusmarine import subset +from copernicusmarine import get, subset from tests.test_utils import execute_in_terminal @@ -23,3 +23,49 @@ def test_motu_api_request_deprecated_api(self, caplog): except Exception: pass assert "'motu_api_request' has been deprecated." in caplog.text + + def test_force_download_deprecated_subset(self): + command = [ + "copernicusmarine", + "subset", + "--force-download", + "-i", + "cmems_mod_glo_phy-cur_anfc_0.083deg_P1M-m", + "--dry-run", + "-t", + "2001", + ] + self.output = execute_in_terminal(command) + assert self.output.returncode == 0 + assert b"'--force-download' has been deprecated." in self.output.stderr + + def test_force_download_deprecated_get(self): + command = [ + "copernicusmarine", + "get", + "--force-download", + "-i", + "cmems_mod_glo_phy-cur_anfc_0.083deg_P1M-m", + "--dry-run", + ] + self.output = execute_in_terminal(command) + assert self.output.returncode == 0 + assert b"'--force-download' has been deprecated." in self.output.stderr + + def test_force_download_deprecated_subset_python_interface(self, caplog): + subset( + dataset_id="cmems_mod_glo_phy-cur_anfc_0.083deg_P1M-m", + start_datetime="2001", + dry_run=True, + force_download=True, + ) + assert "'force_download' has been deprecated." in caplog.text + + def test_force_download_deprecated_get_python_interface(self, caplog): + get( + dataset_id="cmems_mod_glo_phy-cur_anfc_0.083deg_P1M-m", + dry_run=True, + force_download=False, + ) + + assert "'force_download' has been deprecated." in caplog.text