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

Replace halo spinner with rich #2086

Merged
merged 4 commits into from
May 28, 2024
Merged

Replace halo spinner with rich #2086

merged 4 commits into from
May 28, 2024

Conversation

s-ff
Copy link
Collaborator

@s-ff s-ff commented May 24, 2024

This PR is a candidate replacement for Halo spinner as discussed in #1812. It uses Rich module.

If we end up adopting rich, we could maybe use some of its other features to reduce dependencies, for example replacing tqdm with rich.progress and tabulate with rich.table. It could also serve to implement a pager functionality for long output texts.

Checklist

  • No CHANGELOG update needed
  • No new tests needed
  • No documentation update needed

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add bug fixes, new features, breaking changes and anything else you think is worthwhile mentioning to the master (unreleased) section of CHANGELOG.md. If no CHANGELOG update is needed add the following to the PR description: [x] No CHANGELOG update needed

@github-actions github-actions bot dismissed their stale review May 24, 2024 00:03

CHANGELOG updated or no update needed, thanks! 😄

@s-ff s-ff changed the title Replacalo spinner with rich Replac halo spinner with rich May 24, 2024
@s-ff s-ff changed the title Replac halo spinner with rich Replace halo spinner with rich May 24, 2024
@s-ff s-ff requested review from mr-tz and mike-hunhoff May 24, 2024 00:04
capa/loader.py Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
@williballenthin
Copy link
Collaborator

does the rich Console expect to own stderr and that all writes to it go through the console instance? Or can a console be freely mixed with raw print calls (to stderr)?

@williballenthin
Copy link
Collaborator

we can test by having an active spinner (or rich progress bar) and also writing to the output stream directly, and then observing if the spinner is correctly cleaned up/rendered near the new lines.

- remove Halo dependency
- update CHANGELOG.md
- add documentation on rich.console.Console
@s-ff
Copy link
Collaborator Author

s-ff commented May 24, 2024

does the rich Console expect to own stderr and that all writes to it go through the console instance? Or can a console be freely mixed with raw print calls (to stderr)?

we can test by having an active spinner (or rich progress bar) and also writing to the output stream directly, and then observing if the spinner is correctly cleaned up/rendered near the new lines.

I did an expriment for this, and concluded that rich.console.Console can freely be mixed with raw print to stderr.

Test if rich.console can be mixed with raw prints to stderr
import sys
import time

from rich.console import Console

console = Console(stderr=True)

with console.status("Spinner...", spinner="dots"):
    time.sleep(1)
    print("This text is printed to stdout")
    time.sleep(1)
    print("This text is printed to stderr", file=sys.stderr)
    time.sleep(1)

Result:
Kapture 2024-05-24 at 16 21 53

Does this answer your question @williballenthin?

@s-ff s-ff marked this pull request as ready for review May 24, 2024 14:27
@williballenthin
Copy link
Collaborator

wow that's great!

thanks @s-ff!

Copy link
Collaborator

@mr-tz mr-tz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also remove the halo entry from .github/mypy/mypy.ini

capa/loader.py Outdated Show resolved Hide resolved
capa/loader.py Outdated Show resolved Hide resolved
@s-ff s-ff requested a review from mr-tz May 27, 2024 21:34
Copy link
Collaborator

@mr-tz mr-tz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, thanks!

@mr-tz mr-tz merged commit abaabae into mandiant:master May 28, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants