05-support-readline.patch 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. --- contrib/python/pytest/py2/_pytest/debugging.py (index)
  2. +++ contrib/python/pytest/py2/_pytest/debugging.py (working tree)
  3. @@ -4,6 +4,7 @@ from __future__ import absolute_import
  4. from __future__ import division
  5. from __future__ import print_function
  6. +import os
  7. import argparse
  8. import pdb
  9. import sys
  10. @@ -14,6 +15,42 @@ from _pytest import outcomes
  11. from _pytest.config.exceptions import UsageError
  12. +def import_readline():
  13. + try:
  14. + import readline
  15. + except ImportError:
  16. + sys.path.append('/usr/lib/python2.7/lib-dynload')
  17. +
  18. + try:
  19. + import readline
  20. + except ImportError as e:
  21. + print('can not import readline:', e)
  22. +
  23. + import subprocess
  24. + try:
  25. + subprocess.check_call('stty icrnl'.split())
  26. + except OSError as e:
  27. + print('can not restore Enter, use Control+J:', e)
  28. +
  29. +
  30. +def tty():
  31. + if os.isatty(1):
  32. + return
  33. +
  34. + fd = os.open('/dev/tty', os.O_RDWR)
  35. + os.dup2(fd, 0)
  36. + os.dup2(fd, 1)
  37. + os.dup2(fd, 2)
  38. + os.close(fd)
  39. +
  40. + old_sys_path = sys.path
  41. + sys.path = list(sys.path)
  42. + try:
  43. + import_readline()
  44. + finally:
  45. + sys.path = old_sys_path
  46. +
  47. +
  48. def _validate_usepdb_cls(value):
  49. """Validate syntax of --pdbcls option."""
  50. try:
  51. @@ -249,6 +286,7 @@ class pytestPDB(object):
  52. @classmethod
  53. def set_trace(cls, *args, **kwargs):
  54. """Invoke debugging via ``Pdb.set_trace``, dropping any IO capturing."""
  55. + tty()
  56. frame = sys._getframe().f_back
  57. _pdb = cls._init_pdb("set_trace", *args, **kwargs)
  58. _pdb.set_trace(frame)
  59. @@ -262,6 +300,7 @@ class PdbInvoke(object):
  60. out, err = capman.read_global_capture()
  61. sys.stdout.write(out)
  62. sys.stdout.write(err)
  63. + tty()
  64. _enter_pdb(node, call.excinfo, report)
  65. def pytest_internalerror(self, excrepr, excinfo):