tinyerp / erppeek

A versatile tool for Odoo / OpenERP. *** Forked as Odooly ⟶
https://github.com/tinyerp/odooly
Other
171 stars 99 forks source link

IPython integration #51

Open guaka opened 10 years ago

guaka commented 10 years ago

I'm very happy I just bumped into this project. I'm also a very happy IPython user.

Is there a way to get erppeek inside ipython? (or vice versa)

florentx commented 10 years ago

I have no idea, since I am not an IPython user myself. I welcome your own feedback.

guaka commented 10 years ago

I started hacking towards this, by copying main() into another file and adapting it so that it returns global_vars. If I manage to get these global_vars in the IPython environment it would be quite workable.

Another approach is to let erppeek check for the presence of IPython and in that case use that as an alternative to erppeek._interact().

takluyver commented 10 years ago

I think what you want is something like this:

try:
    import IPython
    return IPython.start_ipython(user_ns=global_vars)
except ImportError:
   pass # Continue to set up a basic shell if IPython isn't installed
guaka commented 10 years ago

Excellent! It worked after I added a line for handling argv.

    try:
        import IPython
        sys.argv = [sys.argv[0]]
        return IPython.start_ipython(user_ns=global_vars)
    except ImportError:
        pass # Continue to set up a basic shell if IPython isn't installed
takluyver commented 10 years ago

You can also pass argv=sys.argv[:1] into start_ipython() - that will prevent IPython from trying to parse your programs arguments, but if the user inspects sys.argv, they'll still see the original value.

guaka commented 10 years ago

Nice, but unfortunately erppeek exits without any feedback when I try IPython.start_ipython(user_ns=global_vars, argv=sys.argv[:1])

takluyver commented 10 years ago

Oh, sorry, it should be just argv=[] (i.e. an empty list).

guaka commented 10 years ago

@florentx you could replace the [question] label with the [enhancement] label :)

florentx commented 10 years ago

Please confirm that 1.6 gives enough flexibility for IPython.

I have posted details on pull request #62 ... You can contribute an addition to the documentation, if it works.