From 65ca6e29be4cd3501e0a3d0415e450de7168e93a 2009-11-09 01:49:24 From: Brian Granger Date: 2009-11-09 01:49:24 Subject: [PATCH] Lots of work on command line options and env vars. * All command line options use the -f, --foo, --no-foo style. * We are not using ipython_dir (code), --ipython-dir (command line) and IPYTHON_DIR (env). --- diff --git a/IPython/config/default/ipython_config.py b/IPython/config/default/ipython_config.py index 0582944..f45fbeb 100644 --- a/IPython/config/default/ipython_config.py +++ b/IPython/config/default/ipython_config.py @@ -35,7 +35,7 @@ c = get_config() # These files are run in IPython in the user's namespace. Files with a .py # extension need to be pure Python. Files with a .ipy extension can have # custom IPython syntax (like magics, etc.). -# These files need to be in the cwd, the ipythondir or be absolute paths. +# These files need to be in the cwd, the ipython_dir or be absolute paths. # c.Global.exec_files = [ # 'mycode.py', # 'fancy.ipy' diff --git a/IPython/core/application.py b/IPython/core/application.py index ed25a1e..d9b66e8 100644 --- a/IPython/core/application.py +++ b/IPython/core/application.py @@ -51,22 +51,22 @@ class BaseAppArgParseConfigLoader(ArgParseConfigLoader): """Default command line options for IPython based applications.""" def _add_other_arguments(self): - self.parser.add_argument('-ipythondir', '--ipython-dir', - dest='Global.ipythondir',type=str, - help='Set to override default location of Global.ipythondir.', + self.parser.add_argument('--ipython-dir', + dest='Global.ipython_dir',type=str, + help='Set to override default location of Global.ipython_dir.', default=NoConfigDefault, - metavar='Global.ipythondir') - self.parser.add_argument('-p','-profile', '--profile', + metavar='Global.ipython_dir') + self.parser.add_argument('-p', '--profile', dest='Global.profile',type=str, help='The string name of the ipython profile to be used.', default=NoConfigDefault, metavar='Global.profile') - self.parser.add_argument('-log_level', '--log-level', + self.parser.add_argument('--log-level', dest="Global.log_level",type=int, help='Set the log level (0,10,20,30,40,50). Default is 30.', default=NoConfigDefault, metavar='Global.log_level') - self.parser.add_argument('-config_file', '--config-file', + self.parser.add_argument('--config-file', dest='Global.config_file',type=str, help='Set the config file name to override default.', default=NoConfigDefault, @@ -119,7 +119,7 @@ class Application(object): self.set_command_line_config_log_level() self.attempt(self.post_load_command_line_config) self.log_command_line_config() - self.attempt(self.find_ipythondir) + self.attempt(self.find_ipython_dir) self.attempt(self.find_resources) self.attempt(self.find_config_file_name) self.attempt(self.find_config_file_paths) @@ -149,7 +149,7 @@ class Application(object): don't belong to a particular component. """ self.default_config = Config() - self.default_config.Global.ipythondir = get_ipython_dir() + self.default_config.Global.ipython_dir = get_ipython_dir() self.default_config.Global.log_level = self.log_level def log_default_config(self): @@ -194,24 +194,24 @@ class Application(object): self.log.debug("Command line config loaded:") self.log.debug(repr(self.command_line_config)) - def find_ipythondir(self): + def find_ipython_dir(self): """Set the IPython directory. - This sets ``self.ipythondir``, but the actual value that is passed + This sets ``self.ipython_dir``, but the actual value that is passed to the application is kept in either ``self.default_config`` or - ``self.command_line_config``. This also adds ``self.ipythondir`` to + ``self.command_line_config``. This also adds ``self.ipython_dir`` to ``sys.path`` so config files there can be references by other config files. """ try: - self.ipythondir = self.command_line_config.Global.ipythondir + self.ipython_dir = self.command_line_config.Global.ipython_dir except AttributeError: - self.ipythondir = self.default_config.Global.ipythondir - sys.path.append(os.path.abspath(self.ipythondir)) - if not os.path.isdir(self.ipythondir): - os.makedirs(self.ipythondir, mode=0777) - self.log.debug("IPYTHONDIR set to: %s" % self.ipythondir) + self.ipython_dir = self.default_config.Global.ipython_dir + sys.path.append(os.path.abspath(self.ipython_dir)) + if not os.path.isdir(self.ipython_dir): + os.makedirs(self.ipython_dir, mode=0777) + self.log.debug("IPYTHON_DIR set to: %s" % self.ipython_dir) def find_resources(self): """Find other resources that need to be in place. @@ -253,7 +253,7 @@ class Application(object): This must set ``self.config_file_paths`` to a sequence of search paths to pass to the config file loader. """ - self.config_file_paths = (os.getcwd(), self.ipythondir) + self.config_file_paths = (os.getcwd(), self.ipython_dir) def pre_load_file_config(self): """Do actions before the config file is loaded.""" diff --git a/IPython/core/crashhandler.py b/IPython/core/crashhandler.py index 285ce02..dd5c553 100644 --- a/IPython/core/crashhandler.py +++ b/IPython/core/crashhandler.py @@ -124,7 +124,7 @@ $self.bug_tracker #color_scheme = 'Linux' # dbg try: - rptdir = self.IP.config.IPYTHONDIR + rptdir = self.IP.ipython_dir except: rptdir = os.getcwd() if not os.path.isdir(rptdir): diff --git a/IPython/core/embed.py b/IPython/core/embed.py index 6ff49ad..a43342a 100644 --- a/IPython/core/embed.py +++ b/IPython/core/embed.py @@ -68,7 +68,7 @@ class InteractiveShellEmbed(InteractiveShell): # is True by default. display_banner = CBool(True) - def __init__(self, parent=None, config=None, ipythondir=None, usage=None, + def __init__(self, parent=None, config=None, ipython_dir=None, usage=None, user_ns=None, user_global_ns=None, banner1=None, banner2=None, display_banner=None, custom_exceptions=((),None), exit_msg=''): @@ -76,7 +76,7 @@ class InteractiveShellEmbed(InteractiveShell): self.save_sys_ipcompleter() super(InteractiveShellEmbed,self).__init__( - parent=parent, config=config, ipythondir=ipythondir, usage=usage, + parent=parent, config=config, ipython_dir=ipython_dir, usage=usage, user_ns=user_ns, user_global_ns=user_global_ns, banner1=banner1, banner2=banner2, display_banner=display_banner, custom_exceptions=custom_exceptions) diff --git a/IPython/core/ipapp.py b/IPython/core/ipapp.py index bba0348..019ac07 100644 --- a/IPython/core/ipapp.py +++ b/IPython/core/ipapp.py @@ -79,181 +79,181 @@ See the %gui magic for information on the new interface. #----------------------------------------------------------------------------- cl_args = ( - (('-autocall',), dict( + (('--autocall',), dict( type=int, dest='InteractiveShell.autocall', default=NoConfigDefault, help='Set the autocall value (0,1,2).', metavar='InteractiveShell.autocall') ), - (('-autoindent',), dict( + (('--autoindent',), dict( action='store_true', dest='InteractiveShell.autoindent', default=NoConfigDefault, help='Turn on autoindenting.') ), - (('-noautoindent',), dict( + (('--no-autoindent',), dict( action='store_false', dest='InteractiveShell.autoindent', default=NoConfigDefault, help='Turn off autoindenting.') ), - (('-automagic',), dict( + (('--automagic',), dict( action='store_true', dest='InteractiveShell.automagic', default=NoConfigDefault, help='Turn on the auto calling of magic commands.') ), - (('-noautomagic',), dict( + (('--no-automagic',), dict( action='store_false', dest='InteractiveShell.automagic', default=NoConfigDefault, help='Turn off the auto calling of magic commands.') ), - (('-autoedit_syntax',), dict( + (('--autoedit-syntax',), dict( action='store_true', dest='InteractiveShell.autoedit_syntax', default=NoConfigDefault, help='Turn on auto editing of files with syntax errors.') ), - (('-noautoedit_syntax',), dict( + (('--no-autoedit-syntax',), dict( action='store_false', dest='InteractiveShell.autoedit_syntax', default=NoConfigDefault, help='Turn off auto editing of files with syntax errors.') ), - (('-banner',), dict( + (('--banner',), dict( action='store_true', dest='Global.display_banner', default=NoConfigDefault, help='Display a banner upon starting IPython.') ), - (('-nobanner',), dict( + (('--no-banner',), dict( action='store_false', dest='Global.display_banner', default=NoConfigDefault, help="Don't display a banner upon starting IPython.") ), - (('-cache_size',), dict( + (('--cache-size',), dict( type=int, dest='InteractiveShell.cache_size', default=NoConfigDefault, help="Set the size of the output cache.", metavar='InteractiveShell.cache_size') ), - (('-classic',), dict( + (('--classic',), dict( action='store_true', dest='Global.classic', default=NoConfigDefault, help="Gives IPython a similar feel to the classic Python prompt.") ), - (('-colors',), dict( + (('--colors',), dict( type=str, dest='InteractiveShell.colors', default=NoConfigDefault, help="Set the color scheme (NoColor, Linux, and LightBG).", metavar='InteractiveShell.colors') ), - (('-color_info',), dict( + (('--color-info',), dict( action='store_true', dest='InteractiveShell.color_info', default=NoConfigDefault, help="Enable using colors for info related things.") ), - (('-nocolor_info',), dict( + (('--no-color-info',), dict( action='store_false', dest='InteractiveShell.color_info', default=NoConfigDefault, help="Disable using colors for info related things.") ), - (('-confirm_exit',), dict( + (('--confirm-exit',), dict( action='store_true', dest='InteractiveShell.confirm_exit', default=NoConfigDefault, help="Prompt the user when existing.") ), - (('-noconfirm_exit',), dict( + (('--no-confirm-exit',), dict( action='store_false', dest='InteractiveShell.confirm_exit', default=NoConfigDefault, help="Don't prompt the user when existing.") ), - (('-deep_reload',), dict( + (('--deep-reload',), dict( action='store_true', dest='InteractiveShell.deep_reload', default=NoConfigDefault, help="Enable deep (recursive) reloading by default.") ), - (('-nodeep_reload',), dict( + (('--no-deep-reload',), dict( action='store_false', dest='InteractiveShell.deep_reload', default=NoConfigDefault, help="Disable deep (recursive) reloading by default.") ), - (('-editor',), dict( + (('--editor',), dict( type=str, dest='InteractiveShell.editor', default=NoConfigDefault, help="Set the editor used by IPython (default to $EDITOR/vi/notepad).", metavar='InteractiveShell.editor') ), - (('-log','-l'), dict( + (('--log','-l'), dict( action='store_true', dest='InteractiveShell.logstart', default=NoConfigDefault, help="Start logging to the default file (./ipython_log.py).") ), - (('-logfile','-lf'), dict( + (('--logfile','-lf'), dict( type=str, dest='InteractiveShell.logfile', default=NoConfigDefault, help="Start logging to logfile.", metavar='InteractiveShell.logfile') ), - (('-logappend','-la'), dict( + (('--log-append','-la'), dict( type=str, dest='InteractiveShell.logappend', default=NoConfigDefault, help="Start logging to logappend in append mode.", metavar='InteractiveShell.logfile') ), - (('-pdb',), dict( + (('--pdb',), dict( action='store_true', dest='InteractiveShell.pdb', default=NoConfigDefault, help="Enable auto calling the pdb debugger after every exception.") ), - (('-nopdb',), dict( + (('--nopdb',), dict( action='store_false', dest='InteractiveShell.pdb', default=NoConfigDefault, help="Disable auto calling the pdb debugger after every exception.") ), - (('-pprint',), dict( + (('--pprint',), dict( action='store_true', dest='InteractiveShell.pprint', default=NoConfigDefault, help="Enable auto pretty printing of results.") ), - (('-nopprint',), dict( + (('--no-pprint',), dict( action='store_false', dest='InteractiveShell.pprint', default=NoConfigDefault, help="Disable auto auto pretty printing of results.") ), - (('-prompt_in1','-pi1'), dict( + (('--prompt-in1','-pi1'), dict( type=str, dest='InteractiveShell.prompt_in1', default=NoConfigDefault, help="Set the main input prompt ('In [\#]: ')", metavar='InteractiveShell.prompt_in1') ), - (('-prompt_in2','-pi2'), dict( + (('--prompt-in2','-pi2'), dict( type=str, dest='InteractiveShell.prompt_in2', default=NoConfigDefault, help="Set the secondary input prompt (' .\D.: ')", metavar='InteractiveShell.prompt_in2') ), - (('-prompt_out','-po'), dict( + (('--prompt-out','-po'), dict( type=str, dest='InteractiveShell.prompt_out', default=NoConfigDefault, help="Set the output prompt ('Out[\#]:')", metavar='InteractiveShell.prompt_out') ), - (('-quick',), dict( + (('--quick',), dict( action='store_true', dest='Global.quick', default=NoConfigDefault, help="Enable quick startup with no config files.") ), - (('-readline',), dict( + (('--readline',), dict( action='store_true', dest='InteractiveShell.readline_use', default=NoConfigDefault, help="Enable readline for command line usage.") ), - (('-noreadline',), dict( + (('--no-readline',), dict( action='store_false', dest='InteractiveShell.readline_use', default=NoConfigDefault, help="Disable readline for command line usage.") ), - (('-screen_length','-sl'), dict( + (('--screen-length','-sl'), dict( type=int, dest='InteractiveShell.screen_length', default=NoConfigDefault, help='Number of lines on screen, used to control printing of long strings.', metavar='InteractiveShell.screen_length') ), - (('-separate_in','-si'), dict( + (('--separate-in','-si'), dict( type=str, dest='InteractiveShell.separate_in', default=NoConfigDefault, help="Separator before input prompts. Default '\n'.", metavar='InteractiveShell.separate_in') ), - (('-separate_out','-so'), dict( + (('--separate-out','-so'), dict( type=str, dest='InteractiveShell.separate_out', default=NoConfigDefault, help="Separator before output prompts. Default 0 (nothing).", metavar='InteractiveShell.separate_out') ), - (('-separate_out2','-so2'), dict( + (('--separate-out2','-so2'), dict( type=str, dest='InteractiveShell.separate_out2', default=NoConfigDefault, help="Separator after output prompts. Default 0 (nonight).", metavar='InteractiveShell.separate_out2') ), - (('-nosep',), dict( + (('-no-sep',), dict( action='store_true', dest='Global.nosep', default=NoConfigDefault, help="Eliminate all spacing between prompts.") ), - (('-term_title',), dict( + (('--term-title',), dict( action='store_true', dest='InteractiveShell.term_title', default=NoConfigDefault, help="Enable auto setting the terminal title.") ), - (('-noterm_title',), dict( + (('--no-term-title',), dict( action='store_false', dest='InteractiveShell.term_title', default=NoConfigDefault, help="Disable auto setting the terminal title.") ), - (('-xmode',), dict( + (('--xmode',), dict( type=str, dest='InteractiveShell.xmode', default=NoConfigDefault, help="Exception mode ('Plain','Context','Verbose')", metavar='InteractiveShell.xmode') ), - (('-ext',), dict( + (('--ext',), dict( type=str, dest='Global.extra_extension', default=NoConfigDefault, help="The dotted module name of an IPython extension to load.", metavar='Global.extra_extension') @@ -267,20 +267,20 @@ cl_args = ( action='store_true', dest='Global.force_interact', default=NoConfigDefault, help="If running code from the command line, become interactive afterwards.") ), - (('-wthread',), dict( + (('--wthread',), dict( action='store_true', dest='Global.wthread', default=NoConfigDefault, help="Enable wxPython event loop integration.") ), - (('-q4thread','-qthread'), dict( + (('--q4thread','--qthread'), dict( action='store_true', dest='Global.q4thread', default=NoConfigDefault, help="Enable Qt4 event loop integration. Qt3 is no longer supported.") ), - (('-gthread',), dict( + (('--gthread',), dict( action='store_true', dest='Global.gthread', default=NoConfigDefault, help="Enable GTK event loop integration.") ), # # These are only here to get the proper deprecation warnings - (('-pylab',), dict( + (('--pylab',), dict( action='store_true', dest='Global.pylab', default=NoConfigDefault, help="Disabled. Pylab has been disabled until matplotlib " "supports this version of IPython.") @@ -475,7 +475,7 @@ class IPythonApp(Application): self.shell.showtraceback() def _exec_file(self, fname): - full_filename = filefind(fname, ['.', self.ipythondir]) + full_filename = filefind(fname, ['.', self.ipython_dir]) if os.path.isfile(full_filename): if full_filename.endswith('.py'): self.log.info("Running file in user namespace: %s" % full_filename) @@ -525,14 +525,14 @@ class IPythonApp(Application): self.shell.mainloop() -def load_default_config(ipythondir=None): - """Load the default config file from the default ipythondir. +def load_default_config(ipython_dir=None): + """Load the default config file from the default ipython_dir. This is useful for embedded shells. """ - if ipythondir is None: - ipythondir = get_ipython_dir() - cl = PyFileConfigLoader(default_config_file_name, ipythondir) + if ipython_dir is None: + ipython_dir = get_ipython_dir() + cl = PyFileConfigLoader(default_config_file_name, ipython_dir) config = cl.load_config() return config diff --git a/IPython/core/iplib.py b/IPython/core/iplib.py index 81a5970..de12b2d 100644 --- a/IPython/core/iplib.py +++ b/IPython/core/iplib.py @@ -215,7 +215,7 @@ class InteractiveShell(Component, Magic): embedded_active = CBool(False) editor = Str(get_default_editor(), config=True) filename = Str("") - ipythondir= Unicode('', config=True) # Set to get_ipython_dir() in __init__ + ipython_dir= Unicode('', config=True) # Set to get_ipython_dir() in __init__ logstart = CBool(False, config=True) logfile = Str('', config=True) logappend = Str('', config=True) @@ -273,7 +273,7 @@ class InteractiveShell(Component, Magic): # Subclasses with thread support should override this as needed. isthreaded = False - def __init__(self, parent=None, config=None, ipythondir=None, usage=None, + def __init__(self, parent=None, config=None, ipython_dir=None, usage=None, user_ns=None, user_global_ns=None, banner1=None, banner2=None, display_banner=None, custom_exceptions=((),None)): @@ -283,7 +283,7 @@ class InteractiveShell(Component, Magic): super(InteractiveShell, self).__init__(parent, config=config) # These are relatively independent and stateless - self.init_ipythondir(ipythondir) + self.init_ipython_dir(ipython_dir) self.init_instance_attrs() self.init_term_title() self.init_usage(usage) @@ -341,7 +341,7 @@ class InteractiveShell(Component, Magic): def _banner2_changed(self): self.compute_banner() - def _ipythondir_changed(self, name, new): + def _ipython_dir_changed(self, name, new): if not os.path.isdir(new): os.makedirs(new, mode = 0777) if not os.path.isdir(self.ipython_extension_dir): @@ -349,7 +349,7 @@ class InteractiveShell(Component, Magic): @property def ipython_extension_dir(self): - return os.path.join(self.ipythondir, 'extensions') + return os.path.join(self.ipython_dir, 'extensions') @property def usable_screen_length(self): @@ -381,19 +381,19 @@ class InteractiveShell(Component, Magic): # init_* methods called by __init__ #------------------------------------------------------------------------- - def init_ipythondir(self, ipythondir): - if ipythondir is not None: - self.ipythondir = ipythondir - self.config.Global.ipythondir = self.ipythondir + 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, 'ipythondir'): - self.ipythondir = self.config.Global.ipythondir + if hasattr(self.config.Global, 'ipython_dir'): + self.ipython_dir = self.config.Global.ipython_dir else: - self.ipythondir = get_ipython_dir() + self.ipython_dir = get_ipython_dir() # All children can just read this - self.config.Global.ipythondir = self.ipythondir + self.config.Global.ipython_dir = self.ipython_dir def init_instance_attrs(self): self.jobs = BackgroundJobManager() @@ -1079,7 +1079,7 @@ class InteractiveShell(Component, Magic): histfname = 'history-%s' % self.profile else: histfname = 'history' - self.histfile = os.path.join(self.ipythondir, histfname) + self.histfile = os.path.join(self.ipython_dir, histfname) # Fill the history zero entry, user counter starts at 1 self.input_hist.append('\n') @@ -1087,12 +1087,12 @@ class InteractiveShell(Component, Magic): def init_shadow_hist(self): try: - self.db = pickleshare.PickleShareDB(self.ipythondir + "/db") + self.db = pickleshare.PickleShareDB(self.ipython_dir + "/db") except exceptions.UnicodeDecodeError: - print "Your ipythondir can't be decoded to unicode!" + print "Your ipython_dir can't be decoded to unicode!" print "Please set HOME environment variable to something that" print r"only has ASCII characters, e.g. c:\home" - print "Now it is", self.ipythondir + print "Now it is", self.ipython_dir sys.exit() self.shadowhist = ipcorehist.ShadowHist(self.db) @@ -2327,7 +2327,7 @@ class InteractiveShell(Component, Magic): You can put your extension modules anywhere you want, as long as they can be imported by Python's standard import mechanism. However, to make it easy to write extensions, you can also put your extensions - in ``os.path.join(self.ipythondir, 'extensions')``. This directory + in ``os.path.join(self.ipython_dir, 'extensions')``. This directory is added to ``sys.path`` automatically. """ from IPython.utils.syspathcontext import prepended_to_syspath diff --git a/IPython/core/magic.py b/IPython/core/magic.py index a144032..fda4021 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -3378,34 +3378,6 @@ Defaulting color scheme to 'NoColor'""" qr = IPython.core.usage.quick_reference + self.magic_magic('-brief') page(qr) - - def magic_upgrade(self,arg): - """ Upgrade your IPython installation - - This will copy the config files that don't yet exist in your - ipython dir from the system config dir. Use this after upgrading - IPython if you don't wish to delete your .ipython dir. - - Call with -nolegacy to get rid of ipythonrc* files (recommended for - new users) - - """ - ip = self.getapi() - ipinstallation = path(IPython.__file__).dirname() - upgrade_script = '%s "%s"' % (sys.executable,ipinstallation / 'utils' / 'upgradedir.py') - src_config = ipinstallation / 'config' / 'userconfig' - userdir = path(ip.config.IPYTHONDIR) - cmd = '%s "%s" "%s"' % (upgrade_script, src_config, userdir) - print ">",cmd - shell(cmd) - if arg == '-nolegacy': - legacy = userdir.files('ipythonrc*') - print "Nuking legacy files:",legacy - - [p.remove() for p in legacy] - suffix = (sys.platform == 'win32' and '.ini' or '') - (userdir / ('ipythonrc' + suffix)).write_text('# Empty, see ipy_user_conf.py\n') - def magic_doctest_mode(self,parameter_s=''): """Toggle doctest mode on and off. @@ -3565,18 +3537,18 @@ Defaulting color scheme to 'NoColor'""" overwrite = False from IPython.config import profile profile_dir = os.path.split(profile.__file__)[0] - ipythondir = self.ipythondir + 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(ipythondir, 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: ", ipythondir + print "Installing profiles to: ", ipython_dir for (f, src, dst) in to_install: shutil.copy(src, dst) print " %s" % f @@ -3596,10 +3568,10 @@ Defaulting color scheme to 'NoColor'""" overwrite = False from IPython.config import default config_dir = os.path.split(default.__file__)[0] - ipythondir = self.ipythondir + 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(ipythondir, 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 diff --git a/IPython/core/oldusersetup.py b/IPython/core/oldusersetup.py deleted file mode 100644 index b32ac45..0000000 --- a/IPython/core/oldusersetup.py +++ /dev/null @@ -1,219 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Main IPython Component -""" - -#----------------------------------------------------------------------------- -# Copyright (C) 2001 Janko Hauser -# Copyright (C) 2001-2007 Fernando Perez. -# Copyright (C) 2008-2009 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- - -import glob -import os -import shutil -import sys - -from IPython.utils.genutils import * - -def user_setup(ipythondir,rc_suffix,mode='install',interactive=True): - """Install or upgrade the user configuration directory. - - Can be called when running for the first time or to upgrade the user's - .ipython/ directory. - - Parameters - ---------- - ipythondir : path - The directory to be used for installation/upgrade. In 'install' mode, - if this path already exists, the function exits immediately. - - rc_suffix : str - Extension for the config files. On *nix platforms it is typically the - empty string, while Windows normally uses '.ini'. - - mode : str, optional - Valid modes are 'install' and 'upgrade'. - - interactive : bool, optional - If False, do not wait for user input on any errors. Normally after - printing its status information, this function waits for the user to - hit Return before proceeding. This is because the default use case is - when first installing the IPython configuration, so we want the user to - acknowledge the initial message, which contains some useful - information. - """ - - # For automatic use, deactivate all i/o - if interactive: - def wait(): - try: - raw_input("Please press to start IPython.") - except EOFError: - print >> Term.cout - print '*'*70 - - def printf(s): - print s - else: - wait = lambda : None - printf = lambda s : None - - # Install mode should be re-entrant: if the install dir already exists, - # bail out cleanly. - # XXX. This is too hasty to return. We need to check to make sure that - # all the expected config files and directories are actually there. We - # currently have a failure mode if someone deletes a needed config file - # but still has the ipythondir. - if mode == 'install' and os.path.isdir(ipythondir): - return - - cwd = os.getcwd() # remember where we started - glb = glob.glob - - printf('*'*70) - if mode == 'install': - printf( -"""Welcome to IPython. I will try to create a personal configuration directory -where you can customize many aspects of IPython's functionality in:\n""") - else: - printf('I am going to upgrade your configuration in:') - - printf(ipythondir) - - rcdirend = os.path.join('IPython','config','userconfig') - cfg = lambda d: os.path.join(d,rcdirend) - try: - rcdir = filter(os.path.isdir,map(cfg,sys.path))[0] - printf("Initializing from configuration: %s" % rcdir) - except IndexError: - warning = """ -Installation error. IPython's directory was not found. - -Check the following: - -The ipython/IPython directory should be in a directory belonging to your -PYTHONPATH environment variable (that is, it should be in a directory -belonging to sys.path). You can copy it explicitly there or just link to it. - -IPython will create a minimal default configuration for you. - -""" - warn(warning) - wait() - - if sys.platform =='win32': - inif = 'ipythonrc.ini' - else: - inif = 'ipythonrc' - minimal_setup = {'ipy_user_conf.py' : 'import ipy_defaults', - inif : '# intentionally left blank' } - os.makedirs(ipythondir, mode = 0777) - for f, cont in minimal_setup.items(): - # In 2.5, this can be more cleanly done using 'with' - fobj = file(ipythondir + '/' + f,'w') - fobj.write(cont) - fobj.close() - - return - - if mode == 'install': - try: - shutil.copytree(rcdir,ipythondir) - os.chdir(ipythondir) - rc_files = glb("ipythonrc*") - for rc_file in rc_files: - os.rename(rc_file,rc_file+rc_suffix) - except: - warning = """ - -There was a problem with the installation: -%s -Try to correct it or contact the developers if you think it's a bug. -IPython will proceed with builtin defaults.""" % sys.exc_info()[1] - warn(warning) - wait() - return - - elif mode == 'upgrade': - try: - os.chdir(ipythondir) - except: - printf(""" -Can not upgrade: changing to directory %s failed. Details: -%s -""" % (ipythondir,sys.exc_info()[1]) ) - wait() - return - else: - sources = glb(os.path.join(rcdir,'[A-Za-z]*')) - for new_full_path in sources: - new_filename = os.path.basename(new_full_path) - if new_filename.startswith('ipythonrc'): - new_filename = new_filename + rc_suffix - # The config directory should only contain files, skip any - # directories which may be there (like CVS) - if os.path.isdir(new_full_path): - continue - if os.path.exists(new_filename): - old_file = new_filename+'.old' - if os.path.exists(old_file): - os.remove(old_file) - os.rename(new_filename,old_file) - shutil.copy(new_full_path,new_filename) - else: - raise ValueError('unrecognized mode for install: %r' % mode) - - # Fix line-endings to those native to each platform in the config - # directory. - try: - os.chdir(ipythondir) - except: - printf(""" -Problem: changing to directory %s failed. -Details: -%s - -Some configuration files may have incorrect line endings. This should not -cause any problems during execution. """ % (ipythondir,sys.exc_info()[1]) ) - wait() - else: - for fname in glb('ipythonrc*'): - try: - native_line_ends(fname,backup=0) - except IOError: - pass - - if mode == 'install': - printf(""" -Successful installation! - -Please read the sections 'Initial Configuration' and 'Quick Tips' in the -IPython manual (there are both HTML and PDF versions supplied with the -distribution) to make sure that your system environment is properly configured -to take advantage of IPython's features. - -Important note: the configuration system has changed! The old system is -still in place, but its setting may be partly overridden by the settings in -"~/.ipython/ipy_user_conf.py" config file. Please take a look at the file -if some of the new settings bother you. - -""") - else: - printf(""" -Successful upgrade! - -All files in your directory: -%(ipythondir)s -which would have been overwritten by the upgrade were backed up with a .old -extension. If you had made particular customizations in those files you may -want to merge them back into the new files.""" % locals() ) - wait() - os.chdir(cwd) \ No newline at end of file diff --git a/IPython/core/tests/test_iplib.py b/IPython/core/tests/test_iplib.py index c1b12c8..8a972ae 100644 --- a/IPython/core/tests/test_iplib.py +++ b/IPython/core/tests/test_iplib.py @@ -15,7 +15,7 @@ import nose.tools as nt # our own packages from IPython.core import iplib from IPython.core import ipapi -from IPython.core.oldusersetup import user_setup + #----------------------------------------------------------------------------- # Globals @@ -54,27 +54,4 @@ def test_reset(): continue nt.assert_equals(len(ns),0) - -# make sure that user_setup can be run re-entrantly in 'install' mode. -def test_user_setup(): - # use a lambda to pass kwargs to the generator - user_setup = lambda a,k: user_setup(*a,**k) - kw = dict(mode='install', interactive=False) - - # Call the user setup and verify that the directory exists - yield user_setup, (ip.config.IPYTHONDIR,''), kw - yield os.path.isdir, ip.config.IPYTHONDIR - - # Now repeat the operation with a non-existent directory. Check both that - # the call succeeds and that the directory is created. - tmpdir = tempfile.mktemp(prefix='ipython-test-') - # Use a try with an empty except because try/finally doesn't work with a - # yield in Python 2.4. - try: - yield user_setup, (tmpdir,''), kw - yield os.path.isdir, tmpdir - except: - pass - # Clean up the temp dir once done - shutil.rmtree(tmpdir) \ No newline at end of file diff --git a/IPython/core/usage.py b/IPython/core/usage.py index 62eb175..1fdd8c9 100644 --- a/IPython/core/usage.py +++ b/IPython/core/usage.py @@ -40,7 +40,7 @@ USAGE in directories. In the rest of this text, we will refer to this directory as - IPYTHONDIR. + IPYTHON_DIR. REGULAR OPTIONS After the above threading options have been given, regular options can @@ -150,9 +150,9 @@ REGULAR OPTIONS here (in case your default EDITOR is something like Emacs). -ipythondir - The name of your IPython configuration directory IPYTHONDIR. + The name of your IPython configuration directory IPYTHON_DIR. This can also be specified through the environment variable - IPYTHONDIR. + IPYTHON_DIR. -log|l Generate a log file of all input. The file is named ipython_log.py in your current directory (which prevents logs @@ -201,10 +201,10 @@ REGULAR OPTIONS -profile|p Assume that your config file is ipythonrc- (looks in cur- - rent dir first, then in IPYTHONDIR). This is a quick way to keep + rent dir first, then in IPYTHON_DIR). This is a quick way to keep and load multiple config files for different tasks, especially if you use the include option of config files. You can keep a - basic IPYTHONDIR/ipythonrc file and then have other 'profiles' + basic IPYTHON_DIR/ipythonrc file and then have other 'profiles' which include this one and load extra things for particular tasks. For example: @@ -245,7 +245,7 @@ REGULAR OPTIONS -rcfile Name of your IPython resource configuration file. normally IPython loads ipythonrc (from current directory) or - IPYTHONDIR/ipythonrc. If the loading of your config file fails, + IPYTHON_DIR/ipythonrc. If the loading of your config file fails, IPython starts with a bare bones configuration (no modules loaded at all). @@ -284,7 +284,7 @@ REGULAR OPTIONS Simply removes all input/output separators. -upgrade - Allows you to upgrade your IPYTHONDIR configuration when you + Allows you to upgrade your IPYTHON_DIR configuration when you install a new version of IPython. Since new versions may include new command lines options or example files, this copies updated ipythonrc-type files. However, it backs up (with a .old diff --git a/IPython/gui/wx/wxIPython.py b/IPython/gui/wx/wxIPython.py index 9d70bd1..b5158b7 100644 --- a/IPython/gui/wx/wxIPython.py +++ b/IPython/gui/wx/wxIPython.py @@ -109,7 +109,7 @@ class MyFrame(wx.Frame): def optionSave(self, name, value): ip = get() - path = ip.config.IPYTHONDIR + path = ip.ipython_dir opt = open(path + '/options.conf','w') try: @@ -126,7 +126,7 @@ class MyFrame(wx.Frame): def optionLoad(self): try: ip = get() - path = ip.config.IPYTHONDIR + path = ip.ipython_dir opt = open(path + '/options.conf','r') lines = opt.readlines() opt.close() diff --git a/IPython/kernel/clientconnector.py b/IPython/kernel/clientconnector.py index 3152db3..9a73f49 100644 --- a/IPython/kernel/clientconnector.py +++ b/IPython/kernel/clientconnector.py @@ -65,8 +65,8 @@ class AsyncClientConnector(object): def _find_furl(self, profile='default', cluster_dir=None, furl_or_file=None, furl_file_name=None, - ipythondir=None): - """Find a FURL file by profile+ipythondir or cluster dir. + ipython_dir=None): + """Find a FURL file by profile+ipython_dir or cluster dir. This raises an :exc:`~IPython.kernel.fcutil.FURLError` exception if a FURL file can't be found. @@ -88,11 +88,11 @@ class AsyncClientConnector(object): return furl_file # Try by profile - if ipythondir is None: - ipythondir = get_ipython_dir() + if ipython_dir is None: + ipython_dir = get_ipython_dir() if profile is not None: cluster_dir_obj = ClusterDir.find_cluster_dir_by_profile( - ipythondir, profile) + ipython_dir, profile) sdir = cluster_dir_obj.security_dir furl_file = os.path.join(sdir, furl_file_name) validate_furl_or_file(furl_file) @@ -131,7 +131,7 @@ class AsyncClientConnector(object): return ref def get_task_client(self, profile='default', cluster_dir=None, - furl_or_file=None, ipythondir=None, + furl_or_file=None, ipython_dir=None, delay=DELAY, max_tries=MAX_TRIES): """Get the task controller client. @@ -145,16 +145,16 @@ class AsyncClientConnector(object): profile : str The name of a cluster directory profile (default="default"). The cluster directory "cluster_" will be searched for - in ``os.getcwd()``, the ipythondir and then in the directories - listed in the :env:`IPCLUSTERDIR_PATH` environment variable. + in ``os.getcwd()``, the ipython_dir and then in the directories + listed in the :env:`IPCLUSTER_DIR_PATH` environment variable. cluster_dir : str The full path to a cluster directory. This is useful if profiles are not being used. furl_or_file : str A furl or a filename containing a FURLK. This is useful if you simply know the location of the FURL file. - ipythondir : str - The location of the ipythondir if different from the default. + ipython_dir : str + The location of the ipython_dir if different from the default. This is used if the cluster directory is being found by profile. delay : float The initial delay between re-connection attempts. Susequent delays @@ -168,12 +168,12 @@ class AsyncClientConnector(object): """ return self.get_client( profile, cluster_dir, furl_or_file, - 'ipcontroller-tc.furl', ipythondir, + 'ipcontroller-tc.furl', ipython_dir, delay, max_tries ) def get_multiengine_client(self, profile='default', cluster_dir=None, - furl_or_file=None, ipythondir=None, + furl_or_file=None, ipython_dir=None, delay=DELAY, max_tries=MAX_TRIES): """Get the multiengine controller client. @@ -187,16 +187,16 @@ class AsyncClientConnector(object): profile : str The name of a cluster directory profile (default="default"). The cluster directory "cluster_" will be searched for - in ``os.getcwd()``, the ipythondir and then in the directories - listed in the :env:`IPCLUSTERDIR_PATH` environment variable. + in ``os.getcwd()``, the ipython_dir and then in the directories + listed in the :env:`IPCLUSTER_DIR_PATH` environment variable. cluster_dir : str The full path to a cluster directory. This is useful if profiles are not being used. furl_or_file : str A furl or a filename containing a FURLK. This is useful if you simply know the location of the FURL file. - ipythondir : str - The location of the ipythondir if different from the default. + ipython_dir : str + The location of the ipython_dir if different from the default. This is used if the cluster directory is being found by profile. delay : float The initial delay between re-connection attempts. Susequent delays @@ -210,12 +210,12 @@ class AsyncClientConnector(object): """ return self.get_client( profile, cluster_dir, furl_or_file, - 'ipcontroller-mec.furl', ipythondir, + 'ipcontroller-mec.furl', ipython_dir, delay, max_tries ) def get_client(self, profile='default', cluster_dir=None, - furl_or_file=None, furl_file_name=None, ipythondir=None, + furl_or_file=None, furl_file_name=None, ipython_dir=None, delay=DELAY, max_tries=MAX_TRIES): """Get a remote reference and wrap it in a client by furl. @@ -229,8 +229,8 @@ class AsyncClientConnector(object): profile : str The name of a cluster directory profile (default="default"). The cluster directory "cluster_" will be searched for - in ``os.getcwd()``, the ipythondir and then in the directories - listed in the :env:`IPCLUSTERDIR_PATH` environment variable. + in ``os.getcwd()``, the ipython_dir and then in the directories + listed in the :env:`IPCLUSTER_DIR_PATH` environment variable. cluster_dir : str The full path to a cluster directory. This is useful if profiles are not being used. @@ -240,8 +240,8 @@ class AsyncClientConnector(object): furl_file_name : str The filename (not the full path) of the FURL. This must be provided if ``furl_or_file`` is not. - ipythondir : str - The location of the ipythondir if different from the default. + ipython_dir : str + The location of the ipython_dir if different from the default. This is used if the cluster directory is being found by profile. delay : float The initial delay between re-connection attempts. Susequent delays @@ -257,7 +257,7 @@ class AsyncClientConnector(object): try: furl_file = self._find_furl( profile, cluster_dir, furl_or_file, - furl_file_name, ipythondir + furl_file_name, ipython_dir ) except FURLError: return defer.fail(failure.Failure()) @@ -323,7 +323,7 @@ class ClientConnector(object): self.async_cc = AsyncClientConnector() def get_task_client(self, profile='default', cluster_dir=None, - furl_or_file=None, ipythondir=None, + furl_or_file=None, ipython_dir=None, delay=DELAY, max_tries=MAX_TRIES): """Get the task client. @@ -336,16 +336,16 @@ class ClientConnector(object): profile : str The name of a cluster directory profile (default="default"). The cluster directory "cluster_" will be searched for - in ``os.getcwd()``, the ipythondir and then in the directories - listed in the :env:`IPCLUSTERDIR_PATH` environment variable. + in ``os.getcwd()``, the ipython_dir and then in the directories + listed in the :env:`IPCLUSTER_DIR_PATH` environment variable. cluster_dir : str The full path to a cluster directory. This is useful if profiles are not being used. furl_or_file : str A furl or a filename containing a FURLK. This is useful if you simply know the location of the FURL file. - ipythondir : str - The location of the ipythondir if different from the default. + ipython_dir : str + The location of the ipython_dir if different from the default. This is used if the cluster directory is being found by profile. delay : float The initial delay between re-connection attempts. Susequent delays @@ -359,12 +359,12 @@ class ClientConnector(object): """ client = blockingCallFromThread( self.async_cc.get_task_client, profile, cluster_dir, - furl_or_file, ipythondir, delay, max_tries + furl_or_file, ipython_dir, delay, max_tries ) return client.adapt_to_blocking_client() def get_multiengine_client(self, profile='default', cluster_dir=None, - furl_or_file=None, ipythondir=None, + furl_or_file=None, ipython_dir=None, delay=DELAY, max_tries=MAX_TRIES): """Get the multiengine client. @@ -377,16 +377,16 @@ class ClientConnector(object): profile : str The name of a cluster directory profile (default="default"). The cluster directory "cluster_" will be searched for - in ``os.getcwd()``, the ipythondir and then in the directories - listed in the :env:`IPCLUSTERDIR_PATH` environment variable. + in ``os.getcwd()``, the ipython_dir and then in the directories + listed in the :env:`IPCLUSTER_DIR_PATH` environment variable. cluster_dir : str The full path to a cluster directory. This is useful if profiles are not being used. furl_or_file : str A furl or a filename containing a FURLK. This is useful if you simply know the location of the FURL file. - ipythondir : str - The location of the ipythondir if different from the default. + ipython_dir : str + The location of the ipython_dir if different from the default. This is used if the cluster directory is being found by profile. delay : float The initial delay between re-connection attempts. Susequent delays @@ -400,16 +400,16 @@ class ClientConnector(object): """ client = blockingCallFromThread( self.async_cc.get_multiengine_client, profile, cluster_dir, - furl_or_file, ipythondir, delay, max_tries + furl_or_file, ipython_dir, delay, max_tries ) return client.adapt_to_blocking_client() def get_client(self, profile='default', cluster_dir=None, - furl_or_file=None, ipythondir=None, + furl_or_file=None, ipython_dir=None, delay=DELAY, max_tries=MAX_TRIES): client = blockingCallFromThread( self.async_cc.get_client, profile, cluster_dir, - furl_or_file, ipythondir, + furl_or_file, ipython_dir, delay, max_tries ) return client.adapt_to_blocking_client() @@ -422,7 +422,7 @@ class ClusterStateError(Exception): class AsyncCluster(object): """An class that wraps the :command:`ipcluster` script.""" - def __init__(self, profile='default', cluster_dir=None, ipythondir=None, + def __init__(self, profile='default', cluster_dir=None, ipython_dir=None, auto_create=False, auto_stop=True): """Create a class to manage an IPython cluster. @@ -437,13 +437,13 @@ class AsyncCluster(object): profile : str The name of a cluster directory profile (default="default"). The cluster directory "cluster_" will be searched for - in ``os.getcwd()``, the ipythondir and then in the directories - listed in the :env:`IPCLUSTERDIR_PATH` environment variable. + in ``os.getcwd()``, the ipython_dir and then in the directories + listed in the :env:`IPCLUSTER_DIR_PATH` environment variable. cluster_dir : str The full path to a cluster directory. This is useful if profiles are not being used. - ipythondir : str - The location of the ipythondir if different from the default. + ipython_dir : str + The location of the ipython_dir if different from the default. This is used if the cluster directory is being found by profile. auto_create : bool Automatically create the cluster directory it is dones't exist. @@ -455,7 +455,7 @@ class AsyncCluster(object): to live beyond your current process. There is also an instance attribute ``auto_stop`` to change this behavior. """ - self._setup_cluster_dir(profile, cluster_dir, ipythondir, auto_create) + self._setup_cluster_dir(profile, cluster_dir, ipython_dir, auto_create) self.state = 'before' self.launcher = None self.client_connector = None @@ -480,9 +480,9 @@ class AsyncCluster(object): else: return False - def _setup_cluster_dir(self, profile, cluster_dir, ipythondir, auto_create): - if ipythondir is None: - ipythondir = get_ipython_dir() + def _setup_cluster_dir(self, profile, cluster_dir, ipython_dir, auto_create): + if ipython_dir is None: + ipython_dir = get_ipython_dir() if cluster_dir is not None: try: self.cluster_dir_obj = ClusterDir.find_cluster_dir(cluster_dir) @@ -491,13 +491,13 @@ class AsyncCluster(object): if profile is not None: try: self.cluster_dir_obj = ClusterDir.find_cluster_dir_by_profile( - ipythondir, profile) + ipython_dir, profile) except ClusterDirError: pass if auto_create or profile=='default': # This should call 'ipcluster create --profile default self.cluster_dir_obj = ClusterDir.create_cluster_dir_by_profile( - ipythondir, profile) + ipython_dir, profile) else: raise ClusterDirError('Cluster dir not found.') @@ -593,7 +593,7 @@ class AsyncCluster(object): class Cluster(object): - def __init__(self, profile='default', cluster_dir=None, ipythondir=None, + def __init__(self, profile='default', cluster_dir=None, ipython_dir=None, auto_create=False, auto_stop=True): """Create a class to manage an IPython cluster. @@ -608,13 +608,13 @@ class Cluster(object): profile : str The name of a cluster directory profile (default="default"). The cluster directory "cluster_" will be searched for - in ``os.getcwd()``, the ipythondir and then in the directories - listed in the :env:`IPCLUSTERDIR_PATH` environment variable. + in ``os.getcwd()``, the ipython_dir and then in the directories + listed in the :env:`IPCLUSTER_DIR_PATH` environment variable. cluster_dir : str The full path to a cluster directory. This is useful if profiles are not being used. - ipythondir : str - The location of the ipythondir if different from the default. + ipython_dir : str + The location of the ipython_dir if different from the default. This is used if the cluster directory is being found by profile. auto_create : bool Automatically create the cluster directory it is dones't exist. @@ -627,7 +627,7 @@ class Cluster(object): attribute ``auto_stop`` to change this behavior. """ self.async_cluster = AsyncCluster( - profile, cluster_dir, ipythondir, auto_create, auto_stop + profile, cluster_dir, ipython_dir, auto_create, auto_stop ) self.cluster_dir_obj = self.async_cluster.cluster_dir_obj self.client_connector = None diff --git a/IPython/kernel/clusterdir.py b/IPython/kernel/clusterdir.py index cae1c4b..bc68429 100644 --- a/IPython/kernel/clusterdir.py +++ b/IPython/kernel/clusterdir.py @@ -172,7 +172,7 @@ class ClusterDir(Component): return ClusterDir(cluster_dir) @classmethod - def find_cluster_dir_by_profile(cls, ipythondir, profile='default'): + def find_cluster_dir_by_profile(cls, ipython_dir, profile='default'): """Find an existing cluster dir by profile name, return its ClusterDir. This searches through a sequence of paths for a cluster dir. If it @@ -180,25 +180,25 @@ class ClusterDir(Component): The search path algorithm is: 1. ``os.getcwd()`` - 2. ``ipythondir`` + 2. ``ipython_dir`` 3. The directories found in the ":" separated - :env:`IPCLUSTERDIR_PATH` environment variable. + :env:`IPCLUSTER_DIR_PATH` environment variable. Parameters ---------- - ipythondir : unicode or str + ipython_dir : unicode or str The IPython directory to use. profile : unicode or str The name of the profile. The name of the cluster directory will be "cluster_". """ dirname = 'cluster_' + profile - cluster_dir_paths = os.environ.get('IPCLUSTERDIR_PATH','') + cluster_dir_paths = os.environ.get('IPCLUSTER_DIR_PATH','') if cluster_dir_paths: cluster_dir_paths = cluster_dir_paths.split(':') else: cluster_dir_paths = [] - paths = [os.getcwd(), ipythondir] + cluster_dir_paths + paths = [os.getcwd(), ipython_dir] + cluster_dir_paths for p in paths: cluster_dir = os.path.join(p, dirname) if os.path.isdir(cluster_dir): @@ -229,10 +229,10 @@ class AppWithClusterDirArgParseConfigLoader(ArgParseConfigLoader): def _add_other_arguments(self): self.parser.add_argument('--ipython-dir', - dest='Global.ipythondir',type=str, - help='Set to override default location of Global.ipythondir.', + dest='Global.ipython_dir',type=str, + help='Set to override default location of Global.ipython_dir.', default=NoConfigDefault, - metavar='Global.ipythondir' + metavar='Global.ipython_dir' ) self.parser.add_argument('-p', '--profile', dest='Global.profile',type=str, @@ -270,7 +270,7 @@ class AppWithClusterDirArgParseConfigLoader(ArgParseConfigLoader): class ApplicationWithClusterDir(Application): """An application that puts everything into a cluster directory. - Instead of looking for things in the ipythondir, this type of application + Instead of looking for things in the ipython_dir, this type of application will use its own private directory called the "cluster directory" for things like config files, log files, etc. @@ -280,7 +280,7 @@ class ApplicationWithClusterDir(Application): * If ``--cluster-dir`` is not given, the application directory is resolve using the profile name as ``cluster_``. The search path for this directory is then i) cwd if it is found there - and ii) in ipythondir otherwise. + and ii) in ipython_dir otherwise. The config file for the application is to be put in the cluster dir and named the value of the ``config_file_name`` class attribute. @@ -342,7 +342,7 @@ class ApplicationWithClusterDir(Application): self.profile = self.default_config.Global.profile try: self.cluster_dir_obj = ClusterDir.find_cluster_dir_by_profile( - self.ipythondir, self.profile) + self.ipython_dir, self.profile) except ClusterDirError: pass else: @@ -354,7 +354,7 @@ class ApplicationWithClusterDir(Application): if self.auto_create_cluster_dir: self.cluster_dir_obj = ClusterDir.create_cluster_dir_by_profile( - self.ipythondir, self.profile + self.ipython_dir, self.profile ) self.log.info('Creating new cluster dir: %s' % \ self.cluster_dir_obj.location diff --git a/IPython/kernel/ipclusterapp.py b/IPython/kernel/ipclusterapp.py index b4af002..cd05a82 100644 --- a/IPython/kernel/ipclusterapp.py +++ b/IPython/kernel/ipclusterapp.py @@ -52,10 +52,10 @@ class IPClusterCLLoader(ArgParseConfigLoader): # This has all the common options that all subcommands use parent_parser1 = argparse.ArgumentParser(add_help=False) parent_parser1.add_argument('--ipython-dir', - dest='Global.ipythondir',type=str, - help='Set to override default location of Global.ipythondir.', + dest='Global.ipython_dir',type=str, + help='Set to override default location of Global.ipython_dir.', default=NoConfigDefault, - metavar='Global.ipythondir') + metavar='Global.ipython_dir') parent_parser1.add_argument('--log-level', dest="Global.log_level",type=int, help='Set the log level (0,10,20,30,40,50). Default is 30.', @@ -96,7 +96,7 @@ class IPClusterCLLoader(ArgParseConfigLoader): parser_list = subparsers.add_parser( 'list', - help='List all clusters in cwd and ipythondir.', + help='List all clusters in cwd and ipython_dir.', parents=[parent_parser1] ) @@ -140,7 +140,7 @@ class IPClusterCLLoader(ArgParseConfigLoader): help='Daemonize the ipcluster program. This implies --log-to-file', default=NoConfigDefault ) - parser_start.add_argument('--nodaemon', + parser_start.add_argument('--no-daemon', dest='Global.daemonize', action='store_false', help="Dont't daemonize the ipcluster program.", default=NoConfigDefault @@ -233,16 +233,16 @@ class IPClusterApp(ApplicationWithClusterDir): def list_cluster_dirs(self): # Find the search paths - cluster_dir_paths = os.environ.get('IPCLUSTERDIR_PATH','') + cluster_dir_paths = os.environ.get('IPCLUSTER_DIR_PATH','') if cluster_dir_paths: cluster_dir_paths = cluster_dir_paths.split(':') else: cluster_dir_paths = [] try: - ipythondir = self.command_line_config.Global.ipythondir + ipython_dir = self.command_line_config.Global.ipython_dir except AttributeError: - ipythondir = self.default_config.Global.ipythondir - paths = [os.getcwd(), ipythondir] + \ + ipython_dir = self.default_config.Global.ipython_dir + paths = [os.getcwd(), ipython_dir] + \ cluster_dir_paths paths = list(set(paths)) diff --git a/IPython/lib/irunner.py b/IPython/lib/irunner.py index 2b8dd28..5b8162f 100644 --- a/IPython/lib/irunner.py +++ b/IPython/lib/irunner.py @@ -303,11 +303,11 @@ class IPythonRunner(InteractiveRunner): def __init__(self,program = 'ipython',args=None,out=sys.stdout,echo=True): """New runner, optionally passing the ipython command to use.""" - args0 = ['-colors','NoColor', + args0 = ['--colors','NoColor', '-pi1','In [\\#]: ', '-pi2',' .\\D.: ', - '-noterm_title', - '-noautoindent'] + '--noterm-title', + '--no-auto-indent'] if args is None: args = args0 else: args = args0 + args prompts = [r'In \[\d+\]: ',r' \.*: '] diff --git a/IPython/quarantine/ipy_fsops.py b/IPython/quarantine/ipy_fsops.py index 08282fd..9121a58 100644 --- a/IPython/quarantine/ipy_fsops.py +++ b/IPython/quarantine/ipy_fsops.py @@ -141,7 +141,7 @@ def collect(ip,arg): Without args, try to open ~/_ipython/collect dir (in win32 at least). """ from IPython.external.path import path - basedir = path(ip.options.IPYTHONDIR + '/collect') + basedir = path(ip.ipython_dir + '/collect') try: fs = mglob.expand(arg.split(None,1)[1]) except IndexError: @@ -170,7 +170,7 @@ def inote(ip,arg): Without args, opens notes.txt for editing. """ import time - fname = ip.options.IPYTHONDIR + '/notes.txt' + fname = ip.ipython_dir + '/notes.txt' try: entry = " === " + time.asctime() + ': ===\n' + arg.split(None,1)[1] + '\n' diff --git a/IPython/utils/genutils.py b/IPython/utils/genutils.py index 5764fb9..996cd83 100644 --- a/IPython/utils/genutils.py +++ b/IPython/utils/genutils.py @@ -818,8 +818,11 @@ def get_ipython_dir(): """ ipdir_def = '.ipython' home_dir = get_home_dir() - ipdir = os.path.abspath(os.environ.get('IPYTHONDIR', - os.path.join(home_dir, ipdir_def))) + ipdir = os.environ.get( + 'IPYTHON_DIR', os.environ.get( + 'IPYTHONDIR', os.path.join(home_dir, ipdir_def) + ) + ) return ipdir.decode(sys.getfilesystemencoding()) diff --git a/docs/man/ipcluster.1 b/docs/man/ipcluster.1 index d04adad..418edd7 100644 --- a/docs/man/ipcluster.1 +++ b/docs/man/ipcluster.1 @@ -11,7 +11,7 @@ ipcluster is a control tool for IPython's parallel computing functions. IPython cluster startup. This starts a controller and engines using various -approaches. Use the IPYTHONDIR environment variable to change your IPython +approaches. Use the IPYTHON_DIR environment variable to change your IPython directory from the default of .ipython or _ipython. The log and security subdirectories of your IPython directory will be used by this script for log files and security files. diff --git a/docs/man/ipython.1 b/docs/man/ipython.1 index 4ec3f0e..091041e 100644 --- a/docs/man/ipython.1 +++ b/docs/man/ipython.1 @@ -141,8 +141,8 @@ may want to use a small, lightweight editor here (in case your default EDITOR is something like Emacs). .TP .B \-ipythondir -The name of your IPython configuration directory IPYTHONDIR. This can -also be specified through the environment variable IPYTHONDIR. +The name of your IPython configuration directory IPYTHON_DIR. This can +also be specified through the environment variable IPYTHON_DIR. .TP .B \-log|l Generate a log file of all input. The file is named ipython_log.py in your @@ -197,10 +197,10 @@ your config file (default off). .TP .B \-profile|p Assume that your config file is ipythonrc- (looks in current dir -first, then in IPYTHONDIR). This is a quick way to keep and load +first, then in IPYTHON_DIR). This is a quick way to keep and load multiple config files for different tasks, especially if you use the include option of config files. You can keep a basic -IPYTHONDIR/ipythonrc file and then have other 'profiles' which include +IPYTHON_DIR/ipythonrc file and then have other 'profiles' which include this one and load extra things for particular tasks. For example: .br .sp 1 @@ -244,7 +244,7 @@ Start in bare bones mode (no config file loaded). .TP .B \-rcfile Name of your IPython resource configuration file. normally IPython -loads ipythonrc (from current directory) or IPYTHONDIR/ipythonrc. If +loads ipythonrc (from current directory) or IPYTHON_DIR/ipythonrc. If the loading of your config file fails, IPython starts with a bare bones configuration (no modules loaded at all). .TP @@ -286,7 +286,7 @@ Shorthand for '\-separate_in 0 \-separate_out 0 \-separate_out2 0'. Simply removes all input/output separators. .TP .B \-upgrade -Allows you to upgrade your IPYTHONDIR configuration when you install a +Allows you to upgrade your IPYTHON_DIR configuration when you install a new version of IPython. Since new versions may include new command lines options or example files, this copies updated ipythonrc-type files. However, it backs up (with a .old extension) all files which diff --git a/docs/source/config/overview.txt b/docs/source/config/overview.txt index b6ffc21..2b79a3b 100644 --- a/docs/source/config/overview.txt +++ b/docs/source/config/overview.txt @@ -243,15 +243,15 @@ So where should you put your configuration files? By default, all IPython applications look in the so called "IPython directory". The location of this directory is determined by the following algorithm: -* If the ``-ipythondir`` command line flag is given, its value is used. +* If the ``--ipython-dir`` command line flag is given, its value is used. * If not, the value returned by :func:`IPython.utils.genutils.get_ipython_dir` - is used. This function will first look at the :envvar:`IPYTHONDIR` + is used. This function will first look at the :envvar:`IPYTHON_DIR` environment variable and then default to the directory - :file:`$HOME/.ipythondir`. + :file:`$HOME/.ipython`. For most users, the default value will simply be something like -:file:`$HOME/.ipythondir`. +:file:`$HOME/.ipython`. Once the location of the IPython directory has been determined, you need to know what filename to use for the configuration file. The basic idea is that diff --git a/docs/source/interactive/reference.txt b/docs/source/interactive/reference.txt index 20bdecb..584789d 100644 --- a/docs/source/interactive/reference.txt +++ b/docs/source/interactive/reference.txt @@ -31,7 +31,7 @@ your ipythonrc configuration file for details on those. This file typically installed in the $HOME/.ipython directory. For Windows users, $HOME resolves to C:\\Documents and Settings\\YourUserName in most instances. In the rest of this text, we will refer to this directory as -IPYTHONDIR. +IPYTHON_DIR. @@ -150,9 +150,9 @@ All options with a [no] prepended can be specified in negated form something like Emacs). -ipythondir - name of your IPython configuration directory IPYTHONDIR. This + name of your IPython configuration directory IPYTHON_DIR. This can also be specified through the environment variable - IPYTHONDIR. + IPYTHON_DIR. -log, l generate a log file of all input. The file is named @@ -211,10 +211,10 @@ All options with a [no] prepended can be specified in negated form assume that your config file is ipythonrc- or ipy_profile_.py (looks in current dir first, then in - IPYTHONDIR). This is a quick way to keep and load multiple + IPYTHON_DIR). This is a quick way to keep and load multiple config files for different tasks, especially if you use the include option of config files. You can keep a basic - IPYTHONDIR/ipythonrc file and then have other 'profiles' which + IPYTHON_DIR/ipythonrc file and then have other 'profiles' which include this one and load extra things for particular tasks. For example: @@ -252,7 +252,7 @@ All options with a [no] prepended can be specified in negated form -rcfile name of your IPython resource configuration file. Normally IPython loads ipythonrc (from current directory) or - IPYTHONDIR/ipythonrc. + IPYTHON_DIR/ipythonrc. If the loading of your config file fails, IPython starts with a bare bones configuration (no modules loaded at all). @@ -299,7 +299,7 @@ All options with a [no] prepended can be specified in negated form 0'. Simply removes all input/output separators. -upgrade - allows you to upgrade your IPYTHONDIR configuration when you + allows you to upgrade your IPYTHON_DIR configuration when you install a new version of IPython. Since new versions may include new command line options or example files, this copies updated ipythonrc-type files. However, it backs up (with a @@ -542,7 +542,7 @@ Persistent command history across sessions IPython will save your input history when it leaves and reload it next time you restart it. By default, the history file is named -$IPYTHONDIR/history, but if you've loaded a named profile, +$IPYTHON_DIR/history, but if you've loaded a named profile, '-PROFILE_NAME' is appended to the name. This allows you to keep separate histories related to various tasks: commands related to numerical work will not be clobbered by a system shell history, for @@ -636,7 +636,7 @@ follows: %logstart [log_name [log_mode]] If no name is given, it defaults to a file named 'log' in your -IPYTHONDIR directory, in 'rotate' mode (see below). +IPYTHON_DIR directory, in 'rotate' mode (see below). '%logstart name' saves to file 'name' in 'backup' mode. It saves your history up to that point and then continues logging.