Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix quarantine/ipy_editors.py #2640

Merged
merged 8 commits into from Mar 29, 2013
Merged

fix quarantine/ipy_editors.py #2640

merged 8 commits into from Mar 29, 2013

Conversation

rmcgibbo
Copy link
Contributor

@rmcgibbo rmcgibbo commented Dec 3, 2012

I wanted to use textmate with %ed, so I found this module. It needed a little work, but not too much.

fixes:

  • uses string formatting instead of some old old itpl module
  • doesn't use the deprecated ipyapi
  • fully pep8 compliant
  • better docstring

per @ellisonbg's commit three years ago that moved it into quarantine, I don't think this module should be actually removed from quarantine:

Moving extensions to either quarantine or deathrow.
When a module is moved to quarantine, it means that while we intend
to keep it, it is currently broken or sufficiently untested that it
can't be in the main IPython codebase. To be moved back into the main
IPython codebase a module must:

  1. Work fully.
  2. Have a test suite.
  3. Be a proper IPython extension and tie into the official APIs.
  4. Have members of the IPython dev team who are willing to maintain it.

When a module is moved to deathrow, it means that the code is either broken
and not worth repairing, deprecated, replaced by newer functionality,
or code that should be developed and maintained by a third party.

Since I've never used many of the editors -- and the code depends on the format in which they like their arguments when invoked from the shell -- I can't confirm that all the code works. (It does work for emacs, textmate and idle on osx). Also, it's not really clear how to test this module, since you would need to have all the editors installed.

But regardless, the current ipy_editors.py assuredly does not work, and the code in this PR works at least for some editors (on some platforms). So it's an improvement, no?

…instead of some old old 'itpl' module (1) doesn't use the deprecated ipyapi, (2) fully pep8 compliant, (3) better docstring
# We no longer bundle Itpl. If you update this module, you should use advanced
# string formatting instead.
from IPython.external.Itpl import itplns
from string import Template
Copy link
Member

Choose a reason for hiding this comment

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

For consistency, I'd be inclined to use str.format() with {file} style fields - I think people are more familiar with that than with string.Template. But that's open to discussion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure that's fine. I just used template because it required changing less code :)

You're probably right though. (I'd never heard of string.Template until I looked it up just for this)

@takluyver
Copy link
Member

Thanks. If it's going to be useful to people, though, it will need to come out of quarantine, because those modules aren't installed by default. We could remove some of the less popular editors for now (I've never even heard of Crimson edit or GNUclient, for example). Since it doesn't do anything without user intervention, it can't cause a regression, so I think it's OK not to have tested with every editor on the list.

I'd call the module IPython.lib.editorhooks, but others may have better ideas.

@rmcgibbo
Copy link
Contributor Author

rmcgibbo commented Dec 3, 2012

Oooh. didn't realize about the quarantine not actually being installed, since I was using setup.py develop (or maybe it's just cause I was in the IPython root directory or something). But that makes sense.

Yeah, I've never heard of the those editors either.

Sounds good to me.

@Carreau
Copy link
Member

Carreau commented Dec 3, 2012

Stupid question, the edit magic is different for qtconsole right?
Does this works with the qtconsole ?

Thanks !

@rmcgibbo
Copy link
Contributor Author

rmcgibbo commented Dec 3, 2012

I think so?

%edit
IPython will make a temporary file named: /var/folders/w-/w-Mzx3jVHj4b4e7QTU67UU+++TQ/-Tmp-/ipython_edit_BdSKED.py
No default editor available.
Specify a GUI text editor in the `IPythonWidget.editor` configurable to enable the %edit magic

Either this script should make this clear, or perhaps it should be able to hook into this system. After all, most of the editors that it references are gui apps.

@takluyver
Copy link
Member

Good point, @Carreau . Yes, ideally I'd like to see this support the Qt console as well. In practice, I don't know how easy that is, because of the frontend/kernel separation. As I understand it, when you call %edit in the Qt console, the contents of the file are transmitted to the frontend for it to open an editor. Obviously that's useful if your kernel isn't on the same machine as the frontend, but it means it's tricky for anything in the kernel to affect the editor.

@Carreau
Copy link
Member

Carreau commented Dec 14, 2012

So, do we move this out of quarantine ?
(qtconsole could be improved later)

@rmcgibbo
Copy link
Contributor Author

I will just improve the PR and fix it for the qtconsole.

@rmcgibbo
Copy link
Contributor Author

On second though, after banging my head against this for about an hour, I don't think I understand the qtconsole code well enough to do this.

Looking at the code on like 475 of IPython.frontend.qt.console.ipython_widget.py, it looks like it should be straightforward to set the editor and editor_line variables from an external function.

How do you get access to the active IPythonWidget at run time?

@rmcgibbo
Copy link
Contributor Author

There is some Travis issue:

======================================================================
2343ERROR: Failure: ImportError (Cannot import PySide >= 1.0.3 or PyQt4 >= 4.7)
2344----------------------------------------------------------------------
2345Traceback (most recent call last):
2346  File "/home/travis/virtualenv/python2.6/lib/python2.6/site-packages/nose/loader.py", line 390, in loadTestsFromName
2347    addr.filename, addr.module)
2348  File "/home/travis/virtualenv/python2.6/lib/python2.6/site-packages/nose/importer.py", line 39, in importFromPath
2349    return self.importFromDir(dir_path, fqname)
2350  File "/home/travis/virtualenv/python2.6/lib/python2.6/site-packages/nose/importer.py", line 86, in importFromDir
2351    mod = load_module(part_fqname, fh, filename, desc)
2352  File "/home/travis/virtualenv/python2.6/lib/python2.6/site-packages/IPython/lib/editorhooks.py", line 9, in <module>
2353    from IPython.frontend.qt.console import ipython_widget
2354  File "/home/travis/virtualenv/python2.6/lib/python2.6/site-packages/IPython/frontend/qt/console/ipython_widget.py", line 19, in <module>
2355    from IPython.external.qt import QtCore, QtGui
2356  File "/home/travis/virtualenv/python2.6/lib/python2.6/site-packages/IPython/external/qt.py", line 43, in <module>
2357    raise ImportError('Cannot import PySide >= 1.0.3 or PyQt4 >= 4.7')
2358ImportError: Cannot import PySide >= 1.0.3 or PyQt4 >= 4.7

@takluyver
Copy link
Member

You can't access that object from the kernel, because it's in the frontend. It is configurable, though - see the definitions at line 62

@rmcgibbo
Copy link
Contributor Author

My solution to getting run-time configurable %edit in the qtconsole is a bit of a hack, but it works (I tested emacs and textmate).

Basically, I modified ZMQInteractiveShell.edit to send, in addition to the filename and line number, the "template" string that specifies how to invoke Popen for that editor.

IPythonWidget._edit receives that template, and uses it instead of the configurable.

It seems a bit hacky to me. The problem is basically that the implementation in the TerminalInteractiveShell with the hooks and stuff is totally different than the qtconsole.

For instance, TerminalInteractiveShell has an editor instance variable, but ZMQInteractiveShell doesn't.

@takluyver
Copy link
Member

I think we need to have a more careful work through the code that implements %edit over ZMQ - at the moment, it's rather complex because there's an entirely separate configuration system for editing in the frontend.

In the meantime, I'd be inclined to merge this on the grounds that we shouldn't let aiming for perfection delay improvement. I'm a bit concerned about changing the messaging format to add editor_template, though. On the one hand, the contents of payload dictionaries aren't in the spec. On the other hand, there may well be clients like EIN that expect it to remain constant.

So, while I realise that it's going back on what I said before, I'm now inclined to leave the ZMQ-related changes out, and merge the rest of this. Any thoughts?

@ellisonbg
Copy link
Member

Let's not implement the %edit magic in a hacky way over zeromq. We have plans to do it right and should wait for that.

@@ -321,10 +321,16 @@ def edit(self, parameter_s='', last_call=['','']):
Copy link
Member

Choose a reason for hiding this comment

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

Let's back out the changes to this file.

@rmcgibbo
Copy link
Contributor Author

Okay. I agree with you guys that it's best not to try to do the %edit magic over zmq unless its going to be done "right", which this probably wasn't.

Those changes have been backed out.

"""

from IPython.core.error import TryNext
from IPython.frontend.qt.console import ipython_widget
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is needed now? It's causing problems for the test suite.

@bfroehle
Copy link
Contributor

I'd prefer if we could remove the requirement that the filename be in quotation marks. For example, just allow:

def emacs(exe=u'emacs'):
    install_editor(exe + u' +{line} {filename}')

This could be accomplished by first passing the filename through pipes.quote before substituting it into the command string. That is:

cmd = template.format(filename=pipes.quote(filename), line=line)

Since we are already changing the syntax, it'd be good to add this feature now.

@rmcgibbo
Copy link
Contributor Author

Good idea, @bfroehle. Done.

@Carreau
Copy link
Member

Carreau commented Mar 27, 2013

Reviving old thread. This seem to have only upsides, shoudl we merge it and take care of the remaining point (edit over zmq) later?

My vote : +1 for merging.

@minrk
Copy link
Member

minrk commented Mar 28, 2013

This makes sense to me - if @bfroehle agrees, I say merge.

@bfroehle
Copy link
Contributor

Looks fine to me, but perhaps there should be some help as to how to use this... For example, I guess that I'm supposed to run something like:

from IPython.lib.editorhooks import emacs
emacs()

Also it seems to be impossible to override your first setting because get_ipython().set_hook(...) adds to the end of the list of hooks. You could test this by something like emacs('emacs'); emacs('vi') and test that emacs opens when you call %edit. I'm not sure if this is actually a problem or is in any way easy to fix.

@minrk
Copy link
Member

minrk commented Mar 29, 2013

Yes, that's a bit of a weirdness about hooks in general. I think we can go ahead and merge this, then treat the fact that hooks cannot be replaced as a separate issue.

bfroehle added a commit that referenced this pull request Mar 29, 2013
fix quarantine/ipy_editors.py
@bfroehle bfroehle merged commit c810a36 into ipython:master Mar 29, 2013
@bfroehle
Copy link
Contributor

Merged! :)

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants