Hi Rocky, I looked into this a bit this morning and posted https://github.com/rocky/python2-trepan/pull/8. I've got a few questions, if you've got time today you might pop into #bpython and ping me (ballingt) and we can chat live. I does seem like we should fix embed to take locals and globals.
Tom On Thu, May 28, 2015 at 9:45 AM, Bob Farrell <[email protected] > wrote: > Hi Rocky, > > Two things to point out: 1) I am the original author of bpython but I > haven't actually worked on it in a number of years. 2) bpdb is a contrib, > by someone who may or may not be still around. > > So I'm afraid I'm not going to be much help - hopefully somebody else will > pick this up. :) > > On 28 May 2015 at 13:51, Rocky Bernstein <[email protected]> > wrote: > >> >> On Thursday, May 28, 2015 at 4:30:22 AM UTC-4, Bob Farrell wrote: >>> >>> Hi Rocky (awesome name, by the way), >>> >>> Take a look at the bpdb/ directory in the root of the project directory: >>> https://github.com/bpython/bpython/tree/master/bpdb >>> <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fbpython%2Fbpython%2Ftree%2Fmaster%2Fbpdb&sa=D&sntz=1&usg=AFQjCNGCFTnT6wLU1FR2Nwh1aExY6GHtLg> >>> >>> If I've understood you correctly this should be a working example of >>> what you're looking for. It looks like you're more than familiar with pdb >>> so hopefully this should be a breeze for you. >>> >>> Let us now how you get on ! >>> >> >> Ok. I took a look at https://github.com/bpython/bpython/tree/master/bpdb >> <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fbpython%2Fbpython%2Ftree%2Fmaster%2Fbpdb&sa=D&sntz=1&usg=AFQjCNGCFTnT6wLU1FR2Nwh1aExY6GHtLg>. >> Although I didn't run that code, something that makes no sense to me is how >> instance variables (self) in the BPdb class get picked up by bpython. >> >> Specifically, self.prompt, and self.intro. That definitely didn't work >> for me and so I wound up setting sys.ps1 for the prompt and passing the >> "banner" parameter to bpython.embed(). And even if self.intro works, (does >> it?) passing it as a parameter to embed() seems a lot more straightforward >> and less magical. >> >> So that's the stuff I could figure out. Now onto the I can't. >> >> The first problem I have is getting out of bpython. It seems to close >> sys.stdout. It does this even if inside bpython if I run "raise >> SystemExit", "raise SystemError", quit() or enter Ctrl-D (EOF). So how can >> I get out of bpython without it closing stdout? >> >> The second problem I encounter is in running callbacks into the debugger >> such as for listing files, changing frames for evaluation and so on. I get >> no output, unless I add a gratuitous print('') statement. And even then I >> am getting line feeds (\n) without a carriage return. What's going on >> there? >> >> The last problem is a more minor. embed() has a parameter to set locals, >> but none to set globals. I suppose I could fold or put all globals >> variables into the local scope. But aside from being ugly and potentially >> time consuming, it's semantically wrong. >> >> The specific code I have so far is >> https://github.com/rocky/python2-trepan/blob/master/trepan/processor/command/bpy.py >> but I'd appreciate it if you'd try it out . I think all of the things I've >> mentioned above will be clear. Instructions for installing from git are >> https://github.com/rocky/python2-trepan/wiki/How-to-Install . To run, >> assuming bpython is already installed, just type: >> >> $ trepan2 myscript.py >> (trepan2) bpython >> trepan2 python shell with locals >> Use dbgr(*string*) to issue debugger command: *string* >> trepan2 >>> >> >> >> As you say, since you are familiar with bpython hopefully this will be a >> breeze for you. >> >> Cheers, >> Rocky >> >> >>> Cheers, >>> >>> On Thursday, 28 May 2015 09:24:25 UTC+1, Rocky Bernstein wrote: >>>> >>>> I have recently been beefing up support of the python trepan debugger >>>> <https://pypi.python.org/pypi?name=trepan&:action=display> to go into >>>> both a python and ipython shell. In doing that I came across bpython. >>>> >>>> How does one embed a bpython shell from inside another Python program >>>> such as a debugger? >>>> >>>> Here are some issues that come up: >>>> >>>> >>>> 1. Setting evaluation (locals, globals) to be in the context of the >>>> debugged program >>>> 2. Saving/restoring command history >>>> 3. Saving/restoring command completion functions >>>> >>>> To get a sense of how this is done for ipython and python see >>>> https://github.com/rocky/python2-trepan/blob/master/trepan/processor/command/ipython.py >>>> and >>>> https://github.com/rocky/python2-trepan/blob/master/trepan/processor/command/python.py >>>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "bpython" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/bpython. >> For more options, visit https://groups.google.com/d/optout. >> > > -- > You received this message because you are subscribed to the Google Groups > "bpython" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/bpython. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "bpython" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/bpython. For more options, visit https://groups.google.com/d/optout.
