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

Modules: add a panel around diff previews when updating #3246

Merged
merged 7 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

### Modules

- add a panel around diff previews when updating ([#3246](https://github.com/nf-core/tools/pull/3246))

### Subworkflows

### General
Expand Down
18 changes: 16 additions & 2 deletions nf_core/modules/modules_differ.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from pathlib import Path
from typing import Dict, List, Union

from rich.console import Console
from rich import box
from rich.console import Console, Group, RenderableType
from rich.panel import Panel
from rich.syntax import Syntax

import nf_core.utils
Expand Down Expand Up @@ -276,6 +278,7 @@ def print_diff(
else:
log.info(f"Changes in module '{Path(repo_path, module)}'")

panel_group: list[RenderableType] = []
for file, (diff_status, diff) in diffs.items():
if diff_status == ModulesDiffer.DiffEnum.UNCHANGED:
# The files are identical
Expand All @@ -293,7 +296,18 @@ def print_diff(
# The file has changed
log.info(f"Changes in '{Path(module, file)}':")
# Pretty print the diff using the pygments diff lexer
console.print(Syntax("".join(diff), "diff", theme="ansi_dark", padding=1))
syntax = Syntax("".join(diff), "diff", theme="ansi_dark", line_numbers=True)
panel_group.append(Panel(syntax, title=str(file), title_align="left", padding=0))
console.print(
Panel(
Group(*panel_group),
title=f"[white]{str(module)}[/white]",
title_align="left",
padding=0,
border_style="blue",
box=box.HEAVY,
)
)

@staticmethod
def per_file_patch(patch_fn: Union[str, Path]) -> Dict[str, List[str]]:
Expand Down
Loading