[IPython-dev] Add new commandline option from profile

MinRK benjaminrk at gmail.com
Sun Jun 3 15:13:20 EDT 2012


On Sat, Jun 2, 2012 at 11:45 AM, Arnaud Gardelein <arnaud at oscopy.org> wrote:

> Hi all,
>
> The new ipython configuration system allows to customize for particular
> application three classes, InteractiveShell, PrefilterManager and
> AliasManager all subclasses of Configurable as described in the
> documentation. Each option from those classes are settable from argument
> of ipython command.
> Assuming a new configurable object described in a ipython 'foo' profile:
>
> from IPython.config.configurable import Configurable
> from IPython.utils.traitlets import Int, Float, Unicode, Bool
> class Foo(Configurable):
>    name = Unicode(u'Foo')
>    bar = Bool(False, config=True)
>
> How to make the boolean 'bar' also an argument settable from ipython
> command with a '--bar' or '--no-bar' when invoking ipython
> --profile=foo?
>

You can't do precisely this, because the command-line args are fully parsed
by the time the profile is known (they are used to determine the profile!).

What is your *actual* goal here, because I doubt that it is to configure a
transient object in your config file that will be deleted immediately and
not importable, which would be the case if defined in a config file.

Note that there is a difference between "all configurables" being
accessible and the short '--foo' flags.  Those are manually defined, and
only for a short list of common options.  But *all* configurables are
available in the form:

    --Class.trait=foo

If your goal is to make a particular class of yours configurable, you can
set its options in this way, and then the only thing you need to do is pass
the IPython instance's config object to your constructor:


ipython --Foo.bar=True

In [1]: from IPython.config.configurable import Configurable
In [2]: from IPython.utils.traitlets import Bool

In [3]: class Foo(Configurable):
   ...:     bar = Bool(False, config=True)

In [4]: foo = Foo(config=get_ipython().config)

In [5]: foo.bar
Out[5]: True

-MinRK


>
> Thanks,
>
> Arnaud.
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20120603/da583d0c/attachment-0001.html>


More information about the IPython-dev mailing list