capa
capa copied to clipboard
find a replacement for halo
we use the halo package to show a spinner during long running computations. unfortunately, the package hasn't been updated in a long time, and while this typically isn't an issue itself, it calls a deprecated API:
.../capa/.direnv/python-3.11/lib/python3.11/site-packages/halo/halo.py:497: DeprecationWarning: setDaemon() is deprecated, set the daemon attribute instead
self._spinner_thread.setDaemon(True)
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
maybe https://pypi.org/project/yaspin/ ?
Was cruising for issues with good-first-issue and saw this. Took a crack at it, but I still need to make sure it streams to stderr:
https://github.com/bpshaver/capa/commit/ac742f7ec8ca663cbdb08a22bb4dbb404793101b
It looks like yaspin only writes to sys.stdout
the STDOUT consideration is around things like: capa.exe > output.txt but still wanting to see the progress bar while it executes? this is a good point, thanks for mentioning it.
this is a nice set of requirements: https://github.com/pavdmyt/yaspin/issues/31#issuecomment-1016861612 and the associated issue is rather worrying for yaspin - it doesn't seem to be especially hardened/mature if this isn't addressed yet.
totally open to other libraries, too. this was just the first one on google. also ok with doing it ourselves if the implementation is simple.
Yeah, I read that issue too. At first I was thinking of just disabling the spinner if stdout is not a TTY, but now I see that you want the spinner on stderr while stdout safely goes through the pipe.
Would it be too hacky to just patch sys.stdout to sys.stderr? I'll give it a shot.
import sys
from unittest.mock import patch
with patch("sys.stdout", sys.stderr):
with yaspin(text="spinning"):
Something like this accomplishes the job if you're not writing to stdout within the context of the spinner. In the second instance of main.py, though, there are calls to the logger methods, and I'm unsure how they are affected by the patch. Probably best to modify the handler for the logger so its explicit about going to stdout or stderr.
I've updated my branch with this patch applied to main.py
diffs are here: https://github.com/mandiant/capa/compare/master...bpshaver:capa:chore/replace-halo-dependency