diff --git a/CHANGELOG.md b/CHANGELOG.md index 813c2c3076..1e84fc8043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,8 @@ - Patch: handle file not found when it is an added file to a module ([#2771](https://github.com/nf-core/tools/pull/2771)) - Handle symlinks when migrating pytest ([#2770](https://github.com/nf-core/tools/pull/2770)) - Add `--profile` parameter to nf-test command ([#2767](https://github.com/nf-core/tools/pull/2767)) +- Reduce the sha length in the `nf-core modules list local` and add links to the specific commit ([#2870](https://github.com/nf-core/tools/pull/2870)) +- Add links the nf-core module page and to open the local file in VSCode for module lint results ([#2870](https://github.com/nf-core/tools/pull/2870)) ### General diff --git a/nf_core/components/lint/__init__.py b/nf_core/components/lint/__init__.py index c99934bca3..564dcfaf6b 100644 --- a/nf_core/components/lint/__init__.py +++ b/nf_core/components/lint/__init__.py @@ -11,6 +11,7 @@ import rich.box import rich.console import rich.panel +import rich.repr from rich.markdown import Markdown from rich.table import Table @@ -31,6 +32,7 @@ class LintExceptionError(Exception): pass +@rich.repr.auto class LintResult: """An object to hold the results of a lint test""" @@ -42,6 +44,7 @@ def __init__(self, component, lint_test, message, file_path): self.component_name = component.component_name +@rich.repr.auto class ComponentLint(ComponentCommand): """ An object for linting modules and subworkflows either in a clone of the 'nf-core/modules' @@ -231,9 +234,21 @@ def format_result(test_results, table): if last_modname and lint_result.component_name != last_modname: even_row = not even_row last_modname = lint_result.component_name + + # If this is an nf-core module, link to the nf-core webpage + if lint_result.component.repo_url == "https://github.com/nf-core/modules.git": + module_url = "https://nf-co.re/modules/" + lint_result.component_name.replace("/", "_") + module_name = f"[link={module_url}]{lint_result.component_name}[/link]" + else: + module_name = lint_result.component_name + + # Make the filename clickable to open in VSCode + file_path = os.path.relpath(lint_result.file_path, self.dir) + file_path_link = f"[link=vscode://file/{os.path.abspath(file_path)}]{file_path}[/link]" + table.add_row( - Markdown(f"{lint_result.component_name}"), - os.path.relpath(lint_result.file_path, self.dir), + module_name, + file_path_link, Markdown(f"{lint_result.message}"), style="dim" if even_row else None, ) diff --git a/nf_core/components/list.py b/nf_core/components/list.py index b0c5af219f..f5f2744e17 100644 --- a/nf_core/components/list.py +++ b/nf_core/components/list.py @@ -70,7 +70,7 @@ def pattern_msg(keywords: List[str]) -> str: # We have a pipeline - list what's installed else: # Check that we are in a pipeline directory - print(f"{self.repo_type=}") + log.info(f"Repository type: [blue]{self.repo_type}") try: if self.repo_type != "pipeline": raise UserWarning( @@ -125,10 +125,11 @@ def pattern_msg(keywords: List[str]) -> str: version_sha = component_entry["git_sha"] try: # pass repo_name to get info on modules even outside nf-core/modules - message, date = ModulesRepo( + module = ModulesRepo( remote_url=repo_url, branch=component_entry["branch"], - ).get_commit_info(version_sha) + ) + message, date = module.get_commit_info(version_sha) except LookupError as e: log.warning(e) date = "[red]Not Available" @@ -140,7 +141,14 @@ def pattern_msg(keywords: List[str]) -> str: version_sha = "[red]Not Available" date = "[red]Not Available" message = "[red]Not Available" - table.add_row(component, repo_url, version_sha, message, date) + nice_repo_name = repo_url.replace("https://github.com/", "").replace(".git", "") + table.add_row( + component, + f"[link={repo_url}]{nice_repo_name}[/link]", + f"[link={module.gitless_repo()}/commit/{version_sha}]{version_sha[:7]}[/link]", + message, + date, + ) components.append(component) if print_json: diff --git a/nf_core/modules/modules_repo.py b/nf_core/modules/modules_repo.py index 204c20fd71..9694920274 100644 --- a/nf_core/modules/modules_repo.py +++ b/nf_core/modules/modules_repo.py @@ -69,6 +69,12 @@ def __init__(self, remote_url=None, branch=None, no_pull=False, hide_progress=Fa self.avail_module_names = None + def gitless_repo(self): + gitless_repo_url = self.remote_url + if self.remote_url and ".git" in self.remote_url: + gitless_repo_url = gitless_repo_url[:-4] + return gitless_repo_url + def setup_local_repo(self, remote, branch, hide_progress=True, in_cache=False): """ Sets up the local git repository. If the repository has been cloned previously, it