hedyhli / starcli

:sparkles: Browse trending GitHub projects from your command line
https://pypi.org/project/starcli/
MIT License
555 stars 50 forks source link

Bug: Rich v4: "AttributeError: 'Text' object has no attribute 'stylize_all'" #66

Closed jSadoski closed 4 years ago

jSadoski commented 4 years ago

Description

Rich removed text.stylize_all() in version 4.0.

willmcgugan/rich@e784949: A better Text.stylize

$ python -m starcli
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/joe/Projects/starcli/starcli/__main__.py", line 139, in <module>
    cli()
  File "/Users/joe/Projects/starcli/venv/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/Users/joe/Projects/starcli/venv/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/Users/joe/Projects/starcli/venv/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/joe/Projects/starcli/venv/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/Users/joe/Projects/starcli/starcli/__main__.py", line 134, in cli
    list_layout(repos)  # if layout isn't a grid or table, then use list.
  File "/Users/joe/Projects/starcli/starcli/layouts.py", line 97, in list_layout
    console.print(column(render_repo(repo)))
  File "/Users/joe/Projects/starcli/venv/lib/python3.7/site-packages/rich/console.py", line 188, in _replace
    return RenderGroup(*renderables, fit=fit)
  File "/Users/joe/Projects/starcli/starcli/layouts.py", line 59, in render_repo
    title.stylize_all(f"yellow link {repo['html_url']}")
AttributeError: 'Text' object has no attribute 'stylize_all'

Python version

$ python --version
Python 3.7.0

your operating system (and terminal type of needed)

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.5
BuildVersion:   19F101

$ bash --version
GNU bash, version 5.0.18(1)-release (x86_64-apple-darwin19.5.0)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

starcli version

8f92580

any suggestions to the cause of the problem? (if possible)

Either upgrade to rich>=4.0.0 and replace https://github.com/hedythedev/starcli/blob/8f92580119b5e68c2911067db2f8e18e775a9c2a/starcli/layouts.py#L59 with:

title.stylize(f"yellow link {repo['html_url']}")

(tested, works!)

or narrow the dependency to rich>=3.3.0,<4.0.0 (tested, pip installed rich-3.4.1 for me and worked!) Which is better? I can make a PR for either route.

hedyhli commented 4 years ago

Sorry about that, I forgot to check layouts.py if there are any code still using stylize_all when I bumped the rich requirements. Using rich>=4.0.0 and replacing it with stylize_all would be better, since we don't really want the requirements to be locked on an old version, neither do we want to be using deprecated API. I should probably make an hotfix release after this is fixed, because people installing for the first time will probably get 4.0.0 and then have this error

hedyhli commented 4 years ago

Done