From ee1b3887f12756d5d5f99e094500c23c1bc657f2 2012-11-24 16:48:27 From: Thomas Kluyver Date: 2012-11-24 16:48:27 Subject: [PATCH] Only include inheritance diagram where it's useful. --- diff --git a/IPython/config/configurable.py b/IPython/config/configurable.py index f2bee7e..2d3e3f4 100644 --- a/IPython/config/configurable.py +++ b/IPython/config/configurable.py @@ -2,6 +2,11 @@ """ A base class for objects that are configurable. +Inheritance diagram: + +.. inheritance-diagram:: IPython.config.configurable + :parts: 3 + Authors: * Brian Granger diff --git a/IPython/config/loader.py b/IPython/config/loader.py index 20499d7..12cf91f 100644 --- a/IPython/config/loader.py +++ b/IPython/config/loader.py @@ -1,5 +1,10 @@ """A simple configuration system. +Inheritance diagram: + +.. inheritance-diagram:: IPython.config.loader + :parts: 3 + Authors ------- * Brian Granger diff --git a/IPython/core/formatters.py b/IPython/core/formatters.py index f964501..8e930b7 100644 --- a/IPython/core/formatters.py +++ b/IPython/core/formatters.py @@ -1,6 +1,10 @@ # -*- coding: utf-8 -*- """Display formatters. +Inheritance diagram: + +.. inheritance-diagram:: IPython.core.formatters + :parts: 3 Authors: diff --git a/IPython/core/magic_arguments.py b/IPython/core/magic_arguments.py index 15e0ebb..88afb78 100644 --- a/IPython/core/magic_arguments.py +++ b/IPython/core/magic_arguments.py @@ -37,6 +37,11 @@ arguments:: -o OPTION, --option OPTION An optional argument. +Inheritance diagram: + +.. inheritance-diagram:: IPython.core.magic_arguments + :parts: 3 + ''' #----------------------------------------------------------------------------- # Copyright (C) 2010-2011, IPython Development Team. diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index d9d83c4..203c78b 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -59,6 +59,11 @@ ColorSchemeTable class. Currently the following exist: You can implement other color schemes easily, the syntax is fairly self-explanatory. Please send back new schemes you develop to the author for possible inclusion in future releases. + +Inheritance diagram: + +.. inheritance-diagram:: IPython.core.ultratb + :parts: 3 """ #***************************************************************************** diff --git a/IPython/lib/demo.py b/IPython/lib/demo.py index 142bdd8..6b9a1c5 100644 --- a/IPython/lib/demo.py +++ b/IPython/lib/demo.py @@ -1,6 +1,3 @@ -from __future__ import unicode_literals - - """Module for interactive demos using IPython. This module implements a few classes for running Python scripts interactively @@ -10,7 +7,7 @@ control to IPython. Provided classes -================ +---------------- The classes are (see their docstrings for further details): @@ -33,9 +30,13 @@ The classes are (see their docstrings for further details): - ClearDemo, ClearIPDemo: mixin-enabled versions of the Demo and IPythonDemo classes. +Inheritance diagram: + +.. inheritance-diagram:: IPython.lib.demo + :parts: 3 Subclassing -=========== +----------- The classes here all include a few methods meant to make customization by subclassing more convenient. Their docstrings below have some more details: @@ -50,7 +51,7 @@ subclassing more convenient. Their docstrings below have some more details: Operation -========= +--------- The file is run in its own empty namespace (though you can pass it a string of arguments as if in a command line environment, and it will see those as @@ -123,47 +124,51 @@ an IPython session, and type:: and then follow the directions. Example -======= +------- The following is a very simple example of a valid demo file. -#################### EXAMPLE DEMO ############################### -'''A simple interactive demo to illustrate the use of IPython's Demo class.''' +:: -print 'Hello, welcome to an interactive IPython demo.' + #################### EXAMPLE DEMO ############################### + '''A simple interactive demo to illustrate the use of IPython's Demo class.''' -# The mark below defines a block boundary, which is a point where IPython will -# stop execution and return to the interactive prompt. The dashes are actually -# optional and used only as a visual aid to clearly separate blocks while -# editing the demo code. -# stop + print 'Hello, welcome to an interactive IPython demo.' -x = 1 -y = 2 + # The mark below defines a block boundary, which is a point where IPython will + # stop execution and return to the interactive prompt. The dashes are actually + # optional and used only as a visual aid to clearly separate blocks while + # editing the demo code. + # stop -# stop + x = 1 + y = 2 -# the mark below makes this block as silent -# silent + # stop -print 'This is a silent block, which gets executed but not printed.' + # the mark below makes this block as silent + # silent -# stop -# auto -print 'This is an automatic block.' -print 'It is executed without asking for confirmation, but printed.' -z = x+y + print 'This is a silent block, which gets executed but not printed.' -print 'z=',x + # stop + # auto + print 'This is an automatic block.' + print 'It is executed without asking for confirmation, but printed.' + z = x+y -# stop -# This is just another normal block. -print 'z is now:', z + print 'z=',x -print 'bye!' -################### END EXAMPLE DEMO ############################ + # stop + # This is just another normal block. + print 'z is now:', z + + print 'bye!' + ################### END EXAMPLE DEMO ############################ """ +from __future__ import unicode_literals + #***************************************************************************** # Copyright (C) 2005-2006 Fernando Perez. # diff --git a/IPython/lib/irunner.py b/IPython/lib/irunner.py index a93e68c..de4a63b 100755 --- a/IPython/lib/irunner.py +++ b/IPython/lib/irunner.py @@ -18,16 +18,14 @@ contributed on the ipython-user list: http://mail.scipy.org/pipermail/ipython-user/2006-May/003539.html - -NOTES: +Notes +----- - This module requires pexpect, available in most linux distros, or which can - be downloaded from - - http://pexpect.sourceforge.net + be downloaded from http://pexpect.sourceforge.net - Because pexpect only works under Unix or Windows-Cygwin, this has the same - limitations. This means that it will NOT work under native windows Python. + limitations. This means that it will NOT work under native windows Python. """ from __future__ import print_function diff --git a/IPython/lib/pretty.py b/IPython/lib/pretty.py index c4cd9b0..c8d71aa 100644 --- a/IPython/lib/pretty.py +++ b/IPython/lib/pretty.py @@ -1,105 +1,107 @@ # -*- coding: utf-8 -*- """ - pretty - ~~ +Python advanced pretty printer. This pretty printer is intended to +replace the old `pprint` python module which does not allow developers +to provide their own pretty print callbacks. - Python advanced pretty printer. This pretty printer is intended to - replace the old `pprint` python module which does not allow developers - to provide their own pretty print callbacks. +This module is based on ruby's `prettyprint.rb` library by `Tanaka Akira`. - This module is based on ruby's `prettyprint.rb` library by `Tanaka Akira`. +Example Usage +------------- - Example Usage - ============= +To directly print the representation of an object use `pprint`:: - To directly print the representation of an object use `pprint`:: + from pretty import pprint + pprint(complex_object) - from pretty import pprint - pprint(complex_object) +To get a string of the output use `pretty`:: - To get a string of the output use `pretty`:: + from pretty import pretty + string = pretty(complex_object) - from pretty import pretty - string = pretty(complex_object) +Extending +--------- - Extending - ========= +The pretty library allows developers to add pretty printing rules for their +own objects. This process is straightforward. All you have to do is to +add a `_repr_pretty_` method to your object and call the methods on the +pretty printer passed:: - The pretty library allows developers to add pretty printing rules for their - own objects. This process is straightforward. All you have to do is to - add a `_repr_pretty_` method to your object and call the methods on the - pretty printer passed:: + class MyObject(object): - class MyObject(object): - - def _repr_pretty_(self, p, cycle): - ... + def _repr_pretty_(self, p, cycle): + ... - Depending on the python version you want to support you have two - possibilities. The following list shows the python 2.5 version and the - compatibility one. +Depending on the python version you want to support you have two +possibilities. The following list shows the python 2.5 version and the +compatibility one. - Here the example implementation of a `_repr_pretty_` method for a list - subclass for python 2.5 and higher (python 2.5 requires the with statement - __future__ import):: +Here the example implementation of a `_repr_pretty_` method for a list +subclass for python 2.5 and higher (python 2.5 requires the with statement +__future__ import):: - class MyList(list): + class MyList(list): - def _repr_pretty_(self, p, cycle): - if cycle: - p.text('MyList(...)') - else: - with p.group(8, 'MyList([', '])'): - for idx, item in enumerate(self): - if idx: - p.text(',') - p.breakable() - p.pretty(item) - - The `cycle` parameter is `True` if pretty detected a cycle. You *have* to - react to that or the result is an infinite loop. `p.text()` just adds - non breaking text to the output, `p.breakable()` either adds a whitespace - or breaks here. If you pass it an argument it's used instead of the - default space. `p.pretty` prettyprints another object using the pretty print - method. - - The first parameter to the `group` function specifies the extra indentation - of the next line. In this example the next item will either be not - breaked (if the items are short enough) or aligned with the right edge of - the opening bracked of `MyList`. - - If you want to support python 2.4 and lower you can use this code:: - - class MyList(list): - - def _repr_pretty_(self, p, cycle): - if cycle: - p.text('MyList(...)') - else: - p.begin_group(8, 'MyList([') + def _repr_pretty_(self, p, cycle): + if cycle: + p.text('MyList(...)') + else: + with p.group(8, 'MyList([', '])'): for idx, item in enumerate(self): if idx: p.text(',') p.breakable() p.pretty(item) - p.end_group(8, '])') - If you just want to indent something you can use the group function - without open / close parameters. Under python 2.5 you can also use this - code:: +The `cycle` parameter is `True` if pretty detected a cycle. You *have* to +react to that or the result is an infinite loop. `p.text()` just adds +non breaking text to the output, `p.breakable()` either adds a whitespace +or breaks here. If you pass it an argument it's used instead of the +default space. `p.pretty` prettyprints another object using the pretty print +method. - with p.indent(2): - ... +The first parameter to the `group` function specifies the extra indentation +of the next line. In this example the next item will either be not +breaked (if the items are short enough) or aligned with the right edge of +the opening bracked of `MyList`. + +If you want to support python 2.4 and lower you can use this code:: + + class MyList(list): + + def _repr_pretty_(self, p, cycle): + if cycle: + p.text('MyList(...)') + else: + p.begin_group(8, 'MyList([') + for idx, item in enumerate(self): + if idx: + p.text(',') + p.breakable() + p.pretty(item) + p.end_group(8, '])') + +If you just want to indent something you can use the group function +without open / close parameters. Under python 2.5 you can also use this +code:: + + with p.indent(2): + ... + +Or under python2.4 you might want to modify ``p.indentation`` by hand but +this is rather ugly. + +Inheritance diagram: - Or under python2.4 you might want to modify ``p.indentation`` by hand but - this is rather ugly. +.. inheritance-diagram:: IPython.lib.pretty + :parts: 3 - :copyright: 2007 by Armin Ronacher. - Portions (c) 2009 by Robert Kern. - :license: BSD License. +:copyright: 2007 by Armin Ronacher. + Portions (c) 2009 by Robert Kern. +:license: BSD License. """ from __future__ import with_statement from contextlib import contextmanager diff --git a/IPython/parallel/error.py b/IPython/parallel/error.py index 13c3928..b289a58 100644 --- a/IPython/parallel/error.py +++ b/IPython/parallel/error.py @@ -2,6 +2,11 @@ """Classes and functions for kernel related errors and exceptions. +Inheritance diagram: + +.. inheritance-diagram:: IPython.parallel.error + :parts: 3 + Authors: * Brian Granger diff --git a/IPython/utils/text.py b/IPython/utils/text.py index b53f826..86d52a1 100644 --- a/IPython/utils/text.py +++ b/IPython/utils/text.py @@ -1,6 +1,11 @@ # encoding: utf-8 """ Utilities for working with strings and text. + +Inheritance diagram: + +.. inheritance-diagram:: IPython.utils.text + :parts: 3 """ #----------------------------------------------------------------------------- diff --git a/IPython/utils/traitlets.py b/IPython/utils/traitlets.py index 2f0ebe2..21764e7 100644 --- a/IPython/utils/traitlets.py +++ b/IPython/utils/traitlets.py @@ -28,6 +28,11 @@ We choose to create this module because we need these capabilities, but we need them to be pure Python so they work in all Python implementations, including Jython and IronPython. +Inheritance diagram: + +.. inheritance-diagram:: IPython.utils.traitlets + :parts: 3 + Authors: * Brian Granger diff --git a/docs/sphinxext/apigen.py b/docs/sphinxext/apigen.py index 6ae1921..e68f94d 100644 --- a/docs/sphinxext/apigen.py +++ b/docs/sphinxext/apigen.py @@ -219,11 +219,6 @@ class ApiDocWriter(object): chap_title = ':mod:`' + uri_short + '`' ad += chap_title + '\n' + self.rst_section_levels[1] * len(chap_title) - if len(classes): - ad += '\nInheritance diagram for ``%s``:\n\n' % uri - ad += '.. inheritance-diagram:: %s \n' % uri - ad += ' :parts: 3\n' - ad += '\n.. automodule:: ' + uri + '\n' ad += '\n.. currentmodule:: ' + uri + '\n' multi_class = len(classes) > 1