Closed davidhyman closed 4 years ago
desc
is not a user-defined field, so it can't be overwritten in update()
. See the API documentation.
You have two options. The first one is, like in your example, is to set the desc
attribute explicitly. The alternative is to specify a different name from desc
, such a description
, in bar_format
. As long as it's not the name of a standard field, you can use it.
What might be useful is to detect when standard fields are specified and emit a warning.
Thanks for the prompt response, that works, and makes sense (and of course, format
will protect from any missing arguments).
with enlighten.get_manager() as manager:
steps_bar_format = "{description: <20}{desc_pad}{percentage:3.0f}%|{bar}| {count:{len_total}d}/{total:d}"
steps_bar = manager.counter(total=4, unit="steps", bar_format=steps_bar_format)
steps_bar.update(force=True, description="loading framework")
Agreed about the warning for 'reserved fields' or similar, would be nice to have. Please feel free to close this ticket!
I'll leave this open for now to remind me to add the warning.
Warning code is in master. It was a bit more involved than I thought due to the way keywords are treated in Enlighten. Should be out in a release soon.
Describe the bug When updating a progress bar (
Counter
) I would like to update thedesc
field so that it's reflected in the formatted output:I'd like a progress bar, but with text on it, describing the current action:
currently the description for this bar will remain as "progress":
I'm unsure if this is an intended api to work around it, but I can achieve what I want with:
giving:
Currently I think this might be a bug because the fields are documented as being settable from the update call.
Environment:
Additional context On having a cursory browse, I am not sure whether the
self._fields
update should come after the ln504 update, or whether that second update would be better off checking the contents of the fields dictionary for each item e.g. something likeI imagine this may also affect those other fields e.g. unit, unit pad.
Alternatively, if modifying the
desc
field isn't intended, perhaps the documentation could be updated to remove the affected fields from the "available fields".https://github.com/Rockhopper-Technologies/enlighten/blob/master/enlighten/_counter.py#L504
Also, thanks for this repo - this project is real progress! A step in the right direction. The best bar, bar none.