From 4604e408a91bd3f37f2d3b480d0544e5ec9c18de Mon Sep 17 00:00:00 2001 From: mashehu Date: Thu, 9 Feb 2023 11:57:11 +0100 Subject: [PATCH 1/3] add include statement to info command for installed components fix incorrect handling of locally installed modules --- nf_core/components/info.py | 40 ++++++++++++++++++++++++++++++++++- nf_core/components/install.py | 5 ++--- tests/modules/info.py | 2 +- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/nf_core/components/info.py b/nf_core/components/info.py index b89baaf99e..69b9e19b87 100644 --- a/nf_core/components/info.py +++ b/nf_core/components/info.py @@ -8,6 +8,7 @@ from rich.console import Group from rich.markdown import Markdown from rich.panel import Panel +from rich.syntax import Syntax from rich.table import Table from rich.text import Text @@ -128,6 +129,18 @@ def init_mod_name(self, component): choices=components, style=nf_core.utils.nfcore_question_style, ).unsafe_ask() + else: + if self.repo_type == "pipeline": + # check if the module is locally installed + self.local_path = self.modules_json.get_all_components(self.component_type).get( + self.modules_repo.remote_url, {} + ) + for directory, comp in self.local_path: + if comp == component: + self.local_path = Path(self.component_type, directory, component) + break + if self.local_path: + self.local = True return component @@ -283,7 +296,7 @@ def generate_component_info_help(self): renderables.append(outputs_table) # Installation command - if self.remote_location: + if self.remote_location and not self.local: cmd_base = f"nf-core {self.component_type}" if self.remote_location != NF_CORE_MODULES_REMOTE: cmd_base = f"nf-core {self.component_type} --git-remote {self.remote_location}" @@ -291,4 +304,29 @@ def generate_component_info_help(self): Text.from_markup(f"\n :computer: Installation command: [magenta]{cmd_base} install {self.component}\n") ) + # Print include statement + if self.local_path: + install_folder = Path(self.dir, self.component_type, self.modules_repo.repo_path) + component_name = "_".join(self.component.upper().split("/")) + renderables.append( + Text.from_markup(f"\n [blue]Use the following statement to include this {self.component_type[:-1]}:") + ) + renderables.append( + Syntax( + f"include {{ {component_name} }} from '../{Path(install_folder, self.component).relative_to(self.dir)}/main'", + "groovy", + theme="ansi_dark", + padding=1, + ) + ) + if self.component_type == "subworkflows": + subworkflow_config = Path(install_folder, self.component, "nextflow.config").relative_to(self.dir) + if os.path.isfile(subworkflow_config): + renderables.append( + Text.from_markup("\n [blue]Add the following config statement to use this subworkflow:") + ) + renderables.append( + Syntax(f"includeConfig '{subworkflow_config}'", "groovy", theme="ansi_dark", padding=1) + ) + return Group(*renderables) diff --git a/nf_core/components/install.py b/nf_core/components/install.py index f9a16f73cf..90cdf7b6a9 100644 --- a/nf_core/components/install.py +++ b/nf_core/components/install.py @@ -1,6 +1,5 @@ import logging import os -import re from pathlib import Path import questionary @@ -74,10 +73,10 @@ def install(self, component, silent=False): ) # Set the install folder based on the repository name - install_folder = os.path.join(self.dir, self.component_type, self.modules_repo.repo_path) + install_folder = Path(self.dir, self.component_type, self.modules_repo.repo_path) # Compute the component directory - component_dir = os.path.join(install_folder, component) + component_dir = Path(install_folder, component) # Check that the component is not already installed component_not_installed = self.check_component_installed( diff --git a/tests/modules/info.py b/tests/modules/info.py index 6c5b1063f1..2dbd48b240 100644 --- a/tests/modules/info.py +++ b/tests/modules/info.py @@ -38,7 +38,6 @@ def test_modules_info_local(self): """Test getting info about a locally installed module""" self.mods_install.install("trimgalore") mods_info = nf_core.modules.ModuleInfo(self.pipeline_dir, "trimgalore") - mods_info.local = True mods_info_output = mods_info.get_component_info() console = Console(record=True) console.print(mods_info_output) @@ -47,6 +46,7 @@ def test_modules_info_local(self): assert "Module: trimgalore" in output assert "Inputs" in output assert "Outputs" in output + assert "Location" in output def test_modules_info_in_modules_repo(self): From 2d04d7294ad997a9787cd168be8850f7ea4ac4ea Mon Sep 17 00:00:00 2001 From: mashehu Date: Thu, 9 Feb 2023 12:09:35 +0100 Subject: [PATCH 2/3] update changelog, use same way to generate self.local_path as in the rest of the code --- CHANGELOG.md | 2 ++ nf_core/components/info.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5dd860b3e..16900b7a59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ ### General +- `nf-core modules/subworkflows info` now prints the include statement for the module/subworkflow ([#2182](https://github.com/nf-core/tools/pull/2182)). + ## [v2.7.2 - Mercury Eagle Patch](https://github.com/nf-core/tools/releases/tag/2.7.2) - [2022-12-19] ### Template diff --git a/nf_core/components/info.py b/nf_core/components/info.py index 69b9e19b87..365e017ab1 100644 --- a/nf_core/components/info.py +++ b/nf_core/components/info.py @@ -132,12 +132,13 @@ def init_mod_name(self, component): else: if self.repo_type == "pipeline": # check if the module is locally installed - self.local_path = self.modules_json.get_all_components(self.component_type).get( + local_paths = self.modules_json.get_all_components(self.component_type).get( self.modules_repo.remote_url, {} ) - for directory, comp in self.local_path: + for directory, comp in local_paths: if comp == component: - self.local_path = Path(self.component_type, directory, component) + component_base_path = Path(self.dir, self.component_type) + self.local_path = Path(component_base_path, directory, self.component) break if self.local_path: self.local = True From 6ce1b3c72b146ebf296493facde2ac1cbf0df312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20H=C3=B6rtenhuber?= Date: Thu, 9 Feb 2023 12:54:03 +0100 Subject: [PATCH 3/3] Update nf_core/components/info.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: JĂșlia Mir Pedrol --- nf_core/components/info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nf_core/components/info.py b/nf_core/components/info.py index 365e017ab1..e4d8038b87 100644 --- a/nf_core/components/info.py +++ b/nf_core/components/info.py @@ -138,7 +138,7 @@ def init_mod_name(self, component): for directory, comp in local_paths: if comp == component: component_base_path = Path(self.dir, self.component_type) - self.local_path = Path(component_base_path, directory, self.component) + self.local_path = Path(component_base_path, directory, component) break if self.local_path: self.local = True