From dc9b3fd7fcb8e8e3edb2593582bf50af59b61aa0 Mon Sep 17 00:00:00 2001 From: Erkison Odih Date: Wed, 24 Mar 2021 10:59:59 +0100 Subject: [PATCH 1/2] allow module names with character notations as in conda --- nf_core/modules/create.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/nf_core/modules/create.py b/nf_core/modules/create.py index f9f44ac675..473806f26c 100644 --- a/nf_core/modules/create.py +++ b/nf_core/modules/create.py @@ -32,6 +32,7 @@ def __init__(self, directory=".", tool="", author=None, process_label=None, has_ self.has_meta = has_meta self.force_overwrite = force + self.tool_conda_name = None self.subtool = None self.tool_licence = None self.repo_type = None @@ -89,6 +90,12 @@ def create(self): tool_clean = re.sub(r"[^a-z\d/]", "", self.tool.lower()) if rich.prompt.Confirm.ask(f"[violet]Change '{self.tool}' to '{tool_clean}'?"): self.tool = tool_clean + # Allow characters for use in finding conda package + elif rich.prompt.Confirm.ask( + f"[violet]Does '{self.tool}' have the same capitalizations/punctuations in Bioconda?" + ): + self.tool_conda_name = self.tool + self.tool = tool_clean else: self.tool = "" @@ -118,7 +125,10 @@ def create(self): # Try to find a bioconda package for 'tool' try: - anaconda_response = nf_core.utils.anaconda_package(self.tool, ["bioconda"]) + if self.tool_conda_name: + 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"]])) @@ -126,7 +136,10 @@ def create(self): self.tool_description = anaconda_response.get("summary", "") self.tool_doc_url = anaconda_response.get("doc_url", "") self.tool_dev_url = anaconda_response.get("dev_url", "") - self.bioconda = "bioconda::" + self.tool + "=" + version + if self.tool_conda_name: + self.bioconda = "bioconda::" + self.tool_conda_name + "=" + version + else: + self.bioconda = "bioconda::" + self.tool + "=" + version log.info(f"Using Bioconda package: '{self.bioconda}'") except (ValueError, LookupError) as e: log.warning( @@ -136,7 +149,10 @@ def create(self): # Try to get the container tag (only if bioconda package was found) if self.bioconda: try: - self.container_tag = nf_core.utils.get_biocontainer_tag(self.tool, version) + if self.tool_conda_name: + self.container_tag = nf_core.utils.get_biocontainer_tag(self.tool_conda_name, version) + else: + self.container_tag = nf_core.utils.get_biocontainer_tag(self.tool, version) log.info(f"Using Docker / Singularity container with tag: '{self.container_tag}'") except (ValueError, LookupError) as e: log.info(f"Could not find a container tag ({e})") From 5cd47b0f42c127e6f263519e388ab3966a975fbb Mon Sep 17 00:00:00 2001 From: Erkison Odih Date: Wed, 24 Mar 2021 14:20:53 +0100 Subject: [PATCH 2/2] request different module name on bioconda lookup fail --- nf_core/modules/create.py | 57 ++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/nf_core/modules/create.py b/nf_core/modules/create.py index 473806f26c..4d9aae79cd 100644 --- a/nf_core/modules/create.py +++ b/nf_core/modules/create.py @@ -90,12 +90,6 @@ def create(self): tool_clean = re.sub(r"[^a-z\d/]", "", self.tool.lower()) if rich.prompt.Confirm.ask(f"[violet]Change '{self.tool}' to '{tool_clean}'?"): self.tool = tool_clean - # Allow characters for use in finding conda package - elif rich.prompt.Confirm.ask( - f"[violet]Does '{self.tool}' have the same capitalizations/punctuations in Bioconda?" - ): - self.tool_conda_name = self.tool - self.tool = tool_clean else: self.tool = "" @@ -124,27 +118,36 @@ def create(self): self.file_paths = self.get_module_dirs() # Try to find a bioconda package for 'tool' - try: - if self.tool_conda_name: - 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"]])) - 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", "") - self.tool_dev_url = anaconda_response.get("dev_url", "") - if self.tool_conda_name: - self.bioconda = "bioconda::" + self.tool_conda_name + "=" + version - else: - self.bioconda = "bioconda::" + self.tool + "=" + version - log.info(f"Using Bioconda package: '{self.bioconda}'") - except (ValueError, LookupError) as e: - log.warning( - f"{e}\nBuilding module without tool software and meta, you will need to enter this information manually." - ) + while True: + try: + if self.tool_conda_name: + 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"]])) + 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", "") + self.tool_dev_url = anaconda_response.get("dev_url", "") + if self.tool_conda_name: + self.bioconda = "bioconda::" + self.tool_conda_name + "=" + version + else: + self.bioconda = "bioconda::" + self.tool + "=" + version + log.info(f"Using Bioconda package: '{self.bioconda}'") + break + except (ValueError, LookupError) as e: + if rich.prompt.Confirm.ask( + f"[violet]Could not find Conda dependency using the Anaconda API: '{self.tool}'. Do you want to enter a different bioconda package name?" + ): + self.tool_conda_name = rich.prompt.Prompt.ask("[violet]Name of tool/subtool").strip() + continue + else: + log.warning( + f"{e}\nBuilding module without tool software and meta, you will need to enter this information manually." + ) + break # Try to get the container tag (only if bioconda package was found) if self.bioconda: