Skip to content

Commit

Permalink
Merge pull request #3246 from mashehu/add-diff-seperator
Browse files Browse the repository at this point in the history
Modules: add a panel around diff previews when updating
  • Loading branch information
mashehu authored Oct 25, 2024
2 parents 354311d + 29f6765 commit eb4c237
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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

0 comments on commit eb4c237

Please sign in to comment.