Permalink
Browse files

Terminal IPython working with newapp

  • Loading branch information...
1 parent 649458a commit b1f3e467db73cec91fa99d8286244c58ce307133 @minrk committed May 28, 2011
View
@@ -101,18 +101,15 @@ def __init__(self, shell, config=None, **traits):
if self.hist_file == u'':
# No one has set the hist_file, yet.
- if shell.profile:
- histfname = 'history-%s' % shell.profile
- else:
- histfname = 'history'
- self.hist_file = os.path.join(shell.ipython_dir, histfname + '.sqlite')
+ histfname = 'history'
+ self.hist_file = os.path.join(shell.profile_dir.location, histfname + '.sqlite')
try:
self.init_db()
except sqlite3.DatabaseError:
if os.path.isfile(self.hist_file):
# Try to move the file out of the way.
- newpath = os.path.join(self.shell.ipython_dir, "hist-corrupt.sqlite")
+ newpath = os.path.join(self.shell.profile_dir.location, "hist-corrupt.sqlite")
os.rename(self.hist_file, newpath)
print("ERROR! History file wasn't a valid SQLite database.",
"It was moved to %s" % newpath, "and a new file created.")
@@ -54,6 +54,7 @@
from IPython.core.logger import Logger
from IPython.core.macro import Macro
from IPython.core.magic import Magic
+from IPython.core.newapplication import ProfileDir
from IPython.core.payload import PayloadManager
from IPython.core.plugin import PluginManager
from IPython.core.prefilter import PrefilterManager, ESC_MAGIC
@@ -238,7 +239,9 @@ class InteractiveShell(SingletonConfigurable, Magic):
"""
)
colors = CaselessStrEnum(('NoColor','LightBG','Linux'),
- default_value=get_default_colors(), config=True)
+ default_value=get_default_colors(), config=True,
+ help="Set the color scheme (NoColor, Linux, and LightBG)."
+ )
debug = CBool(False, config=True)
deep_reload = CBool(False, config=True, help=
"""
@@ -291,7 +294,6 @@ def _exiter_default(self):
"""
)
- profile = Unicode('', config=True)
prompt_in1 = Str('In [\\#]: ', config=True)
prompt_in2 = Str(' .\\D.: ', config=True)
prompt_out = Str('Out[\\#]: ', config=True)
@@ -342,10 +344,18 @@ def _exiter_default(self):
payload_manager = Instance('IPython.core.payload.PayloadManager')
history_manager = Instance('IPython.core.history.HistoryManager')
+ profile_dir = Instance('IPython.core.newapplication.ProfileDir')
+ @property
+ def profile(self):
+ if self.profile_dir is not None:
+ name = os.path.basename(self.profile_dir.location)
+ return name.replace('profile_','')
+
+
# Private interface
_post_execute = Instance(dict)
- def __init__(self, config=None, ipython_dir=None,
+ def __init__(self, config=None, ipython_dir=None, profile_dir=None,
user_ns=None, user_global_ns=None,
custom_exceptions=((), None)):
@@ -355,6 +365,7 @@ def __init__(self, config=None, ipython_dir=None,
# These are relatively independent and stateless
self.init_ipython_dir(ipython_dir)
+ self.init_profile_dir(profile_dir)
self.init_instance_attrs()
self.init_environment()
@@ -372,7 +383,7 @@ def __init__(self, config=None, ipython_dir=None,
# While we're trying to have each part of the code directly access what
# it needs without keeping redundant references to objects, we have too
# much legacy code that expects ip.db to exist.
- self.db = PickleShareDB(os.path.join(self.ipython_dir, 'db'))
+ self.db = PickleShareDB(os.path.join(self.profile_dir.location, 'db'))
self.init_history()
self.init_encoding()
@@ -457,16 +468,16 @@ def set_autoindent(self,value=None):
def init_ipython_dir(self, ipython_dir):
if ipython_dir is not None:
self.ipython_dir = ipython_dir
- self.config.Global.ipython_dir = self.ipython_dir
return
- if hasattr(self.config.Global, 'ipython_dir'):
- self.ipython_dir = self.config.Global.ipython_dir
- else:
- self.ipython_dir = get_ipython_dir()
+ self.ipython_dir = get_ipython_dir()
- # All children can just read this
- self.config.Global.ipython_dir = self.ipython_dir
+ def init_profile_dir(self, profile_dir):
+ if profile_dir is not None:
+ self.profile_dir = profile_dir
+ return
+ self.profile_dir =\
+ ProfileDir.create_profile_dir_by_name(self.ipython_dir, 'default')
def init_instance_attrs(self):
self.more = False
View
@@ -46,6 +46,7 @@
from IPython.core.error import TryNext
from IPython.core.error import UsageError
from IPython.core.fakemodule import FakeModule
+from IPython.core.newapplication import ProfileDir
from IPython.core.macro import Macro
from IPython.core import page
from IPython.core.prefilter import ESC_MAGIC
@@ -533,10 +534,7 @@ def magic_page(self, parameter_s=''):
def magic_profile(self, parameter_s=''):
"""Print your currently active IPython profile."""
- if self.shell.profile:
- printpl('Current IPython profile: $self.shell.profile.')
- else:
- print 'No profile active.'
+ print self.shell.profile
def magic_pinfo(self, parameter_s='', namespaces=None):
"""Provide detailed information about an object.
@@ -3373,22 +3371,16 @@ def magic_install_profiles(self, s):
else:
overwrite = False
from IPython.config import profile
- profile_dir = os.path.split(profile.__file__)[0]
+ profile_dir = os.path.dirname(profile.__file__)
ipython_dir = self.ipython_dir
- files = os.listdir(profile_dir)
-
- to_install = []
- for f in files:
- if f.startswith('ipython_config'):
- src = os.path.join(profile_dir, f)
- dst = os.path.join(ipython_dir, f)
- if (not os.path.isfile(dst)) or overwrite:
- to_install.append((f, src, dst))
- if len(to_install)>0:
- print "Installing profiles to: ", ipython_dir
- for (f, src, dst) in to_install:
- shutil.copy(src, dst)
- print " %s" % f
+ print "Installing profiles to: %s [overwrite=%s]"(ipython_dir,overwrite)
+ for src in os.listdir(profile_dir):
+ if src.startswith('profile_'):
+ name = src.replace('profile_', '')
+ print " %s"%name
+ pd = ProfileDir.create_profile_dir_by_name(ipython_dir, name)
+ pd.copy_config_file('ipython_config.py', path=src,
+ overwrite=overwrite)
@skip_doctest
def magic_install_default_config(self, s):
@@ -3404,15 +3396,9 @@ def magic_install_default_config(self, s):
overwrite = True
else:
overwrite = False
- from IPython.config import default
- config_dir = os.path.split(default.__file__)[0]
- ipython_dir = self.ipython_dir
- default_config_file_name = 'ipython_config.py'
- src = os.path.join(config_dir, default_config_file_name)
- dst = os.path.join(ipython_dir, default_config_file_name)
- if (not os.path.isfile(dst)) or overwrite:
- shutil.copy(src, dst)
- print "Installing default config file: %s" % dst
+ pd = self.shell.profile_dir
+ print "Installing default config file in: %s" % pd.location
+ pd.copy_config_file('ipython_config.py', overwrite=overwrite)
# Pylab support: simple wrappers that activate pylab, load gui input
# handling and modify slightly %run
@@ -58,11 +58,21 @@ def get_default_editor():
class TerminalInteractiveShell(InteractiveShell):
- autoedit_syntax = CBool(False, config=True)
+ autoedit_syntax = CBool(False, config=True,
+ help="auto editing of files with syntax errors.")
banner = Unicode('')
- banner1 = Unicode(default_banner, config=True)
- banner2 = Unicode('', config=True)
- confirm_exit = CBool(True, config=True)
+ banner1 = Unicode(default_banner, config=True,
+ help="""The part of the banner to be printed before the profile"""
+ )
+ banner2 = Unicode('', config=True,
+ help="""The part of the banner to be printed after the profile"""
+ )
+ confirm_exit = CBool(True, config=True,
+ help="""
+ Set to confirm when you try to exit IPython with an EOF (Control-D
+ in Unix, Control-Z/Enter in Windows). By typing 'exit', 'quit' or
+ '%%Exit', you can force a direct exit without any confirmation.""",
+ )
# This display_banner only controls whether or not self.show_banner()
# is called when mainloop/interact are called. The default is False
# because for the terminal based application, the banner behavior
@@ -71,19 +81,35 @@ class TerminalInteractiveShell(InteractiveShell):
display_banner = CBool(False) # This isn't configurable!
embedded = CBool(False)
embedded_active = CBool(False)
- editor = Unicode(get_default_editor(), config=True)
- pager = Unicode('less', config=True)
-
- screen_length = Int(0, config=True)
- term_title = CBool(False, config=True)
-
- def __init__(self, config=None, ipython_dir=None, user_ns=None,
+ editor = Unicode(get_default_editor(), config=True,
+ help="Set the editor used by IPython (default to $EDITOR/vi/notepad)."
+ )
+ pager = Unicode('less', config=True,
+ help="The shell program to be used for paging.")
+
+ screen_length = Int(0, config=True,
+ help=
+ """Number of lines of your screen, used to control printing of very
+ long strings. Strings longer than this number of lines will be sent
+ through a pager instead of directly printed. The default value for
+ this is 0, which means IPython will auto-detect your screen size every
+ time it needs to print certain potentially long strings (this doesn't
+ change the behavior of the 'print' keyword, it's only triggered
+ internally). If for some reason this isn't working well (it needs
+ curses support), specify it yourself. Otherwise don't change the
+ default.""",
+ )
+ term_title = CBool(False, config=True,
+ help="Enable auto setting the terminal title."
+ )
+
+ def __init__(self, config=None, ipython_dir=None, profile_dir=None, user_ns=None,
user_global_ns=None, custom_exceptions=((),None),
usage=None, banner1=None, banner2=None,
display_banner=None):
super(TerminalInteractiveShell, self).__init__(
- config=config, ipython_dir=ipython_dir, user_ns=user_ns,
+ config=config, profile_dir=profile_dir, user_ns=user_ns,
user_global_ns=user_global_ns, custom_exceptions=custom_exceptions
)
# use os.system instead of utils.process.system by default, except on Windows
Oops, something went wrong.

0 comments on commit b1f3e46

Please sign in to comment.