From 5e640b7d34bdf52e610180061cea5c75cd255a1f Mon Sep 17 00:00:00 2001 From: Matthias Zepper Date: Fri, 3 May 2024 18:59:19 +0200 Subject: [PATCH] Update --additional-tag to --tag. --- CHANGELOG.md | 2 +- README.md | 2 +- nf_core/__main__.py | 11 +++++------ nf_core/download.py | 19 +++++++++++-------- tests/test_cli.py | 4 ++-- tests/test_download.py | 37 ++++++++++++++++++++----------------- 6 files changed, 40 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad441df63..bace79a53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ - Replace `--tower` with `--platform`. The former will remain for backwards compatability for now but will be removed in a future release. ([#2853](https://github.com/nf-core/tools/pull/2853)) - Better error message when GITHUB_TOKEN exists but is wrong/outdated -- New `-a` / `--additional-tag` argument to add custom tags during a pipeline download ([#2938](https://github.com/nf-core/tools/pull/2938)) +- New `--tag` argument to add custom tags during a pipeline download ([#2938](https://github.com/nf-core/tools/pull/2938)) ### Components diff --git a/README.md b/README.md index b63514b44..fa909804c 100644 --- a/README.md +++ b/README.md @@ -437,7 +437,7 @@ Subsequently, the `*.git` folder can be moved to it's final destination and link > [!TIP] > Also without access to Seqera Platform, pipelines downloaded with the `--platform` flag can be run if the _absolute_ path is specified: `nextflow run -r 2.5 file:/path/to/pipelinedownload.git`. Downloads in this format allow you to include multiple revisions of a pipeline in a single file, but require that the revision (e.g. `-r 2.5`) is always explicitly specified. -Facilities and those who are setting up pipelines for others to use may find the `-a` / `--additional-tag` argument helpful. It must be followed by a string in a `key=value` format and can be provided multiple times. The `key` must refer to a valid branch, tag or commit SHA. The right-hand side must comply with the naming conventions for Git tags and may not yet exist in the repository. The `-a` / `--additional-tag` argument allows customizing the downloaded pipeline with additional tags that can be used to select particular revisions in the Seqera Platform interface. For example, an accredited facility may opt to tag particular revisions according to their structured release management process: `-a "3.12.0=testing" -a "3.9.0=validated"` so their staff can easily ensure that the correct version of the pipeline is run in production. +Facilities and those who are setting up pipelines for others to use may find the `--tag` argument helpful. It must be followed by a string in a `key=value` format and can be provided multiple times. The `key` must refer to a valid branch, tag or commit SHA. The right-hand side must comply with the naming conventions for Git tags and may not yet exist in the repository. The `--tag` argument allows customizing the downloaded pipeline with additional tags that can be used to select particular revisions in the Seqera Platform interface. For example, an accredited facility may opt to tag particular revisions according to their structured release management process: `--tag "3.12.0=testing" --tag "3.9.0=validated"` so their staff can easily ensure that the correct version of the pipeline is run in production. ## Pipeline software licences diff --git a/nf_core/__main__.py b/nf_core/__main__.py index f3212200d..ead74aa67 100644 --- a/nf_core/__main__.py +++ b/nf_core/__main__.py @@ -368,6 +368,7 @@ def create_params_file(pipeline, revision, output, force, show_hidden): @click.option("-f", "--force", is_flag=True, default=False, help="Overwrite existing files") # TODO: Remove this in a future release. Deprecated in March 2024. @click.option( + "-t", "--tower", is_flag=True, default=False, @@ -375,7 +376,6 @@ def create_params_file(pipeline, revision, output, force, show_hidden): help="Download for Seqera Platform. DEPRECATED: Please use `--platform` instead.", ) @click.option( - "-t", "--platform", is_flag=True, default=False, @@ -389,10 +389,9 @@ def create_params_file(pipeline, revision, output, force, show_hidden): help="Include configuration profiles in download. Not available with `--platform`", ) @click.option( - "-a", - "--additional-tags", + "--tag", multiple=True, - help="Add custom alias tags to `--platform` downloads. For example, '-a \"3.10=validated\"' adds the custom 'validated' tag to the 3.10 release.", + help="Add custom alias tags to `--platform` downloads. For example, `--tag \"3.10=validated\"` adds the custom 'validated' tag to the 3.10 release.", ) # -c changed to -s for consistency with other --container arguments, where it is always the first letter of the last word. # Also -c might be used instead of -d for config in a later release, but reusing params for different options in two subsequent releases might be too error-prone. @@ -436,7 +435,7 @@ def download( tower, platform, download_configuration, - additional_tags, + tag, container_system, container_library, container_cache_utilisation, @@ -459,7 +458,7 @@ def download( force, tower or platform, # True if either specified download_configuration, - additional_tags, + tag, container_system, container_library, container_cache_utilisation, diff --git a/nf_core/download.py b/nf_core/download.py index 26e48958f..5edba513f 100644 --- a/nf_core/download.py +++ b/nf_core/download.py @@ -94,7 +94,7 @@ class DownloadWorkflow: force (bool): Flag to force download even if files already exist (overwrite existing files). Defaults to False. platform (bool): Flag to customize the download for Seqera Platform (convert to git bare repo). Defaults to False. download_configuration (str): Download the configuration files from nf-core/configs. Defaults to None. - additional_tags (List[str]): Specify additional tags to add to the downloaded pipeline. Defaults to None. + tag (List[str]): Specify additional tags to add to the downloaded pipeline. Defaults to None. container_system (str): The container system to use (e.g., "singularity"). Defaults to None. container_library (List[str]): The container libraries (registries) to use. Defaults to None. container_cache_utilisation (str): If a local or remote cache of already existing container images should be considered. Defaults to None. @@ -1736,19 +1736,22 @@ def __add_additional_tags(self) -> None: if self.repo.is_valid_object(anchor) and not self.repo.is_valid_object(tag): try: self.repo.create_tag( - tag, ref=anchor, message=f"Synonynmous tag to {anchor}; added by 'nf-core download'." + tag, ref=anchor, message=f"Synonynmous tag to {anchor}; added by `nf-core download`." ) self.repo.create_head(tag, anchor) # should heads be created as well? except (GitCommandError, InvalidGitRepositoryError) as e: log.error(f"[red]Additional tag(s) could not be applied:[/]\n{e}\n") else: - log.error( - f"[red]Adding the additional tag '{tag}' to '{anchor}' failed.[/]\n Mind that '{anchor}' must be a valid git reference that resolves to a commit, while '{tag}' must not exist hitherto." - ) + if not self.repo.is_valid_object(anchor): + log.error( + f"[red]Adding tag '{tag}' to '{anchor}' failed.[/]\n Mind that '{anchor}' must be a valid git reference that resolves to a commit." + ) + if self.repo.is_valid_object(tag): + log.error( + f"[red]Adding tag '{tag}' to '{anchor}' failed.[/]\n Mind that '{tag}' must not exist hitherto." + ) else: - log.error( - f"[red]Could not apply invalid '-a' / '--additional-tag' specification[/]: '{additional_tag}'" - ) + log.error(f"[red]Could not apply invalid `--tag` specification[/]: '{additional_tag}'") def bare_clone(self, destination): if self.repo: diff --git a/tests/test_cli.py b/tests/test_cli.py index 826008f03..5df0a3241 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -168,7 +168,7 @@ def test_cli_download(self, mock_dl): "force": None, "platform": None, "download-configuration": None, - "additional-tags": "3.12=testing", + "tag": "3.12=testing", "container-system": "singularity", "container-library": "quay.io", "container-cache-utilisation": "copy", @@ -189,7 +189,7 @@ def test_cli_download(self, mock_dl): "force" in params, "platform" in params, "download-configuration" in params, - (params["additional-tags"],), + (params["tag"],), params["container-system"], (params["container-library"],), params["container-cache-utilisation"], diff --git a/tests/test_download.py b/tests/test_download.py index 589fe6eda..3e0f11d57 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -645,7 +645,23 @@ def test_download_workflow_for_platform(self, tmp_dir, _): ) # indirect definition via $container variable. # - # Test adding custom tags to Seqera Platform download + # Brief test adding a single custom tag to Seqera Platform download + # + @mock.patch("nf_core.download.DownloadWorkflow.get_singularity_images") + @with_temporary_folder + def test_download_workflow_for_platform_with_one_custom_tag(self, _, tmp_dir): + download_obj = DownloadWorkflow( + pipeline="nf-core/rnaseq", + revision=("3.9"), + compress_type="none", + platform=True, + container_system=None, + additional_tags=("3.9=cool_revision",), + ) + assert isinstance(download_obj.additional_tags, list) and len(download_obj.additional_tags) == 1 + + # + # Test adding custom tags to Seqera Platform download (full test) # @mock.patch("nf_core.download.DownloadWorkflow.get_singularity_images") @with_temporary_folder @@ -707,21 +723,8 @@ def test_download_workflow_for_platform_with_custom_tags(self, _, tmp_dir): assert all( log in self.logged_messages for log in { - "[red]Could not apply invalid '-a' / '--additional-tag' specification[/]: '3.9=invalid tag'", - "[red]Adding the additional tag 'not_included' to '3.14.0' failed.[/]\n Mind that '3.14.0' must be a valid git reference that resolves to a commit, while 'not_included' must not exist hitherto.", - "[red]Could not apply invalid '-a' / '--additional-tag' specification[/]: 'What is this?'", + "[red]Could not apply invalid `--tag` specification[/]: '3.9=invalid tag'", + "[red]Adding tag 'not_included' to '3.14.0' failed.[/]\n Mind that '3.14.0' must be a valid git reference that resolves to a commit.", + "[red]Could not apply invalid `--tag` specification[/]: 'What is this?'", } ) - - @mock.patch("nf_core.download.DownloadWorkflow.get_singularity_images") - @with_temporary_folder - def test_download_workflow_for_platform_with_one_custom_tag(self, _, tmp_dir): - download_obj = DownloadWorkflow( - pipeline="nf-core/rnaseq", - revision=("3.9"), - compress_type="none", - platform=True, - container_system=None, - additional_tags=("3.9=cool_revision",), - ) - assert isinstance(download_obj.additional_tags, list) and len(download_obj.additional_tags) == 1