scikit-hep / pyhf

pure-Python HistFactory implementation with tensors and autodiff
https://pyhf.readthedocs.io/
Apache License 2.0
283 stars 84 forks source link

Use Rich for formatting summary output #1277

Open matthewfeickert opened 3 years ago

matthewfeickert commented 3 years ago

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

python_m_rich

and python -m rich.palette

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.

matthewfeickert commented 3 years ago

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

rich_ATLAS_connect

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

rich-palette-atlas-connect

beojan commented 3 years ago

rich is an amazing library. By the way, it can also do really nice progress bars and spinners so it can replace tqdm too.

lukasheinrich commented 3 years ago

yeah the summary output is a good target for this!

matthewfeickert commented 3 years ago

Wow.

python -m rich.progress

is sooooo nice! 0_0!

matthewfeickert commented 3 years ago

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

matthewfeickert commented 2 years ago

@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: willmcgugan@gmail.com
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: tartley@tartley.com
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 <bkafle662@gmail.com>, Roland Shoemaker <rolandshoemaker@gmail.com>
Author-email: rolandshoemaker@gmail.com
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: georg@python.org
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?