From abaabae164943ced12371c7b83e023ef3934b213 Mon Sep 17 00:00:00 2001 From: Fariss Date: Tue, 28 May 2024 09:58:32 +0200 Subject: [PATCH] Replace halo spinner with rich (#2086) * Replace halo spinner with rich * remove Halo dependency * Omit halo from mypy.ini --------- Co-authored-by: Soufiane Fariss --- .github/mypy/mypy.ini | 3 --- CHANGELOG.md | 1 + capa/loader.py | 10 +++++++--- pyproject.toml | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/mypy/mypy.ini b/.github/mypy/mypy.ini index a3356eea..3bd4b2e2 100644 --- a/.github/mypy/mypy.ini +++ b/.github/mypy/mypy.ini @@ -1,8 +1,5 @@ [mypy] -[mypy-halo.*] -ignore_missing_imports = True - [mypy-tqdm.*] ignore_missing_imports = True diff --git a/CHANGELOG.md b/CHANGELOG.md index fe3ccc82..99f92a8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - add function in capa/helpers to load plain and compressed JSON reports #1883 @Rohit1123 - document Antivirus warnings and VirusTotal false positive detections #2028 @RionEV @mr-tz +- replace Halo spinner with Rich #2086 @s-ff ### Breaking Changes diff --git a/capa/loader.py b/capa/loader.py index 3d608996..8e91fae0 100644 --- a/capa/loader.py +++ b/capa/loader.py @@ -11,7 +11,7 @@ import datetime from typing import Set, Dict, List, Optional from pathlib import Path -import halo +from rich.console import Console from typing_extensions import assert_never import capa.perf @@ -176,6 +176,10 @@ def get_extractor( UnsupportedArchError UnsupportedOSError """ + + # stderr=True is used here to redirect the spinner banner to stderr, so that users can redirect capa's output. + console = Console(stderr=True, quiet=disable_progress) + if backend == BACKEND_CAPE: import capa.features.extractors.cape.extractor @@ -222,7 +226,7 @@ def get_extractor( if os_ == OS_AUTO and not is_supported_os(input_path): raise UnsupportedOSError() - with halo.Halo(text="analyzing program", spinner="simpleDots", stream=sys.stderr, enabled=not disable_progress): + with console.status("analyzing program...", spinner="dots"): bv: BinaryView = binaryninja.load(str(input_path)) if bv is None: raise RuntimeError(f"Binary Ninja cannot open file {input_path}") @@ -247,7 +251,7 @@ def get_extractor( if os_ == OS_AUTO and not is_supported_os(input_path): raise UnsupportedOSError() - with halo.Halo(text="analyzing program", spinner="simpleDots", stream=sys.stderr, enabled=not disable_progress): + with console.status("analyzing program...", spinner="dots"): vw = get_workspace(input_path, input_format, sigpaths) if should_save_workspace: diff --git a/pyproject.toml b/pyproject.toml index 2d3ba28d..68dcf2dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,6 @@ dependencies = [ "wcwidth==0.2.13", "ida-settings==2.1.0", "viv-utils[flirt]==0.7.9", - "halo==0.0.31", "networkx==3.1", "ruamel.yaml==0.18.6", "vivisect==1.1.1", @@ -50,6 +49,7 @@ dependencies = [ "dncil==1.0.2", "pydantic==2.7.1", "protobuf==5.26.1", + "rich==13.4.2" ] dynamic = ["version"]