Skip to content

Commit

Permalink
Use tqdm for search bar
Browse files Browse the repository at this point in the history
  • Loading branch information
vladsavelyev committed Apr 16, 2024
1 parent 882f1b7 commit 0d3c189
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions multiqc/utils/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
from pathlib import Path
from typing import Dict, Union, List, Optional

import rich
import rich.progress
import yaml
import tqdm

from multiqc.utils import lzstring

Expand Down Expand Up @@ -300,31 +299,37 @@ def add_file(fn, root):
for path in config.analysis_dir:
handle_analysis_path(Path(path))

# Search through collected files
console = rich.console.Console(
stderr=True,
highlight=False,
force_interactive=False if config.no_ansi else None,
color_system=None if config.no_ansi else "auto",
)
progress_obj = rich.progress.Progress(
"[blue]|[/] ",
rich.progress.SpinnerColumn(),
"[blue]{task.description}[/] |",
rich.progress.BarColumn(),
"[progress.percentage]{task.percentage:>3.0f}%",
"[green]{task.completed}/{task.total}",
"[dim]{task.fields[s_fn]}",
console=console,
# ANSI escape code for dim text
if not config.no_ansi:
DIM = "\033[2m"
BLUE = "\033[34m"
RESET = "\033[0m"
else:
DIM = ""
BLUE = ""
RESET = ""

# Set up the tqdm progress bar
with tqdm.tqdm(
total=len(searchfiles),
desc="Searching",
unit="file",
disable=config.no_ansi or config.quiet,
)
with progress_obj as progress:
mqc_task = progress.add_task("searching", total=len(searchfiles), s_fn="")
for sf in searchfiles:
progress.update(mqc_task, advance=1, s_fn=os.path.join(sf[1], sf[0])[-50:])
bar_format=f"{BLUE}| {'searching':>17} {RESET}| " + "{bar} {percentage:3.0f}% {n_fmt}/{total_fmt} {desc}",
) as pbar:
for i, sf in enumerate(searchfiles):
# Update the progress bar description with the file being searched
if i % 100 == 0:
pbar.set_description_str(f"{DIM}{os.path.join(sf[1], sf[0])[-50:]}{RESET}")
pbar.update(1)

# Your file processing logic
if not add_file(sf[0], sf[1]):
file_search_stats["skipped_no_match"] += 1
progress.update(mqc_task, s_fn="")

# Clear the description after the loop is complete
pbar.set_description_str(f"{'':>50}")
pbar.refresh()

runtimes["total_sp"] = time.time() - total_sp_starttime
if config.profile_runtime:
Expand Down

0 comments on commit 0d3c189

Please sign in to comment.