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

%config magic #923

Merged
merged 10 commits into from Oct 29, 2011
Merged

%config magic #923

merged 10 commits into from Oct 29, 2011

Conversation

minrk
Copy link
Member

@minrk minrk commented Oct 24, 2011

should close #903

Adds %config magic, which allows %config Foo.bar = 5 configuration of IPython configurables.

The Magic class keeps a list of configurables which will be updated by the change, so any objects that should be accessible to this magic should be appended to shell.configurables. I started with everything I saw as configurable in InteractiveShell.

Usage

Use just %config to see what classes are available, and %config Class to get the trait info for that class.

When setting values via%config Class.trait = value It is evaluated with user_ns in globals, so you can do arbitrary things like:

In [4]: default = 'png'

In [5]: %config InlineBackendConfig.figure_format = raw_input('what figure format should we use? ') or default

Of course, this magic reveals just how much we don't use traits/config properly. Almost everything is attached to the InteractiveShell object, and has an effect exactly once during an init_foo() method, rather than allowing config propagation via _trait_changed() methods.

For instance, IPCompleter has an omit__names attribute, but the configurable is InteractiveShell.readline_omit__names, which is clearly wrong.

We've done a good job with config in new code, but I think existing code needs a pretty hefty pass to get configurables attached to the right objects, and getting logic like %colors into shell._colors_changed.

@minrk
Copy link
Member Author

minrk commented Oct 25, 2011

Moving discussion from #903 to here (PR), pinging @fperez and @ellisonbg to keep conversation updates linked up.

I've renamed InlineBackendConfig -> InlineBackend (with warning on old name, for any of those still lingering on it).

Here's a quick question: Should we switch the inline figure default back to svg from png? PNG is the default, because it's a good deal sharper, and for figure snobs it does look better than SVG. However, it is less capable, in that the SVG+XHTML export will lack figures in the default state (see #735). Since it's easy to change the figure format, maybe we should change the default to the more capable one, and let the nicer-looking format be configurable?

A possible issue would be that the svg dpi is tuned such that svg and png figures are the same size in the QtConsole, but I find that they are not the same in a browser using the notebook, and the png size is more sensible. It is also true that png is just a much more portable and reliable (if not editable) format.

@minrk
Copy link
Member Author

minrk commented Oct 25, 2011

I updated some docs, to cover using the %config magic to configure the inline backend, and moved the completer configurables to the completer class, where they belong.

@ellisonbg
Copy link
Member

@fperez will probably have thoughts on what image format should be default. I am fine moving to png and it does look nicer in many cases. Also, having it as the default will bring png bugs in matplotlib to light more readily.

There may be some browser tuning we can/should do to make the figure sizes of png/svg the same.

@minrk
Copy link
Member Author

minrk commented Oct 25, 2011

@ellisonbg - I should clarify. The default is png, because it looks better. I'm wondering if we should change it to svg because some functionality (xhtml export) is unavailable with the default.

@fperez
Copy link
Member

fperez commented Oct 25, 2011

On Tue, Oct 25, 2011 at 2:14 PM, Min RK
reply@reply.github.com
wrote:

@ellisonbg - I should clarify.  The default is png, because it looks better.  I'm wondering if we should change it to svg because some functionality (xhtml export) is unavailable with the default.

We switched from svg to png a while back in deference to the
qtconsole, b/c the Qt svg renderer doesn't implement the full spec,
only a subset. Mpl figures do use features beyond this subset, such
as path clipping, and therefore the figures could have ugly artifacts
in the console.

Browsers tend to have much more robust svg support, so I could see
reconsidering this decision and simply having users configure their
qtconsole app separately if they so desire...

@ellisonbg
Copy link
Member

@minrk: oops, that was a brain typo, I do realize the default in png. I am fine moving to svg given the support in browsers is much better than the qt console.

@fperez
Copy link
Member

fperez commented Oct 28, 2011

@minrk, note that I'm getting a failure in the test suite when I merge this onto master:

======================================================================
FAIL: Doctest: IPython.core.magic.Magic.magic_config
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/fperez/usr/lib/python2.6/site-packages/IPython/testing/plugin/ipdoctest.py", line 265, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for IPython.core.magic.Magic.magic_config
  File "/home/fperez/usr/lib/python2.6/site-packages/IPython/core/magic.py", line 3627, in magic_config

----------------------------------------------------------------------
File "/home/fperez/usr/lib/python2.6/site-packages/IPython/core/magic.py", line 3657, in IPython.core.magic.Magic.magic_config
Failed example:
    get_ipython().magic(u"config IPCompleter")
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python2.6/doctest.py", line 1253, in __run
        compileflags, 1) in test.globs
      File "<doctest IPython.core.magic.Magic.magic_config[1]>", line 1, in <module>
        get_ipython().magic(u"config IPCompleter")
      File "/home/fperez/usr/lib/python2.6/site-packages/IPython/core/interactiveshell.py", line 1998, in magic
        result = fn(magic_args)
      File "/home/fperez/usr/lib/python2.6/site-packages/IPython/core/magic.py", line 3707, in magic_config
        help = re.sub(r'^\-\-', '', help, flags=re.MULTILINE)
    TypeError: sub() got an unexpected keyword argument 'flags'

>>  raise self.failureException(self.format_failure(<StringIO.StringIO instance at 0x4482cb0>.getvalue()))

Do you see it too? If not, we can try to debug it together on my box... Problem seen on python 2.6, ubuntu 10.10, 64 bit.

@fperez
Copy link
Member

fperez commented Oct 28, 2011

ps - I think if you want to pass flags in a 2.6-compatible manner to a regexp, you must compile it and then use the .sub() method of the compiled regexp. In 2.6, the re module doesn't support flags in the methods. The signature for re.sub changed:

2.6:

re.sub(pattern, repl, string[, count])

2.7:

re.sub(pattern, repl, string[, count, flags])

@minrk
Copy link
Member Author

minrk commented Oct 28, 2011

good catch, I didn't realize it had changed. I'll compile&call.

@minrk
Copy link
Member Author

minrk commented Oct 28, 2011

regex is now compiled, should work on 2.6.

@fperez
Copy link
Member

fperez commented Oct 28, 2011

Heads-up @minrk: this one popped a conflict after I just merged the read-only branch... Can you give it a quick rebase? I was about to work on it and saw the conflicts...

This method should be used whenever updating the config of an object.
It is useful for all configurables, not just Applications.
include deprecation warning on old name
it is a dict of instances, which are not allowed in config
also cleaned up %config and %pylab docstrings to be a little more sphinx-autogen friendly.
* InteractiveShell.readline_omit__names -> IPCompleter.omit__names
* InteractiveShell.readline_merge_completions -> IPCompleter.merge_completions

add test for IPCompleter.omit__names, which also covers IPCompleter
as a configurable.

update %config doctest to match, and replace Completer with IPCompleter
in TerminalIPythonApp.classes
@minrk
Copy link
Member Author

minrk commented Oct 29, 2011

rebased - tiny conflict with PR #921.

@fperez
Copy link
Member

fperez commented Oct 29, 2011

Looks good, ran lots of tests on 2.6 and 2.7, via screen and normal logins. After some initial weird glitching, that went away with a pyc cleanout, all looks good now so I think it's good to merge.

I'm going to leave the image default discussion to happen separately so we don't hold this PR forever, made #944 for that.

Merging now, thanks for the great work! This wil be very useful.

Final comment: adding mention of %config to the main configuration section in the docs is probably a good idea. Since that would be a docs-only patch, just go ahead and commit it any time if you get a chance (and if you can't do it now, let me know and I can take a crack at it later). But I'll merge the code now.

fperez added a commit that referenced this pull request Oct 29, 2011
New %config magic to interactively manipulate all configurables.

This allows users to type `%config Foo.bar = 5` to control any IPython configurable.

The Magic class keeps a list of configurables which will be updated by the change, so any objects that should be accessible to this magic should be appended to `shell.configurables`.  I started with everything I saw as configurable in InteractiveShell.

## Usage

Use just `%config` to see what classes are available, and `%config Class` to get the trait info for that class.

When setting values via` %config Class.trait = value` It is evaluated with user_ns in globals, so you can do arbitrary things like:

```python
In [4]: default = 'png'

In [5]: %config InlineBackendConfig.figure_format = raw_input('what figure format should we use? ') or default
```

## Note

This magic reveals just how much we *don't* use traits/config properly.  Almost everything is attached to the InteractiveShell object, and has an effect exactly once during an `init_foo()` method, rather than allowing config propagation via `_trait_changed()` methods.

For instance, IPCompleter has an `omit__names` attribute, but the configurable is `InteractiveShell.readline_omit__names`, which is clearly wrong.

We've done a good job with config in *new* code, but I think existing code needs a pretty hefty pass to get configurables attached to the right objects, and getting logic like `%colors` into `shell._colors_changed`.

Closes #903
@fperez fperez merged commit b725362 into ipython:master Oct 29, 2011
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
New %config magic to interactively manipulate all configurables.

This allows users to type `%config Foo.bar = 5` to control any IPython configurable.

The Magic class keeps a list of configurables which will be updated by the change, so any objects that should be accessible to this magic should be appended to `shell.configurables`.  I started with everything I saw as configurable in InteractiveShell.

## Usage

Use just `%config` to see what classes are available, and `%config Class` to get the trait info for that class.

When setting values via` %config Class.trait = value` It is evaluated with user_ns in globals, so you can do arbitrary things like:

```python
In [4]: default = 'png'

In [5]: %config InlineBackendConfig.figure_format = raw_input('what figure format should we use? ') or default
```

## Note

This magic reveals just how much we *don't* use traits/config properly.  Almost everything is attached to the InteractiveShell object, and has an effect exactly once during an `init_foo()` method, rather than allowing config propagation via `_trait_changed()` methods.

For instance, IPCompleter has an `omit__names` attribute, but the configurable is `InteractiveShell.readline_omit__names`, which is clearly wrong.

We've done a good job with config in *new* code, but I think existing code needs a pretty hefty pass to get configurables attached to the right objects, and getting logic like `%colors` into `shell._colors_changed`.

Closes ipython#903
Carreau added a commit to Carreau/ipykernel that referenced this pull request Jul 6, 2016
And InlineBackaedConfig was renamed in  0.12 (2011):

`ipython/ipython#923

So we can likely remove the warning.
martinRenou pushed a commit to ipython/matplotlib-inline that referenced this pull request Feb 11, 2021
And InlineBackaedConfig was renamed in  0.12 (2011):

`ipython/ipython#923

So we can likely remove the warning.
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.

Expose a magic to control config of the inline pylab backend
3 participants