Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Example usage:
ipdb.set_trace()
ipdb.set_trace(context=5) # will show five lines of code
# instead of the default three lines
# Or you can set it using IPDB_CONTEXT_SIZE env variable.
ipdb.pm()
ipdb.run('x[0] = 3')
result = ipdb.runcall(function, arg0, arg1, kwarg='foo')
Expand Down
15 changes: 11 additions & 4 deletions ipdb/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def import_module(possible_modules, needed_module):
if count == 0:
raise
try:
# IPython 5.0 and newer
# For some versions of IPython 5.x
from IPython.terminal.debugger import TerminalPdb as Pdb
from IPython.core.debugger import BdbQuit_excepthook
except ImportError:
Expand Down Expand Up @@ -70,9 +70,9 @@ def import_module(possible_modules, needed_module):


def _init_pdb(context=3):
if 'context' in getargspec(Pdb.__init__)[0]:
try:
p = Pdb(def_colors, context=context)
else:
except TypeError:
p = Pdb(def_colors)
p.rcLines += def_exec_lines
return p
Expand All @@ -86,7 +86,14 @@ def wrap_sys_excepthook():
sys.excepthook = BdbQuit_excepthook


def set_trace(frame=None, context=3):
def set_trace(frame=None, context=None):
if context:
pass

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm.... I'm slightly worried about this behavior. So, if I have my env var set, then I do: set_trace(context=7), the argumet gets ignored? It seems the argument should have precedence over an env var.

An alternative option may be:

def set_trace(frame=None, context=None):
    if context is None: 
        if os.getenv('IPDB_CONTEXT_SIZE') is not None:
            context = int(os.getenv('IPDB_CONTEXT_SIZE'))
        else:
            context = 3

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, You are right, it will be more flexible =) But I made it in other way (I made commit).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like it.

elif os.getenv('IPDB_CONTEXT_SIZE'):
context = int(os.environ['IPDB_CONTEXT_SIZE'])
Copy link

@disconnect3d disconnect3d May 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be:

if context is None:
    context = int(os.environ.get('IPDB_CONTEXT_SIZE', 3))

else:
context = 3

wrap_sys_excepthook()
if frame is None:
frame = sys._getframe().f_back
Expand Down