From edb2245655e77d13063fc7d1005b995deb9d3e53 Mon Sep 17 00:00:00 2001 From: Erik Danielsson Date: Mon, 2 Aug 2021 10:38:36 +0200 Subject: [PATCH 1/2] Added new flag and prompt for specifying conda package version --- nf_core/__main__.py | 7 +++++-- nf_core/modules/create.py | 21 +++++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/nf_core/__main__.py b/nf_core/__main__.py index 483d709780..2338cbc806 100755 --- a/nf_core/__main__.py +++ b/nf_core/__main__.py @@ -493,7 +493,8 @@ def remove(ctx, dir, tool): @click.option("-n", "--no-meta", is_flag=True, default=False, help="Don't use meta map for sample information") @click.option("-f", "--force", is_flag=True, default=False, help="Overwrite any files if they already exist") @click.option("-c", "--conda-name", type=str, default=None, help="Name of the conda package to use") -def create_module(ctx, tool, dir, author, label, meta, no_meta, force, conda_name): +@click.option("-p", "--conda-package-version", type=str, default=None, help="Version of conda package to use") +def create_module(ctx, tool, dir, author, label, meta, no_meta, force, conda_name, conda_package_version): """ Create a new DSL2 module from the nf-core template. @@ -514,7 +515,9 @@ def create_module(ctx, tool, dir, author, label, meta, no_meta, force, conda_nam # Run function try: - module_create = nf_core.modules.ModuleCreate(dir, tool, author, label, has_meta, force, conda_name) + module_create = nf_core.modules.ModuleCreate( + dir, tool, author, label, has_meta, force, conda_name, conda_package_version + ) module_create.create() except UserWarning as e: log.critical(e) diff --git a/nf_core/modules/create.py b/nf_core/modules/create.py index 8473f64b8d..60a11f90ac 100644 --- a/nf_core/modules/create.py +++ b/nf_core/modules/create.py @@ -25,7 +25,15 @@ class ModuleCreate(object): def __init__( - self, directory=".", tool="", author=None, process_label=None, has_meta=None, force=False, conda_name=None + self, + directory=".", + tool="", + author=None, + process_label=None, + has_meta=None, + force=False, + conda_name=None, + conda_version=None, ): self.directory = directory self.tool = tool @@ -35,6 +43,7 @@ def __init__( self.force_overwrite = force self.subtool = None self.tool_conda_name = conda_name + self.tool_conda_version = conda_version self.tool_licence = None self.repo_type = None self.tool_licence = "" @@ -131,9 +140,13 @@ def create(self): anaconda_response = nf_core.utils.anaconda_package(self.tool_conda_name, ["bioconda"]) else: anaconda_response = nf_core.utils.anaconda_package(self.tool, ["bioconda"]) - version = anaconda_response.get("latest_version") - if not version: - version = str(max([parse_version(v) for v in anaconda_response["versions"]])) + if not self.tool_conda_version: + version = questionary.select( + "Select bioconda version:", + choices=[str(parse_version(v)) for v in anaconda_response["versions"]], + ).unsafe_ask() + else: + version = self.tool_conda_version self.tool_licence = nf_core.utils.parse_anaconda_licence(anaconda_response, version) self.tool_description = anaconda_response.get("summary", "") self.tool_doc_url = anaconda_response.get("doc_url", "") From 658dce5ace4caecbf4273e21295e7dacf409e509 Mon Sep 17 00:00:00 2001 From: Erik Danielsson Date: Mon, 2 Aug 2021 10:49:01 +0200 Subject: [PATCH 2/2] Update changelog and remove prompt --- CHANGELOG.md | 1 + nf_core/modules/create.py | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9f518293f..d2abc015ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Modules * Fixed typo in `module_utils.py`. +* Added `--conda-package-version` flag for specifying version of conda package in `nf-core modules create`. ([#1238](https://github.com/nf-core/tools/issues/1238)) ## [v2.1 - Zinc Zebra](https://github.com/nf-core/tools/releases/tag/2.1) - [2021-07-27] diff --git a/nf_core/modules/create.py b/nf_core/modules/create.py index 60a11f90ac..6fa3e74bbc 100644 --- a/nf_core/modules/create.py +++ b/nf_core/modules/create.py @@ -140,13 +140,14 @@ def create(self): anaconda_response = nf_core.utils.anaconda_package(self.tool_conda_name, ["bioconda"]) else: anaconda_response = nf_core.utils.anaconda_package(self.tool, ["bioconda"]) + if not self.tool_conda_version: - version = questionary.select( - "Select bioconda version:", - choices=[str(parse_version(v)) for v in anaconda_response["versions"]], - ).unsafe_ask() + version = anaconda_response.get("latest_version") + if not version: + version = str(max([parse_version(v) for v in anaconda_response["versions"]])) else: version = self.tool_conda_version + self.tool_licence = nf_core.utils.parse_anaconda_licence(anaconda_response, version) self.tool_description = anaconda_response.get("summary", "") self.tool_doc_url = anaconda_response.get("doc_url", "")