Is fancy pip formatting erasing my error backtrace?

There appears to be an interaction problem with https://github.com/kivy/python-for-android and recent pip: it appears pip uses formatting codes to rewrite already written output, and this clashes with whatever python-for-android is doing and I appear to get chunks of missing output or things written half over the terminal and I can’t see the actual error. This is the only readable error part I am getting: working: pip._internal.exceptions.InstallationError: Could not build wheels for sfxscan which use PEP...(and 37 more) along with Found link https://files.pythonhosted.org/packages/c4/27/39e87b69a9a65cc89b6d83d21e7dec... (1301154 more, please see e.stdout). Nothing else of use as far as I can see

Earlier pip versions I don’t think I ever saw do this, has there been a recent change in how formatting works? Is there an option to turn this fancy but for me essentially useless feature off so I can get untampered output?

I would have filed a bug but I’m not 100% sure yet this is the culprit, but if anyone can tell me how to disable all that special terminal cursor and backspace rewrite and whatever stuff I would love to try

Janky way of doing it, but I slapped this together as pipcap.py, to run as $ python pipcap.py:

import sys
from contextlib import redirect_stdout, redirect_stderr
from io import StringIO

from pip._internal import main as pip_main


sys.argv = ["pip", "list"]

new_stdout = StringIO()
new_stderr = StringIO()

with redirect_stdout(new_stdout):
    with redirect_stderr(new_stderr):
        pip_main()

print('stdout:')
print(new_stdout.getvalue().encode(encoding='utf-8'))

print('stderr:')
print(new_stderr.getvalue().encode(encoding='utf-8'))

Replace sys.argv = ['pip', 'list'] with whatever command sequence is of interest. Not sure if the .encode() is really necessary, but.

For whatever arcane reason (it detects the stream isn’t a terminal, maybe?) all of the ANSI coloring gets stripped out when I run it on my Debian box:

$ python3.6 --version
Python 3.6.8
$ python3.6 pipcap.py
stdout:
b'Package    Version\n---------- -------\npip        19.0.3 \nsetuptools 40.6.2 \nvirtualenv 16.4.3 \n'
stderr:
b"You are using pip version 19.0.3, however version 19.1.1 is available.\nYou should consider upgrading via the 'pip install --upgrade pip' command.\n"

Might give you what you need to diagnose?

1 Like

Is there a way to do it with a command line option? I’m not running pip directly (python-for-android is) so getting a script in there is a bit of a janky process.

Also I’ve run multiple times and whatever pip does makes everything go completely haywire when I resize the terminal as well, and I’ve definitely once had the error backtrace show up and once NOT at a different output width. So that’s really a bit of a problem :hushed:

(at the one width where it did show up, it was cut off horizontally so I couldn’t read the essential part of the error, and it wasn’t just wrapped but the right half MISSING - really broken output formatting)

Can always try pip --no-color. (I should’ve checked for/recommended that one first…)

Alternatively/additionally, -q or -qq might trim out some offending stuff?

The problem isn’t that it’s too much AT ALL, the problem is that pip majorly messes with the output:

[INFO]:    -> running bash -c '/home/userhome/.local/share/python-for-android/build/venv/bin/pip' install -c constraints.txt -v .
           working:   /usr/bin/ccache arm-linux-androideabi-gcc -DANDROID -fomit-frame-pointer -D__ANDROID_API__=21 -mandroid -isystem /ndk/sysr...(and 1013 more)

This is all I’ve seen for MINUTES now, and at some point it suddenly expands these 1013 or more with some rewriting magic that just does major harm to my output. Isn’t there a switch to turn that off? I’m sure a couple of color codes don’t do much damage, but whatever is going on with this admittedly fancy but otherwise useless rewriting is really causing me headaches over here

I really don’t want to trim anything down, I just want to get all of the actual output

Edit: I guess your script might work, I’ll give that a try later when I get around to it. but an option would make things a lot easier for sure, I’m not even 100% sure still this is pip’s rewriting messing it up so much but it looks like it

Ahh, that looks more like it’s in pip’s progress-bar treatment of the compile process.

Maybe --progress-bar off?

1 Like

Ok, I just tried both --no-color and --progress-bar off and sadly pip still rewrites all left and right through the output messing things up… I suppose it’s time for a ticket, even if this isn’t why output goes missing it is a bit of a nuisance that it can’t be disabled even if just to see if that messes with something so much to cause that missing output

Edit: unless there is an option of course but in pip3 install --help I can’t see one that looks like it either

Edit 2: nice, got lucky and had another run where despite the rewritten output I got the build error at a terminal width where I could actually read it. pretty sure it wasn’t any of the options though I think I just got rather lucky

Mm, y’know… now that I think about it, I wonder if the problem is in the build tool, not pip. Which builder are you using? setuptools?

1 Like

Oh, interesting idea! Yes, I’m indeed using setuptools. Now that I’m thinking about it, I think the output may have changed once I started using pyproject.toml so I wonder if this is related to the new build isolation?

<nod>, my pip installs definitely changed when I switched to pyproject.toml, such that there’s now a spinner during the build step. That’s probably what’s mucking with things.

1 Like

Yeah that sounds like that might be it. Wish there was a way to disable it, although finger’s crossed maybe I’ve fixed my build issue so maybe I’m good for now

This almost definitely isn’t pip, since it doesn’t have any output of the format “(and xyz more)” or see e.stdout etc.

You should be able to disable ANSI output with --progress (color is dependent on the stream being a tty, but --no-color will force it off).

None the less, if that’s not happening, please file a bug report on our issue tracker (https://github.com/pypa/pip/issues/choose) with a minimal example and steps to reproduce and I’ll be more than happy to figure out what we can do. :slight_smile:

1 Like

This has already been raised (and answered) on the pip tracker.

@jtt Please try to avoid reporting the same issue in multiple places, it causes a lot of duplication of effort For those reading this thread, it appears that the problem may lie with the OP’s environment (Python for Android).

1 Like

@pf_moore I asked here until it seemed established enough there was no option for it (which I easily could have missed) and then it seemed to me like a ticket was the best next step. You can also see this from the timestamps from the posts I hope. I really try not to double post, apologies if it looked like that

(I created the ticket after Brian’s helpful suggestion that it might be the spinner code which seemed reasonable although now it looks like it isn’t, my bad!)

Edit: I should have posted a note to the ticket here when I created it, here is it: https://github.com/pypa/pip/issues/6588

Oh, I’d missed that. Thanks for flagging that @pf_moore. =)

Strong +1

I usually go straight for a ticket, but I was thinking I might save time for everyone involved asking here first to find out if I just had missed an option. So again my apologies if I caused more wasted time, my intention really was to save it :woman_shrugging: (but I messed it up by not linking the ticket once I opened it after the responses here, again, my apologies)