##// END OF EJS Templates
use relative filename in latex and dvips commands
use relative filename in latex and dvips commands

File last commit:

r27216:9e1981ea
r27702:df3b1605
Show More
config.py
187 lines | 7.5 KiB | text/x-python | PythonLexer
Fernando Perez
Create core.magics.config according to new API.
r6961 """Implementation of configuration-related magic functions.
"""
#-----------------------------------------------------------------------------
# Copyright (c) 2012 The IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# Stdlib
import re
# Our own packages
from IPython.core.error import UsageError
Fernando Perez
Renamed @register_magics to @magics_class to avoid confusion....
r6973 from IPython.core.magic import Magics, magics_class, line_magic
Pierre Gerold
Replace all import of IPython.utils.warn module
r22092 from logging import error
Fernando Perez
Create core.magics.config according to new API.
r6961
#-----------------------------------------------------------------------------
# Magic implementation classes
#-----------------------------------------------------------------------------
Matthias Bussonnier
Fix more escape sequences
r24452 reg = re.compile(r'^\w+\.\w+$')
Fernando Perez
Renamed @register_magics to @magics_class to avoid confusion....
r6973 @magics_class
Fernando Perez
Create core.magics.config according to new API.
r6961 class ConfigMagics(Magics):
def __init__(self, shell):
super(ConfigMagics, self).__init__(shell)
self.configurables = []
@line_magic
def config(self, s):
"""configure IPython
%config Class[.trait=value]
This magic exposes most of the IPython config system. Any
Configurable class should be able to be configured with the simple
line::
%config Class.trait=value
Where `value` will be resolved in the user's namespace, if it is an
expression or variable name.
Examples
--------
To see what classes are available for config, pass no arguments::
In [1]: %config
Available objects for config:
AliasManager
DisplayFormatter
Nikita Kniazev
Preserve function/method identity in magic decorators...
r27102 HistoryManager
IPCompleter
LoggingMagics
MagicsManager
OSMagics
PrefilterManager
ScriptMagics
TerminalInteractiveShell
Fernando Perez
Create core.magics.config according to new API.
r6961
To view what is configurable on a given class, just pass the class
name::
In [2]: %config IPCompleter
Nikita Kniazev
Preserve function/method identity in magic decorators...
r27102 IPCompleter(Completer) options
----------------------------
IPCompleter.backslash_combining_completions=<Bool>
Enable unicode completions, e.g. \\alpha<tab> . Includes completion of latex
commands, unicode names, and expanding unicode characters back to latex
commands.
Fernando Perez
Create core.magics.config according to new API.
r6961 Current: True
Nikita Kniazev
Preserve function/method identity in magic decorators...
r27102 IPCompleter.debug=<Bool>
Enable debug for the Completer. Mostly print extra information for
experimental jedi integration.
Current: False
IPCompleter.greedy=<Bool>
Activate greedy completion
Matthias Bussonnier
Remove deprecated banner parameter...
r27216 PENDING DEPRECATION. this is now mostly taken care of with Jedi.
Nikita Kniazev
Preserve function/method identity in magic decorators...
r27102 This will enable completion on elements of lists, results of function calls, etc.,
but can be unsafe because the code is actually evaluated on TAB.
Fernando Perez
Create core.magics.config according to new API.
r6961 Current: False
Nikita Kniazev
Preserve function/method identity in magic decorators...
r27102 IPCompleter.jedi_compute_type_timeout=<Int>
Experimental: restrict time (in milliseconds) during which Jedi can compute types.
Set to 0 to stop computing types. Non-zero value lower than 100ms may hurt
performance by preventing jedi to build its cache.
Current: 400
IPCompleter.limit_to__all__=<Bool>
DEPRECATED as of version 5.0.
Fernando Perez
Create core.magics.config according to new API.
r6961 Instruct the completer to use __all__ for the completion
Specifically, when completing on ``object.<tab>``.
When True: only those names in obj.__all__ will be included.
When False [default]: the __all__ attribute is ignored
Current: False
Nikita Kniazev
Preserve function/method identity in magic decorators...
r27102 IPCompleter.merge_completions=<Bool>
Whether to merge completion results into a single list
If False, only the completion results from the first non-empty
completer will be returned.
Current: True
IPCompleter.omit__names=<Enum>
Instruct the completer to omit private method names
Specifically, when completing on ``object.<tab>``.
When 2 [default]: all names that start with '_' will be excluded.
When 1: all 'magic' names (``__foo__``) will be excluded.
When 0: nothing will be excluded.
Choices: any of [0, 1, 2]
Current: 2
IPCompleter.profile_completions=<Bool>
If True, emit profiling data for completion subsystem using cProfile.
Current: False
IPCompleter.profiler_output_dir=<Unicode>
Template for path at which to output profile data for completions.
Current: '.completion_profiles'
IPCompleter.use_jedi=<Bool>
Experimental: Use Jedi to generate autocompletions. Default to True if jedi
is installed.
Current: True
Fernando Perez
Create core.magics.config according to new API.
r6961
but the real use is in setting values::
In [3]: %config IPCompleter.greedy = True
and these values are read from the user_ns if they are variables::
In [4]: feeling_greedy=False
In [5]: %config IPCompleter.greedy = feeling_greedy
"""
Min RK
update dependency imports...
r21253 from traitlets.config.loader import Config
Fernando Perez
Create core.magics.config according to new API.
r6961 # some IPython objects are Configurable, but do not yet have
# any configurable traits. Exclude them from the effects of
# this magic, as their presence is just noise:
Sang Min Park
Sort and unique %config results
r23617 configurables = sorted(set([ c for c in self.shell.configurables
if c.__class__.class_traits(config=True)
]), key=lambda x: x.__class__.__name__)
Fernando Perez
Create core.magics.config according to new API.
r6961 classnames = [ c.__class__.__name__ for c in configurables ]
line = s.strip()
if not line:
# print available configurable names
Thomas Kluyver
Convert print statements to print function calls...
r13348 print("Available objects for config:")
Fernando Perez
Create core.magics.config according to new API.
r6961 for name in classnames:
Nikita Kniazev
Preserve function/method identity in magic decorators...
r27102 print(" ", name)
Fernando Perez
Create core.magics.config according to new API.
r6961 return
elif line in classnames:
# `%config TerminalInteractiveShell` will print trait info for
# TerminalInteractiveShell
c = configurables[classnames.index(line)]
cls = c.__class__
help = cls.class_get_help(c)
# strip leading '--' from cl-args:
help = re.sub(re.compile(r'^--', re.MULTILINE), '', help)
Thomas Kluyver
Convert print statements to print function calls...
r13348 print(help)
Fernando Perez
Create core.magics.config according to new API.
r6961 return
Matthias BUSSONNIER
improve config line magic...
r10207 elif reg.match(line):
cls, attr = line.split('.')
return getattr(configurables[classnames.index(cls)],attr)
Fernando Perez
Create core.magics.config according to new API.
r6961 elif '=' not in line:
Matthias BUSSONNIER
improve config line magic...
r10207 msg = "Invalid config statement: %r, "\
"should be `Class.trait = value`."
MinRK
finish up PR #3116...
r10245
ll = line.lower()
for classname in classnames:
if ll == classname.lower():
msg = msg + '\nDid you mean %s (note the case)?' % classname
break
Matthias BUSSONNIER
improve config line magic...
r10207
raise UsageError( msg % line)
Fernando Perez
Create core.magics.config according to new API.
r6961
# otherwise, assume we are setting configurables.
# leave quotes on args when splitting, because we want
# unquoted args to eval in user_ns
cfg = Config()
linar-jether
Fix locals collisions with shell variables...
r25530 exec("cfg."+line, self.shell.user_ns, locals())
Fernando Perez
Create core.magics.config according to new API.
r6961
for configurable in configurables:
try:
configurable.update_config(cfg)
except Exception as e:
error(e)