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

ANSI escape codes break tqdm.tqdm.write formatting #777

Closed
3 tasks
volans- opened this issue Jul 18, 2019 · 2 comments · Fixed by #1008
Closed
3 tasks

ANSI escape codes break tqdm.tqdm.write formatting #777

volans- opened this issue Jul 18, 2019 · 2 comments · Fixed by #1008
Assignees
Labels
c1-quick 🕐 Complexity low duplicate 🗐 Seen it before p2-bug-warning ⚠ Visual output bad to-merge ↰ Imminent
Projects
Milestone

Comments

@volans-
Copy link
Contributor

volans- commented Jul 18, 2019

I'm aware that there are various efforts to improve existing issues related to write() ( #737 ) and to multiple progress bars, but I'd like to report that since tqdm release 4.25.0 and in particular change #592 a previously working code is now visually broken when colors are used.

Pre-4.25.0 behaviour:

$ cumin --force -c /tmp/cumin-dEULJH/config.yaml 'cumin-dEULJH-1' 'ls -la /tmp'
1 hosts will be targeted:
cumin-dEULJH-1
FORCE mode enabled, continuing without confirmation
----- OUTPUT of 'ls -la /tmp' -----
total 8
drwxrwxrwt    2 root     root          4096 Jul  5  2018 .
drwxr-xr-x    1 root     root          4096 Jul 18 16:29 ..
================
PASS |██████████████████████████████████████████████████████████████████████████████████████████████████████| 100% (1/1) [00:00<00:00,  5.40hosts/s]
FAIL |                                                                                                              |   0% (0/1) [00:00<?, ?hosts/s]
100.0% (1/1) success ratio (>= 100.0% threshold) for command: 'ls -la /tmp'.
100.0% (1/1) success ratio (>= 100.0% threshold) of nodes successfully executed all commands.

Since 4.25.0 (scroll all to the right):

$ cumin --force -c /tmp/cumin-dEULJH/config.yaml 'cumin-dEULJH-1' 'ls -la /tmp'
1 hosts will be targeted:
cumin-dEULJH-1
FORCE mode enabled, continuing without confirmation
                                                                                                                                                              |                                                                                                                   |   0% (0/1) [00:00<?, ?hosts/s]
----- OUTPUT of 'ls -la /tmp' -----                                                                                                                                                                                                                                                                                    |                                                                                                                   |   0% (0/1) [00:00<?, ?hosts/s]
total 8                                                                                                                                                                                                                                                                                                                |                                                                                                                   |   0% (0/1) [00:00<?, ?hosts/s]
drwxrwxrwt    2 root     root          4096 Jul  5  2018 .                                                                                                                                                                                                                                                             |                                                                                                                   |   0% (0/1) [00:00<?, ?hosts/s]
drwxr-xr-x    1 root     root          4096 Jul 18 16:29 ..                                                                                                                                                                                                                                                            |                                                                                                                   |   0% (0/1) [00:00<?, ?hosts/s]
================                                                                                                                                         PASS |███████████████████████████████████████████████████████████████████████████████████████████████████████████| 100% (1/1) [00:00<00:00,  4.64hosts/s]
FAIL |                                                                                                                   |   0% (0/1) [00:00<?, ?hosts/s]
100.0% (1/1) success ratio (>= 100.0% threshold) for command: 'ls -la /tmp'.
100.0% (1/1) success ratio (>= 100.0% threshold) of nodes successfully executed all commands.

To see the colors and also the effect on a normally-sized shell see the attached screenshot:
Screen Shot 2019-07-18 at 20 32 36

As soon as I either remove any color from bar_format or revert

N_BARS = max(1, ncols - len(RE_ANSI.sub('', l_bar + r_bar)))

to

N_BARS = max(1, ncols - len(l_bar + r_bar)

everything works back again as before, with the small issue of the progress bars being shorter. CC @jnhansen as was involved in the related change.

If instead of removing the colors I remove the second progress bar this happens (again scroll all to the right):

$ cumin --force -c /tmp/cumin-dEULJH/config.yaml 'cumin-dEULJH-1' 'ls -la /tmp'
1 hosts will be targeted:
cumin-dEULJH-1
FORCE mode enabled, continuing without confirmation
                                                                                                                                                     ----- OUTPUT of 'ls -la /tmp' -----
                                                                                                                                                     total 8
                                                                                                                                                     drwxrwxrwt    2 root     root          4096 Jul  5  2018 .
                                                                                                                                                     drwxr-xr-x    1 root     root          4096 Jul 18 16:29 ..
                                                                                                                                                     ================
PASS |███████████████████████████████████████████████████████████████████████████████████████████████████████| 100% (1/1) [00:00<00:00,  4.47hosts/s]
100.0% (1/1) success ratio (>= 100.0% threshold) for command: 'ls -la /tmp'.
100.0% (1/1) success ratio (>= 100.0% threshold) of nodes successfully executed all commands.

Please advice if there is any workaround that I can use to have those two progress bars working with recent versions of tqdm.

@casperdcl casperdcl added p2-bug-warning ⚠ Visual output bad help wanted 🙏 We need you (discussion or implementation) labels Jul 18, 2019
wmfgerrit pushed a commit to wikimedia/cumin that referenced this issue Jul 19, 2019
* Limit the maximum usable version of tqdm as a temporary workaround for
  tqdm/tqdm#777

Change-Id: Id616117aac1c0d8c628dd8edaa5412acd5f121fa
@nanonano
Copy link

I'm experiencing the same issue in v4.45.0 when using a single progress bar.

Extra line feeds get inserted for writes if color codes are used in the progress bar, using the workaround above, specifying the older version fixes it.

from tqdm import tqdm
  
for i in tqdm(range(10), desc='\033[91m' + "With color"):
    tqdm.write("something")

for i in tqdm(range(10), desc="Without color"):
    tqdm.write("something")

output looks like this.

something

something

something

something

something

something

something

something

something

something
With color: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:00<00:00, 1412.22it/s]
something
something
something
something
something
something
something
something
something
something
Without color: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:00<00:00, 966.74it/s]

nanonano added a commit to BittyTax/BittyTax that referenced this issue Jul 3, 2020
The logger output has been replaced by a more user friendly and more pretty output.

The colorama package is used to provide colour output on both Windows and Mac/Linux.

The tqdm package is used to display progress bars while the accounting tool is progressing transactions. Due to an issue with tqdm (tqdm/tqdm#777) which creates extra new lines if any additional output is made during the progress bar, the setup.py has the tqdm package set to 'tqdm>=4.11.2,<4.25.0' as a workaround.

A progress "spinner" has also been added while the PDF report is being generated as this can be slow for large amounts of data.

The logger is no longer used.
@casperdcl casperdcl self-assigned this Jul 19, 2020
@casperdcl casperdcl added c1-quick 🕐 Complexity low to-merge ↰ Imminent and removed help wanted 🙏 We need you (discussion or implementation) labels Jul 19, 2020
@casperdcl casperdcl added this to Next Release in Casper Jul 19, 2020
@casperdcl casperdcl added this to the Non-breaking milestone Jul 19, 2020
@casperdcl casperdcl changed the title ANSI escape codes in bar_format breaks formatting ANSI escape codes break tqdm.tqdm.write formatting Jul 19, 2020
@casperdcl casperdcl added the duplicate 🗐 Seen it before label Jul 19, 2020
@casperdcl
Copy link
Sponsor Member

duplicate of #692

Casper automation moved this from Next Release to Done Aug 2, 2020
nanonano added a commit to BittyTax/BittyTax that referenced this issue Aug 16, 2020
Release v4.48.1 fixed the issue so the workaround is no longer required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c1-quick 🕐 Complexity low duplicate 🗐 Seen it before p2-bug-warning ⚠ Visual output bad to-merge ↰ Imminent
Projects
Casper
  
Done
Development

Successfully merging a pull request may close this issue.

3 participants