Skip to content

Commit

Permalink
feat: force download has no effect but does not raise (#253)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
renaudjester authored Dec 13, 2024
1 parent 13f0feb commit 81fceff
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
3 changes: 3 additions & 0 deletions copernicusmarine/command_line_interface/group_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions copernicusmarine/command_line_interface/group_subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions copernicusmarine/command_line_interface/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"],
)
6 changes: 6 additions & 0 deletions copernicusmarine/core_functions/deprecated_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
]
)

Expand Down
48 changes: 47 additions & 1 deletion tests/test_deprecated_options.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from copernicusmarine import subset
from copernicusmarine import get, subset
from tests.test_utils import execute_in_terminal


Expand All @@ -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

0 comments on commit 81fceff

Please sign in to comment.