pyhf
pyhf copied to clipboard
Use Rich for formatting summary output
Description
The Rich library is so cool and beautiful that I feel it would be very interesting to see if we could use rich
For a preview of rich v9.9.0's capabilities, this is the output of python -m rich

and python -m rich.palette

It seems that it could be quite useful for adding color highlights to some of the summary information we could output at times, especially with the pyhf CLI API.
Still looks pretty good on ATLAS Connect login nodes too:
(base) [feickert@login ~]$ hostname
login.usatlas.org
(base) [feickert@login ~]$ echo $TERM
xterm-256color
(base) [feickert@login ~]$ python -m rich

(base) [feickert@login ~]$ python -m rich.palette

rich is an amazing library. By the way, it can also do really nice progress bars and spinners so it can replace tqdm too.
yeah the summary output is a good target for this!
Wow.
python -m rich.progress
is sooooo nice! 0_0!
As if we needed more reason :) there's also now Textual from @willmcgugan which looks like magic! :)
https://github.com/willmcgugan/textual
Example: (HT @lukasheinrich) https://twitter.com/willmcgugan/status/1408143208631214080
@lukasheinrich @kratsg Something we should think about is if we want to add rich to the core dependencies or if we want to make it an extra.
rich and its dependencies seem pretty stable
$ pip show rich
Name: rich
Version: 11.0.0
Summary: Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal
Home-page: https://github.com/willmcgugan/rich
Author: Will McGugan
Author-email: [email protected]
License: MIT
Location: /home/feickert/.pyenv/versions/3.9.6/envs/pyhf-dev-CPU/lib/python3.9/site-packages
Requires: colorama, commonmark, pygments
Required-by:
$ pip show colorama
Name: colorama
Version: 0.4.4
Summary: Cross-platform colored terminal text.
Home-page: https://github.com/tartley/colorama
Author: Jonathan Hartley
Author-email: [email protected]
License: BSD
Location: /home/feickert/.pyenv/versions/3.9.6/envs/pyhf-dev-CPU/lib/python3.9/site-packages
Requires:
Required-by: nbdime, rich, twine
$ pip show commonmark
Name: commonmark
Version: 0.9.1
Summary: Python parser for the CommonMark Markdown spec
Home-page: https://github.com/rtfd/commonmark.py
Author: Bibek Kafle <[email protected]>, Roland Shoemaker <[email protected]>
Author-email: [email protected]
License: BSD-3-Clause
Location: /home/feickert/.pyenv/versions/3.9.6/envs/pyhf-dev-CPU/lib/python3.9/site-packages
Requires:
Required-by: rich
$ pip show pygments
Name: Pygments
Version: 2.10.0
Summary: Pygments is a syntax highlighting package written in Python.
Home-page: https://pygments.org/
Author: Georg Brandl
Author-email: [email protected]
License: BSD License
Location: /home/feickert/.pyenv/versions/3.9.6/envs/pyhf-dev-CPU/lib/python3.9/site-packages
Requires:
Required-by: ipython, jupyter-console, jupyterlab-pygments, nbconvert, nbdime, qtconsole, readme-renderer, rich, Sphinx
so I'm not really concerned about replacing click.echo with it, but I can understand that some people in the HEP world would grumble about adding a required dependency to make things really nice to read.
Thoughts?