pyhf icon indicating copy to clipboard operation
pyhf copied to clipboard

Use Rich for formatting summary output

Open matthewfeickert opened this issue 4 years ago • 6 comments

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 avatar Jan 23 '21 22:01 matthewfeickert

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

matthewfeickert avatar Jan 23 '21 22:01 matthewfeickert

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

beojan avatar Jan 29 '21 10:01 beojan

yeah the summary output is a good target for this!

lukasheinrich avatar Feb 14 '21 21:02 lukasheinrich

Wow.

python -m rich.progress

is sooooo nice! 0_0!

matthewfeickert avatar Feb 19 '21 08:02 matthewfeickert

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 avatar Jun 24 '21 19:06 matthewfeickert

@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?

matthewfeickert avatar Jan 10 '22 18:01 matthewfeickert