pypa / setuptools

Official project repository for the Setuptools build system
https://pypi.org/project/setuptools/
MIT License
2.53k stars 1.19k forks source link

Can't pdb a setup() call in Windows cmd.exe #433

Open ghost opened 9 years ago

ghost commented 9 years ago

Originally reported by: embray (Bitbucket: embray, GitHub: embray)


I ran across this while trying to run

$ python3.4 -m pdb setup.py build_ext

on Windows, in a standard cmd.exe prompt, while trying to debug an unrelated issue.

This results in a traceback stemming from Pdb ending with:

ValueError: underlying buffer has been detached

the full traceback isn't really important. This traces back to https://bitbucket.org/tarek/distribute/issues/311 -- because the original sys.stdout's raw buffer is detached, Pdb breaks. https://bitbucket.org/tarek/distribute/issues/334 added a partial workaround, but it's acknowledge there that there may be corner cases not covered. This is one such corner case.

One workaround is to manually edit the distutils/setuptools/etc. source code and add a pdb.set_trace() closer to the code you wish to debug (so that PDB is not invoked until after this sys.stdout switcheroo).

Some other possibilities might be to monkeypatch distutils.dist to replace the print() function (this all only applies to Python 3 anyways IIUC) or alternatively pdb can be monkeypatched. The code the messes with sys.stdout could be rewritten as a context manager that handles this.

It's probably not worth it though since this is indeed a narrow corner case. But if you would accept such a patch I'll think about writing it. In the meantime just thought I'd document the issue.


ghost commented 9 years ago

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


I've run into this issue myself. Thanks for writing up the details and your research. I'd like a better experience, so if you're interested in pursuing a patch, I'd be eager to see it.