Dvc: progress, prompt: isatty broken on Windows, default git bash and conda python

Created on 6 Nov 2019  路  21Comments  路  Source: iterative/dvc

Effectively it means that we don't see any progress bars. Just empty screen for commands.

It's a well known issue on a default setup - conda + git bash (haven't tested other configurations). More on this here: https://stackoverflow.com/a/32599341/298182

To reproduce:

import sys

file = sys.stderr
print(file.isatty())

returns False if you run like this python test.py
returns True if winpty python test.py

bug p1-important ui

All 21 comments

DVC_IGNORE_ISATTY=true dvc add data

works, but has broken formatting :slightly_frowning_face:

Can reproduce the same with regular official python (not from conda).

Based on the SO link should we just document winpty on git-bash?

if DVC_IGNORE_ISATTY still had broken formatting this means that git-bash simply doesn't support \r and progress bars

@efiop does winpty fix the formatting?

@casperdcl It actually looks pretty strange:

$ DVC_IGNORE_ISATTY=true dvc add data
  0%|          |Add                                   0/1 [00:00<?,     ?file/s]
!
Computing hashes (only done once)                   0 [00:00<??:??,      ?md5/s]
100% Add                                          1/1 [00:16<00:00,  16.2s/file]

To track the changes with git, run:

        git add data.dvc

This is literally what I'm seeing, no line was updated :thinking:

Didn't try winpty yet :slightly_frowning_face: @shcheklein Does it work with dvc add correctly?

@efiop @casperdcl winpty works fine for me. I wonder how other tools deal with this. For example, I've seen conda printing progress bars without any winpty? What is that specific that winpty is doing after all?

Ah interesting... conda uses tqdm so there must be a way to patch it.

@casperdcl may be it does not check isatty at all?

@shcheklein @efiop DVC_IGNORE_ISATTY=true also skips checking isatty so there must be something else going on

Actually this may just be a colorama issue on windows, which may coincidentally have been fixed by my last devel-branch commit: https://github.com/tqdm/tqdm/commit/ae6de71c3460123944aa7bb80d7cb0b5bdcafb7b

@efiop / @shcheklein could you try

pip install -U git+https://github.com/tqdm/tqdm.git@ae6de71c#egg=tqdm

and check if it fixes this issue?

@casperdcl Installing that still shows

$ DVC_IGNORE_ISATTY=true dvc add data
  0%|          |Add                                   0/1 [00:00<?,     ?file/s]
!
Computing hashes (only done once)                   0 [00:00<??:??,      ?md5/s]
100% Add                                          1/1 [00:16<00:00,  16.2s/file]

To track the changes with git, run:

        git add data.dvc

for me :slightly_frowning_face:

hmm. @efiop was colorama also installed on your machine?

@casperdcl Ah, wait. I do see a change if i drop #egg part in that command(not sure what is up with that). Now it works, but it prints on a new line each time:

kupru@DESKTOP-LQKMJV2 /cygdrive/c/Users/kupru/myrepo
$ DVC_IGNORE_ISATTY=true dvc add data
  0%|          |Add                                   0/1 [00:00<?,     ?file/s]
!
  0%|          |Computing hashes (only done once) 0/12057 [00:00<?,      ?md5/s]
  0%|          |Computing hashes (only done o17/12057 [00:00<01:25,    142md5/s]
  0%|          |Computing hashes (only done o31/12057 [00:00<01:26,    140md5/s]
  0%|          |Computing hashes (only done o48/12057 [00:00<01:24,    142md5/s]
  0%|          |Computing hashes (only done o60/12057 [00:00<01:31,    132md5/s]
  1%|          |Computing hashes (only done o75/12057 [00:00<01:31,    132md5/s]
  1%|          |Computing hashes (only done o91/12057 [00:00<01:26,    138md5/s]
  1%|          |Computing hashes (only done 104/12057 [00:00<01:29,    134md5/s]
  1%|          |Computing hashes (only done 118/12057 [00:00<01:29,    134md5/s]
  1%|1         |Computing hashes (only done 132/12057 [00:00<01:29,    133md5/s]
  1%|1         |Computing hashes (only done 147/12057 [00:01<01:29,    133md5/s]
  1%|1         |Computing hashes (only done 161/12057 [00:01<01:31,    131md5/s]
  1%|1         |Computing hashes (only done 175/12057 [00:01<01:31,    130md5/s]
  2%|1         |Computing hashes (only done 191/12057 [00:01<01:27,    136md5/s]
  2%|1         |Computing hashes (only done 206/12057 [00:01<01:27,    136md5/s]
  2%|1         |Computing hashes (only done 220/12057 [00:01<01:28,    134md5/s]
  2%|1         |Computing hashes (only done 235/12057 [00:01<01:26,    137md5/s]
  2%|2         |Computing hashes (only done 249/12057 [00:01<01:26,    137md5/s]
  2%|2         |Computing hashes (only done 263/12057 [00:01<01:30,    131md5/s]
  2%|2         |Computing hashes (only done 277/12057 [00:02<01:32,    127md5/s]
  2%|2         |Computing hashes (only done 290/12057 [00:02<01:32,    127md5/s]
  3%|2         |Computing hashes (only done 303/12057 [00:02<01:35,    123md5/s]
  3%|2         |Computing hashes (only done 316/12057 [00:02<01:36,    122md5/s]
  3%|2         |Computing hashes (only done 329/12057 [00:02<01:34,    124md5/s]
  3%|2         |Computing hashes (only done 344/12057 [00:02<01:30,    129md5/s]
  3%|2         |Computing hashes (only done 359/12057 [00:02<01:27,    133md5/s]
  3%|3         |Computing hashes (only done 373/12057 [00:02<01:30,    129md5/s]

So looks like it almost works :)

@casperdcl Yes, colorama is installed(we have it as a dependency for dvc too). 0.4.1 though

hmm - so likely some sort of variant of https://github.com/tartley/colorama/issues/79 - maybe at the top of the main file @efiop try patching:

diff --git a/dvc/__main__.py b/dvc/__main__.py
index e160b02..7d1804a 100644
--- a/dvc/__main__.py
+++ b/dvc/__main__.py
@@ -4,6 +4,10 @@ from __future__ import unicode_literals
 import sys

 from dvc.main import main
+from dvc.progress import Tqdm
+import colorama
+colorama.deinit()
+colorama.init(strip=False, convert=True)

 if __name__ == "__main__":
     main(sys.argv[1:])

?

@casperdcl Didn't help. Same as in https://github.com/iterative/dvc/issues/2747#issuecomment-551300835 :slightly_frowning_face:

Btw, running wget in gitbash, it also doesn't respect \r and prints new lines each time.

unfortunately rprichard/winpty isn't exactly a small fix which could be integrated into dvc core. May have to rely on detecting MSYS/Cygwin/git-bash from os.environ and doing something special accordingly.

Would also need to ensure the "something special" (e.g. reduce progress updates to once per 2 seconds to prevent console spamming, or maybe disable progress altogether, or add a single . each iteration, etc...) isn't done when using winpty

looks like https://github.com/msys2/MINGW-packages/pull/2675 isn't yet in the latest gitforwindows... Interestingly I found (in git-bash):

# normal (dvc CLI) use
$ python -c 'import sys; print(sys.stderr.encoding)'
<_io.TextIOWrapper name='<stderr>' mode='w' encoding='cp1252'>
# emulate file redirection
$ python -c 'import sys; print(sys.stderr.encoding)' 2>/dev/null
<_io.TextIOWrapper name='<stderr>' mode='w' encoding='cp850'>

maybe we could use isatty() or encoding == 'cp1252'? Tested on latest git-bash & conda3, though not sure if windows version affects this as well.

As a quick follow-up - it's not a good idea to check env vars for detecting if running in git-bash because we still want to disable if really redirecting to a file.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

analystanand picture analystanand  路  3Comments

ghost picture ghost  路  3Comments

GildedHonour picture GildedHonour  路  3Comments

dnabanita7 picture dnabanita7  路  3Comments

shcheklein picture shcheklein  路  3Comments