Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] from rich.progress import read should be removed from the docs and updated with rich.progress.open example #2204

Closed
hwmrocker opened this issue Apr 20, 2022 · 5 comments

Comments

@hwmrocker
Copy link

You may find a solution to your problem in the docs or issues.

Describe the bug

When I try to use the new promoted progress for file like objects, as described here

import json
from rich.progress import read

with read("data.json", description="Loading data...") as f:
    data = json.load(f)

When executing I get this error:

ImportError: cannot import name 'read' from 'rich.progress' (/home/olaf/.cache/pypoetry/virtualenvs/image-cleanup-ct1VzT8t-py3.10/lib/python3.10/site-packages/rich/progress.py)

Platform

Click to expand

What platform (Win/Linux/Mac) are you running on? What terminal software are you using?

I may ask you to copy and paste the output of the following commands. It may save some time if you do it now.

If you're using Rich in a terminal:

python -m rich.diagnose
pip freeze | grep rich

❯ python -m rich.diagnose
  pip freeze | grep rich

╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── <class 'rich.console.Console'> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ A high level console interface.                                                                                                                                                                                                                                            │
│                                                                                                                                                                                                                                                                            │
│ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=311 ColorSystem.TRUECOLOR>                                                                                                                                                                                                                              │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                                                                                                                                                                                            │
│     color_system = 'truecolor'                                                                                                                                                                                                                                             │
│         encoding = 'utf-8'                                                                                                                                                                                                                                                 │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>                                                                                                                                                                                           │
│           height = 19                                                                                                                                                                                                                                                      │
│    is_alt_screen = False                                                                                                                                                                                                                                                   │
│ is_dumb_terminal = False                                                                                                                                                                                                                                                   │
│   is_interactive = True                                                                                                                                                                                                                                                    │
│       is_jupyter = False                                                                                                                                                                                                                                                   │
│      is_terminal = True                                                                                                                                                                                                                                                    │
│   legacy_windows = False                                                                                                                                                                                                                                                   │
│         no_color = False                                                                                                                                                                                                                                                   │
│          options = ConsoleOptions(size=ConsoleDimensions(width=311, height=19), legacy_windows=False, min_width=1, max_width=311, is_terminal=True, encoding='utf-8', max_height=19, justify=None, overflow=None, no_wrap=False, highlight=None, markup=None, height=None) │
│            quiet = False                                                                                                                                                                                                                                                   │
│           record = False                                                                                                                                                                                                                                                   │
│         safe_box = True                                                                                                                                                                                                                                                    │
│             size = ConsoleDimensions(width=311, height=19)                                                                                                                                                                                                                 │
│        soft_wrap = False                                                                                                                                                                                                                                                   │
│           stderr = False                                                                                                                                                                                                                                                   │
│            style = None                                                                                                                                                                                                                                                    │
│         tab_size = 8                                                                                                                                                                                                                                                       │
│            width = 311                                                                                                                                                                                                                                                     │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭────────────────────────────────────────────────────────────────────────────────────────── Environment Variables ───────────────────────────────────────────────────────────────────────────────────────────╮
│ {'TERM': 'xterm-256color', 'COLORTERM': 'truecolor', 'CLICOLOR': None, 'NO_COLOR': None, 'TERM_PROGRAM': 'vscode', 'COLUMNS': None, 'LINES': None, 'JPY_PARENT_PID': None, 'VSCODE_VERBOSE_LOGGING': None} │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
platform="Linux"
rich @ file:///home/olaf/.cache/pypoetry/artifacts/53/08/03/3c963ded6c89839fa82a21a6f019f969ba2889bd04e49afc295aed14d9/rich-12.2.0-py3-none-any.whl
@astrochun
Copy link

astrochun commented Apr 20, 2022

I had mentioned this being an issue in #1759. I think it's open now. Though open only supports read and not write.

@hwmrocker hwmrocker changed the title [BUG] from rich.progress import read doesn't work [BUG] from rich.progress import read should be removed from the docs Apr 20, 2022
@hwmrocker
Copy link
Author

Ah thx, in this case this part should be removed from the docs. Let me try to create an PR for this.

hwmrocker added a commit to hwmrocker/rich that referenced this issue Apr 20, 2022
The docs are still mentioning `rich.progress.read` but the new way is `rich.progress.open`
I move the docs handling files to top.

I you think progress for reading a file is not basic usage please decline this PR.
To have a progress when reading a file is very useful for me, and I personally think this it is a great selling point.
@astrochun
Copy link

astrochun commented Apr 20, 2022

@hwmrocker, not removed but maybe updated to reflect the API change. But I see the changes to reflect that.

@hwmrocker hwmrocker changed the title [BUG] from rich.progress import read should be removed from the docs [BUG] from rich.progress import read should be removed from the docs and updated with rich.progress.open example Apr 21, 2022
@willmcgugan
Copy link
Collaborator

The section describing read was a remanent of an older edit. The "Reading from a file" section describes the correct API in more detail. Docs have been updated.

@github-actions
Copy link

Did I solve your problem?

Why not buy the devs a coffee to say thanks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants