Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adds a short sha representation to modules list command pointing to the repo specific commit #2870

Merged
merged 9 commits into from
Mar 18, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
- 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 size of the sha representation in the `list` command and links to the specific commit ([#2870](https://github.com/nf-core/tools/pull/2870))
ewels marked this conversation as resolved.
Show resolved Hide resolved

### General

Expand Down
18 changes: 16 additions & 2 deletions nf_core/components/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -31,6 +32,7 @@ class LintExceptionError(Exception):
pass


@rich.repr.auto
class LintResult:
"""An object to hold the results of a lint test"""

Expand All @@ -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'
Expand Down Expand Up @@ -231,9 +234,20 @@ 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_name = f"[link=https://nf-co.re/modules/{lint_result.component_name.replace("/","_")}]{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,
)
Expand Down
16 changes: 12 additions & 4 deletions nf_core/components/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"
Expand All @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions nf_core/modules/modules_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading