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

Class %hierarchy and graphiz %%dot magics #1854

Closed
wants to merge 2 commits into from

Conversation

tkf
Copy link
Contributor

@tkf tkf commented Jun 4, 2012

This PR introduces two magics.

First magic is %hierarchy. This magic command draws hierarchy of given class or the class of given instance. For example, the following shows class hierarchy of currently running IPython shell.

%hierarchy get_ipython()

Second magic is %%dot. You can write graphiz dot language in a cell using this magic. Example:

%%dot -- -Kfdp
digraph G {
    a->b; b->c; c->d; d->b; d->a;
}

I have two concerns:

  • The function run_dot, which runs the dot command to produce the figure, is heavily borrowed from Sphinx extension. I am not sure if there are any copyright problem.
  • I used self.shell.display_formatter.format to get "full path" (something like IPython.zmq.zmqshell.ZMQInteractiveShell) of a class. Maybe there is a better way to do that.

tkf added 2 commits June 3, 2012 23:39
%hierarchy magic draws class hierarchy of a given class or class of a
given instance.  It relies on Sphinx's inheritance_diagram extension.
@takluyver
Copy link
Member

It's great to see people making creative use of the magic system, but this does raise a question about how much we want to ship as part of IPython. We do have an extension system, and my inclination is that this belongs as a separate extension. Others may disagree, though.

Your concerns:

  • Sphinx is BSD licensed, and so long as that covers whichever extension it's from, we can borrow their code. We should include a copyright notice from Sphinx, though, and a note that we're using it under a BSD license.
  • klass.__name__ and klass.__module__ seem to cover it.

@tkf
Copy link
Contributor Author

tkf commented Jun 7, 2012

Can these magic commands go into IPython? I will fix what you suggested if it is likely. I think drawing class hierarchy is pretty general so having it in IPython is good. %%dot command is kind of a side effect of implementing the %hierarchy command and I guess it won't hurt having it as a extension.

@takluyver
Copy link
Member

I've posted on the mailing list about it, and how we can make it easier to find third party extensions. We'll see if anyone else weighs in.

My own feeling is that it would be best to do this as a separate extension for now, so that you can easily work on it and make more frequent updates than IPython's release schedule. Installing an extension is very simple with the %install_ext command. If %hierarchy becomes widely used, we could look at including it to save people that installation step.

@tkf
Copy link
Contributor Author

tkf commented Jun 7, 2012

Thanks. Yea, maybe it should be a separate extension.

@ellisonbg
Copy link
Member

I am probably +1 on these being separate extensions. But we are discussing on the list where such extensions should be hosted.

@takluyver
Copy link
Member

The feeling on the list is that you can use gist.github.com to host extensions (or, of course, set up a regular repository on Github/Bitbucket/etc.). Then we can list them in an index - I've set up a draft here: http://wiki.ipython.org/Extensions_Index

The conversation's still going on on the mailing list, so feel free to join in. http://mail.scipy.org/mailman/listinfo/ipython-dev

@tkf
Copy link
Contributor Author

tkf commented Jun 8, 2012

I changed them into a separate extension.
https://github.com/tkf/ipython-hierarchymagic

@tkf tkf closed this Jun 8, 2012
@takluyver
Copy link
Member

Great, thanks. We'll keep you updated on anything we decide about extensions in the future.

Would you like to add the extension to the index? It's a wiki, so just create an account and edit the page, adding a section like that for physics.
http://wiki.ipython.org/Extensions_Index

@tkf
Copy link
Contributor Author

tkf commented Jun 9, 2012

Thanks for the mention. I edited the page.

@takluyver
Copy link
Member

Thanks. Can I suggest that you manipulate the screenshot in an image editor to put the two cells side by side? That would make better use of the space on the page.

@tkf
Copy link
Contributor Author

tkf commented Jun 10, 2012

I just removed the screenshot. I thought it was small enough. Maybe I will put the side-by-side one sometime later.

@takluyver
Copy link
Member

I think it's OK to include screenshots, I was just thinking that there's width to spare, while we don't want to make people scroll too much.

@takluyver
Copy link
Member

(Not that there's much need to scroll, but I hope one day we'll have 100 extensions on that page ;-) )

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

3 participants