So, after a long time trying to get everything running (largely due to being
distracted on IRC, granted), I managed to track down and fix the problems.

Before I start, I'd like to say I'm really impressed with the work you've done
- I nearly had a shit fit when I saw you'd gutted all of the attribute lookup
stuff and wondered why on earth you were surprised it was not working, and then
noticed the "python" module and dependency injection stuff you're doing. So,
good work !

Now, here's why you weren't finding the problem:
        try:
            self.completer.complete(cw, 0)
        except Exception:
# This sucks, but it's either that or list all the exceptions that could
# possibly be raised here, so if anyone wants to do that, feel free to send me
# a patch. XXX: Make sure you raise here if you're debugging the completion
# stuff !

Unfortunately, given that all kinds of exceptions can occur during completion
stuff (since we're letting the user execute code inside our program), a long
time ago I resigned to just catching "Exception" and dealing with it -
TypeError, ValueError, blah blah blah, can all be raised. So, unless you do a
"raise" in that except block, anything that goes wrong in the completion stuff
will be ignored and you won't see any legitimate bugs in the code.

In this case, firstly the "types" module hadn't been imported in python.py,
secondly "matches" doesn't get defined here if attr_lookup fails (this is
technically a bug in my code):
    try:
        matches = attr_lookup(obj, expr, attr)
    finally:
        # Dark magic:
        if __getattribute__ is not None:
            setattr(type_, '__getattribute__', __getattribute__)
        if __getattr__ is not None:
            setattr(type_, '__getattr__', __getattr__)
        # /Dark magic
        return matches

so that raises a NameError, and thridly, "expr" and "attr" weren't being passed
in to get_obj_attrs, so they were undefined too. attr_matches now passes them
in:

    def attr_matches(self, text):
        """Taken from rlcompleter.py and bent to my will."""

        m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text)
        if not m:
            return []

        expr, attr = m.group(1, 3)
        obj = eval(expr, self.interp.locals)

        s = language.get_obj_attrs(obj, expr, attr)
        return s

(Previously just did "language.get_obj_attrs(obj)").

Okay ! So, I've attached a patch; everything seems to work fine now; hopefully
you'll be able to use what I've done to get it working with oranj - just make
sure to raise that exception I mentioned !

Oh, and that "foo(" stuff in the completion list is pretty cool; looking
forward to pulling that upstream.

As far as I can tell everything's ready to go as-is as far as pulling changes
upstream goes. Once we've got that done I'm happy to give you commit privs to
the main bpython repo so you can push your changes there directly - you've done
a great job on the language-agnostic front. Can you think of anything that's
preventing me pulling upstream now ? I'll let you get back to me before I do
anything.

On Wed, May 13, 2009 at 12:01:12PM -0700, Pavel Panchekha wrote:
> 
> Committed new revision to oranj. Try to redownload it and modify the
> file src/objects/about.py to the installation path (or just read the
> INSTALL file).
> 
> I'll get a build script up and running for that at some point.
> 
> On May 13, 5:19 pm, Bob Farrell <[email protected]>
> wrote:
> > Been fighting for a while now to get this working but there are a some 
> > missing
> > dependencies.
> >
> > I'm guessing this:
> >    http://code.activestate.com/recipes/475116/
> > is the "terminal" module.
> >
> > No idea what the "files" module is, but it's looking for that too, and I 
> > really
> > need to get out of the office now. I might take a look at this later but
> > ideally if you could get this working in a --no-site-packages virtualenv and
> > list any dependencies on the bitbucket.org wiki (or include any extra deps 
> > in
> > the distribution) that'd be great.
> >
> > Nice work, though - good to see you're taking the right approach with 
> > keeping
> > bpython agnostic. Once we figure out what's up with the attribute lookup 
> > issue
> > (which I can probably diagnose by just using bpython without the --oranj 
> > flag)
> > I'll do some testing and then I see no problem pulling your changes 
> > upstream.
> >
> >
> >
> > On Wed, May 13, 2009 at 08:20:32AM -0700, Pavel Panchekha wrote:
> >
> > >http://bitbucket.org/pavpanchekha/bpython-oranj/
> >
> > > Python is now a bit broken (no attr matching), oranj just as good (use
> > > --oranj command line flag).
> >
> > > Because I've yet to make a build system thing for oranj, the following
> > > directory tree is required:
> >
> > > oranj
> > >  - folder
> > >    - bpython
> > >  - src
> > >  - ...
> >
> > > folder can be called anything.
> >
> > > I should really fix that.
> >
> > > On May 13, 2:22 pm, Bob Farrell <[email protected]>
> > > wrote:
> > > > Well, there's some hideously dark magic that goes on with the 
> > > > autocompletion
> > > > stuff which you might want to bypass. Feel free to send a patch over 
> > > > (or,
> > > > ideally, if you can fork the bpython project on bitbucket.org so I can 
> > > > pull and
> > > > push without having to worry about emailing patch files around) and 
> > > > I'll take a
> > > > look. I'm at work, may as well do something interesting. :)
> >
> > > > On Wed, May 13, 2009 at 05:58:47AM -0700, Pavel Panchekha wrote:
> >
> > > > > Hmm. I have it mostly working, but I seem to have completely broken
> > > > > attribute matching. Don't know why, and can't seem to be able to debug
> > > > > anything. If you want, I can send you a patch as it is now, maybe you
> > > > > will understand better than me. Don't want to waste your time though.
> >
> > > > > What I have right now is that I split out all of the language specific
> > > > > stuff completely, and everything but the attribute matching works (Oh,
> > > > > and I haven't tested rewind, but that shouldn't be a problem).
> >
> > > > > On May 13, 9:46 am, Bob Farrell <[email protected]>
> > > > > wrote:
> > > > > > Hi Pavel,
> >
> > > > > > On Tue, May 12, 2009 at 05:58:13PM -0700, Pavel Panchekha wrote:
> >
> > > > > > > Having a bit of trouble here with the color formatting. The
> > > > > > > BPythonFormatter works (mostly, had to fix it up a bit) but 
> > > > > > > there's
> > > > > > > another issue.
> >
> > > > > > > When Oranj prints error messages, it'd be nice if they were 
> > > > > > > colored.
> > > > > > > They already are when using the console, but I need to use the 
> > > > > > > curses
> > > > > > > color codes for printing in the bpython.
> >
> > > > > > > What I'm doing is this:
> >
> > > > > > > msg = "\x01r\x03%s\x01d\x03%s" % (type(e).__name__, ("" if not 
> > > > > > > e.args
> > > > > > > else (": " + " ".join(map(str, e.args)))))
> >
> > > > > > > Ideally, this should make the first bit (type(e).__name__) red 
> > > > > > > and the
> > > > > > > other bit normal gray colored (Its the error message). This isn't
> > > > > > > working, however - the entire line is red.
> >
> > > > > > I thought this was already possible, but turns out it wasn't - I've 
> > > > > > changed the
> > > > > > code so that you can achieve what you were aiming for now by doing 
> > > > > > this:
> > > > > >     msg = "\x01r\x03what\x04\x01d\x03hello"
> > > > > > and then passing that to Repl.write, which will now split on \x04 - 
> > > > > > you'll have
> > > > > > to pull from the hg repo to get the latest changes, or just use 
> > > > > > this:
> >
> > > > > >     def write(self, s):
> > > > > >         """For overriding stdout defaults"""
> > > > > >         if '\x04' in s:
> > > > > >             for block in s.split('\x04'):
> > > > > >                 self.write(block)
> > > > > >             return
> > > > > >         if s.rstrip() and '\x03' in s:
> > > > > >             t = s.split('\x03')[1]
> > > > > >         else:
> > > > > >             t = s
> >
> > > > > >         if isinstance(t, unicode):
> > > > > >             t = t.encode(getattr(sys.__stdout__, 'encoding') or 
> > > > > > sys.getdefaultencoding())
> >
> > > > > >         if not self.stdout_hist:
> > > > > >             self.stdout_hist = t
> > > > > >         else:
> > > > > >             self.stdout_hist += t
> >
> > > > > >         self.echo(s)
> > > > > >         self.s_hist.append(s.rstrip())
> >
> > > > > > The more I look at the way the colours work in bpython, the more I 
> > > > > > hate it. Oh
> > > > > > well. :)
> >
> > > > > > > Anything I'm doing wrong? I could send complete, (sorta) working 
> > > > > > > code
> > > > > > > if you want, but in any case, is there anything obviously wrong?
> >
> > > > > > > On May 12, 5:06 pm, Pavel Panchekha <[email protected]> 
> > > > > > > wrote:
> > > > > > > > Thanks for the rundown. It shouldn't be too hard - most of the 
> > > > > > > > stuff
> > > > > > > > you mentioned is already there in a half-done way, just need to 
> > > > > > > > clean
> > > > > > > > it up. With luck, I'll extract the python-specific bits as I 
> > > > > > > > go, so it
> > > > > > > > can be merged upstream. I'll try to keep the mailing list 
> > > > > > > > posted if I
> > > > > > > > finish up.
> >
> > > > > > > > On May 12, 4:53 pm, Bob Farrell 
> > > > > > > > <[email protected]>
> > > > > > > > wrote:
> >
> > > > > > > > > Hi Pavel,
> >
> > > > > > > > > On Tue, May 12, 2009 at 11:01:05AM -0700, Pavel Panchekha 
> > > > > > > > > wrote:
> >
> > > > > > > > > > I'd like to write a shell for oranj similar to bpython. 
> > > > > > > > > > I've already
> > > > > > > > > > written a pygments parser for it, and writing completion 
> > > > > > > > > > shouldn't be
> > > > > > > > > > too hard. What else needs to be changed before I can get a 
> > > > > > > > > > full
> > > > > > > > > > bpython-esque shell for oranj? Is there anything in curses 
> > > > > > > > > > to fiddle
> > > > > > > > > > with, for example? (I tried just replacing PythonLexer with
> > > > > > > > > > OranjLexer, but it doesn't seem to work)
> >
> > > > > > > > > > Oranj:http://github.com/pavpanchekha/oranj/tree/master
> > > > > > > > > > OranjLexer:http://dev.pocoo.org/projects/pygments/ticket/409
> >
> > > > > > > > > I tried downloading it and running it (seems it depends on 
> > > > > > > > > 2.6) but, since I
> > > > > > > > > didn't have readline built against my 2.6 build, it errored - 
> > > > > > > > > you try to import
> > > > > > > > > readline, pass on an ImportError and then refer to it anyway.
> >
> > > > > > > > > Anyway, so I've rebuilt my python2.6 and got it working.
> >
> > > > > > > > > It looks to me like you'd be best off using bpython pretty 
> > > > > > > > > much as-is and
> > > > > > > > > providing something similar to the "code" module for oranj, 
> > > > > > > > > i.e. a way of
> > > > > > > > > executing oranj code from any Python program. Here's how 
> > > > > > > > > bpython uses it:
> >
> > > > > > > > >     def push(self, s):
> > > > > > > > >         """Push a line of code onto the buffer so it can 
> > > > > > > > > process it all
> > > > > > > > >         at once when a code block ends"""
> > > > > > > > >         s = s.rstrip('\n')
> > > > > > > > >         self.buffer.append(s)
> >
> > > > > > > > >         try:
> > > > > > > > >             more = 
> > > > > > > > > self.interp.runsource("\n".join(self.buffer))
> > > > > > > > >         except SystemExit:
> > > > > > > > >             # Avoid a traceback on e.g. quit()
> > > > > > > > >             self.do_exit = True
> > > > > > > > >             return False
> >
> > > > > > > > >         if not more:
> > > > > > > > >             self.buffer = []
> >
> > > > > > > > >         return more
> >
> > > > > > > > > "self.interp" in this case is one of these:
> >
> > > > > > > > >     class Interpreter(code.InteractiveInterpreter):
> >
> > > > > > > > > So, if you can make a Python module that mimics the code 
> > > > > > > > > module (at least the
> > > > > > > > > part of it that bpython uses) then you should be able to swap 
> > > > > > > > > out the Python
> > > > > > > > > code module with your one, change the lexer it being used, do 
> > > > > > > > > your own
> > > > > > > > > autocompletion routines and everything should hopefully Just 
> > > > > > > > > Work.
> >
> > > > > > > > > You might also want to try to mimic the behaviour of 
> > > > > > > > > inspect.getargspec, since
> > > > > > > > > bpython uses that to show what arguments a function is 
> > > > > > > > > expecting.
> >
> > > > > > > > > I can't think of anything else right now, but if you have any 
> > > > > > > > > more questions
> > > > > > > > > feel free to ask. Also if you think you can make the 
> > > > > > > > > necessary changes to
> > > > > > > > > bpython and still keep it 100% compatible with its current 
> > > > > > > > > functionality (i.e.
> > > > > > > > > if you can make it so anyone could come along and plug in 
> > > > > > > > > their own module to
> > > > > > > > > make it work with some other language) then I'd be happy to 
> > > > > > > > > bring that
> > > > > > > > > upstream. Otherwise, you are of course encouraged to fork it. 
> > > > > > > > > :)
> >
> > > > > > > > > Good luck !
> >
> > > > > > --
> > > > > > Bob Farrell
> >
> > > > --
> > > > Bob Farrell
> >
> > --
> > Bob Farrell
> > 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"bpython" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/bpython?hl=en
-~----------~----~----~----~------~----~------~--~---

diff -r 169862f5ec16 bpython/cli.py
--- a/bpython/cli.py	Wed May 13 11:28:46 2009 -0400
+++ b/bpython/cli.py	Thu May 14 01:00:59 2009 +0100
@@ -262,7 +262,7 @@
         expr, attr = m.group(1, 3)
         obj = eval(expr, self.interp.locals)
 
-        s = language.get_obj_attrs(obj)
+        s = language.get_obj_attrs(obj, expr, attr)
         return s
         
     def cw(self):
@@ -1710,6 +1710,7 @@
         return
 
     tb = None
+    o = None
 
     try:
         o = curses.wrapper(main_curses)
@@ -1730,7 +1731,7 @@
         sys.exit(1)
 
 # Fake stdout data so everything's still visible after exiting
-    if OPTS.flush_output:
+    if OPTS.flush_output and o is not None:
         sys.stdout.write(o)
 
     sys.stdout.flush()
diff -r 169862f5ec16 bpython/oranj.py
--- a/bpython/oranj.py	Wed May 13 11:28:46 2009 -0400
+++ b/bpython/oranj.py	Thu May 14 01:00:59 2009 +0100
@@ -2,7 +2,7 @@
 
 # Temporary
 import sys
-sys.path.append("../../..")
+sys.path.append("../..")
 
 import src.interpreter as intp
 import src.libintp
diff -r 169862f5ec16 bpython/python.py
--- a/bpython/python.py	Wed May 13 11:28:46 2009 -0400
+++ b/bpython/python.py	Thu May 14 01:00:59 2009 +0100
@@ -2,6 +2,7 @@
 import code
 import traceback, sys, os
 import rlcompleter
+import types
 
 name = "Python"
 
@@ -97,9 +98,7 @@
 
 push_on_start = ['from bpython import _internal\n', 'help = _internal._help']
 
-def get_obj_attrs(obj):
-    f = open("/tmp/output", "a")
-    
+def get_obj_attrs(obj, expr, attr):
     type_ = type(obj)
     __getattribute__ = None
     __getattr__ = None
@@ -127,7 +126,7 @@
                 # XXX: This happens for e.g. built-in types
                 __getattribute__ = None
     # /Dark magic
-
+    matches = []
     try:
         matches = attr_lookup(obj, expr, attr)
     finally:
@@ -137,7 +136,6 @@
         if __getattr__ is not None:
             setattr(type_, '__getattr__', __getattr__)
         # /Dark magic
-        f.write(repr(matches) + "\n")
         return matches
 
 def attr_lookup(obj, expr, attr):

Reply via email to