Skip to content

Make the ProgressBar class API #399

Closed

Description

@pombredanne

@mitsuhiko The click._termui_impl.ProgressBar is a wonderful and magical piece of code.

There are cases though where subclassing this can be needed such as providing a few defaults progress messages such as on enter or exit of the context manager for intro and summaries.

This is especially useful to avoid otherwise naughty code mixing progress reporting and actual processing

Nothing prohibits this of course, but if it were made API, subclassing would benefit from a tad more stability with new upgrades. The overall interface of the class has been rather stable for about one year now with only a minor change to support manually updating more than one step at a time....

So IMHO this would benefit to be exposed in a non _ underscore module.

Activity

  1. pombredanne commented on Aug 6, 2015

    @pombredanne
    ContributorAuthor

    BTW the code I am using this in is here https://github.com/nexB/scancode-toolkit/blob/e3b57934a0d6e41a7e3ee6e8261912d3b91764cb/src/scancode/utils.py#L64

    It is rather nasty and tangled and under heavy refactoring to be cleaner and less spaghetti like ... ;)

  2. flying-sheep commented on Aug 21, 2015

    @flying-sheep
    Contributor

    i’m 👍ing this!

    i just made the progressbar abstraction smart-progress, which i at first wanted to base on tqdm, but which now relies on that class.

    sadly that means relying on an undocumented, private API.

    from my usage you can maybe derive what a more general interface would need. IMHO:

    • it’s already pretty awesome to extend. apart from ignoring a few parameters/fields, i basically just have to override __enter__, render_finish, and render_progress.
    • I’d suggest to create a render_start method and call that instead of render_progress in __enter__.
    • also please extract this and this part into a info_bits or format_info_bits method/property which would allow to easily use the information in without copying code from format_progress_line

    thank you very much!

  3. flying-sheep commented on Aug 21, 2015

    @flying-sheep
    Contributor

    @pombredanne your link is broken. protip® from github: press y to get a canonical link to a commit that will never break by changing master

  4. untitaker commented on Aug 21, 2015

    @untitaker
    Contributor

    I recall Armin mentioning one time that he is fundamentally unhappy with the ProgressBar API.

  5. flying-sheep commented on Aug 21, 2015

    @flying-sheep
    Contributor

    well, it’s still easily extensible and its functionality is too useful not to use.

    and being able to either use iteration or the update method is also very useful.

  6. pombredanne commented on Aug 21, 2015

    @pombredanne
    ContributorAuthor

    @flying-sheep link updated
    You can see there an enhanced progress bar, a more verbose progress logger and a noop progress bar (displaying nothing). The three are then used to display more or less based on command options.

    https://github.com/nexB/scancode-toolkit/blob/e3b57934a0d6e41a7e3ee6e8261912d3b91764cb/src/scancode/utils.py#L64

  7. flying-sheep commented on Aug 27, 2015

    @flying-sheep
    Contributor

    also useful would be feature detection if the shell can do unicode and then go to a finer-grained bar like this.

    that would also benefit from a more flexible format_progress_line. e.g. by adding a format_bar method that can be overridden

  8. mitsuhiko commented on Sep 15, 2015

    @mitsuhiko
    Contributor

    I think it would be nice if people could experiment around with it somewhere else and when we found a better way, we redo it in click. I'm not super happy with how it works.

  9. flying-sheep commented on Sep 20, 2015

    @flying-sheep
    Contributor

    could you voice your problems with it?

  10. davidism commented on Apr 20, 2020

    @davidism
    Member

    ProgressBar's implementation is pretty messy. It works, but there are better solutions out there, such as tqdm. For now I'd rather not elevate its API more than is already documented.

  11. locked as resolved and limited conversation to collaborators on Nov 13, 2020
  12. added
    help output
    on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help output

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions