easybuild-framework icon indicating copy to clipboard operation
easybuild-framework copied to clipboard

NameError: name 'Group' is not defined (because Rich version installed is too old)

Open JensTimmerman opened this issue 3 years ago • 6 comments

 eb -r easybuild-easyconfigs/easybuild/easyconfigs/p/Python/Python-2.7.18-GCCcore-11.2.0-bare.eb  --robot-paths=easybuild-easyconfigs/easybuild/easyconfigs
== Temporary log file in case of crash /tmp/eb-5cuj4fae/easybuild-rx0j599m.log
== resolving dependencies ...
Traceback (most recent call last):
  File "/usr/lib64/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib64/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/jens/.local/lib/python3.10/site-packages/easybuild/main.py", line 597, in <module>
    main()
  File "/home/jens/.local/lib/python3.10/site-packages/easybuild/main.py", line 559, in main
    with rich_live_cm():
  File "/home/jens/.local/lib/python3.10/site-packages/easybuild/tools/output.py", line 131, in rich_live_cm
    pbar_group = Group(
NameError: name 'Group' is not defined

This seems to happen because the import errors when from rich.console import Console, Group are silenced and no alternatives to Group are implemented in easybuild/tools/output.py

>>> from rich.console import Console, Group
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Group' from 'rich.console' (/home/jens/.local/lib/python3.10/site-packages/rich/console.py)

I could fix this on my system by running pip install -U rich But I believe the import error checking or an extra check for the existance of Group could be added to improve user experience (or in the exception handling print out a helpfull message )

JensTimmerman avatar Jul 20 '22 12:07 JensTimmerman

Hmm, I'm a bit confused as to how you were able to trigger this...

The if show_progress_bars() guard in rich_live_cm should prevent that you ever run into this. If rich is not installed, then show_progress_bars() should always return False unless you have configured EasyBuild to use rich output style, which would result in a clean error if rich is not available.

boegel avatar Aug 03 '22 13:08 boegel

@boegel this happens when you have an old version of rich installed that does not yet have the Group class in rich.console

So rich is installed, but the Group import failed and was silently ignored.

This is why pip install -U rich fixed this, it updated rich to a newer version that does have Group available for import.

JensTimmerman avatar Aug 03 '22 13:08 JensTimmerman

OK, thanks for clarifying.

In that case, we can easily fix this by changing the import rich "test" that's being done in tools/config.py, which determines the value of HAVE_RICH to be a bit more elaborate (like actually trying to import stuff from rich that we know we need). That's bound to break again in the future though, so I wonder if we can come up with a better mechanism...

boegel avatar Aug 04 '22 08:08 boegel

well you could set HAVE_RICH to false where you are now doing a pass in the import error?

JensTimmerman avatar Aug 04 '22 13:08 JensTimmerman

Well, we do, but the import test we're doing there is not specific enough (we only do import rich, we don't try to import Group from rich.console), see https://github.com/easybuilders/easybuild-framework/blob/c10f1e069fc50397f4089e48fa3bc92eff8b16a5/easybuild/tools/config.py#L51-L55

I think this basically boils down to printing a warning when we notice that the Rich version that is found is too old. EasyBuild clearly has a minimal version requirement here (whatever Rich version provides Group), but we're not checking that anywhere. We should do that in config.py, and print a warning if the import worked, but the Rich version is too old (and then still set HAVE_RICH to False)... That would have made the problem immediately clear, and would have avoided the nasty crash.

boegel avatar Aug 05 '22 15:08 boegel

Looks like we would need https://github.com/Textualize/rich/releases/tag/v10.7.0

ocaisa avatar Sep 30 '22 14:09 ocaisa

I looked into this a while ago, and adding a version check for Rich isn't all that trivial.

It seems quite unlikely now that people will be hitting a sufficiently old Rich version, so closing this as "won't fix"...

boegel avatar Apr 03 '24 19:04 boegel