Skip to main content

Automatically embed IPython for traceback.

Project description

ei

Embedding IPython for debugging.

Install

From GitHub:

pip install git+https://github.com.djosix/ei.git

From PyPI:

pip install ei

Usage

patch and unpatch:

def main():
    a, b, c = 1, 2, 3
    raise ValueError()

if __name__ == '__main__':
    import ei

    # replace sys.excepthook with ei.Hook(select=True),
    # refer to ei.Hook() for more options
    ei.patch(select=True)
    # set select=True if you want to choose which stack frame to embed into

    # when an exception is raised, an IPython shell will be embedded into
    # the stack frame with local variables
    main()

    # restore sys.excepthook
    ei.unpatch()

You can also use capture with the with statement:

def main():
    a, b, c = 1, 2, 3
    raise ValueError()

if __name__ == '__main__':
    import ei

    # context manager for patch() and unpatch()
    with ei.capture(select=True):
        main()

In case you want to change mode and color of the traceback class:

import ei

ei.probe()
'''
IPython debug hook is available!
  class ListTB
    modes: None
    colors: ['NoColor', 'Linux', 'LightBG', 'Neutral', '']
  class VerboseTB
    modes: None
    colors: ['NoColor', 'Linux', 'LightBG', 'Neutral', '']
  class FormattedTB
    modes: ['Plain', 'Context', 'Verbose', 'Minimal']
    colors: ['NoColor', 'Linux', 'LightBG', 'Neutral', '']
  class AutoFormattedTB
    modes: ['Plain', 'Context', 'Verbose', 'Minimal']
    colors: ['NoColor', 'Linux', 'LightBG', 'Neutral', '']
  class ColorTB
    modes: ['Plain', 'Context', 'Verbose', 'Minimal']
    colors: ['NoColor', 'Linux', 'LightBG', 'Neutral', '']
  class SyntaxTB
    modes: None
    colors: ['NoColor', 'Linux', 'LightBG', 'Neutral', '']
'''

# default: AutoFormattedTB
ei.patch(tb_mode='Verbose', tb_color='Linux')

def fuckup(n):
    n = 123 / n
    return n

print(fuckup(0))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ei-0.0.5.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distributions

ei-0.0.5-py3.7.egg (12.4 kB view hashes)

Uploaded Source

ei-0.0.5-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page