##// END OF EJS Templates
make config_file_paths List instead of Unicode
MinRK -
Show More
@@ -1,133 +1,133 b''
1 1 # encoding: utf-8
2 2 """
3 3 An application for IPython.
4 4
5 5 All top-level applications should use the classes in this module for
6 6 handling configuration and creating componenets.
7 7
8 8 The job of an :class:`Application` is to create the master configuration
9 9 object and then create the configurable objects, passing the config to them.
10 10
11 11 Authors:
12 12
13 13 * Brian Granger
14 14 * Fernando Perez
15 15
16 16 Notes
17 17 -----
18 18 """
19 19
20 20 #-----------------------------------------------------------------------------
21 21 # Copyright (C) 2008-2009 The IPython Development Team
22 22 #
23 23 # Distributed under the terms of the BSD License. The full license is in
24 24 # the file COPYING, distributed as part of this software.
25 25 #-----------------------------------------------------------------------------
26 26
27 27 #-----------------------------------------------------------------------------
28 28 # Imports
29 29 #-----------------------------------------------------------------------------
30 30
31 31 import os
32 32 import sys
33 33
34 34 from IPython.config.application import Application
35 35 from IPython.core import release, crashhandler
36 36 from IPython.utils.path import get_ipython_dir, get_ipython_package_dir
37 from IPython.utils.traitlets import Tuple, Unicode, Type
37 from IPython.utils.traitlets import List, Unicode, Type
38 38
39 39 #-----------------------------------------------------------------------------
40 40 # Classes and functions
41 41 #-----------------------------------------------------------------------------
42 42
43 43
44 44 class BaseIPythonApplication(Application):
45 45
46 46 name = Unicode(u'ipython')
47 47 description = Unicode(u'IPython: an enhanced interactive Python shell.')
48 48 version = Unicode(release.version)
49 49
50 50 # The name of the default config file. Track separately from the actual
51 51 # name because some logic happens only if we aren't using the default.
52 52 default_config_file_name = Unicode(u'ipython_config.py')
53 53
54 54 # The directory that contains IPython's builtin profiles.
55 55 builtin_profile_dir = Unicode(
56 56 os.path.join(get_ipython_package_dir(), u'config', u'profile')
57 57 )
58 58
59 config_file_paths = Tuple(Unicode, Unicode, Unicode)
59 config_file_paths = List(Unicode)
60 60 def _config_file_paths_default(self):
61 return (os.getcwdu(), self.ipython_dir, self.builtin_profile_dir)
61 return [os.getcwdu(), self.ipython_dir, self.builtin_profile_dir]
62 62
63 63 profile_name = Unicode(u'', config=True,
64 64 help="""The IPython profile to use."""
65 65 )
66 66
67 67 ipython_dir = Unicode(get_ipython_dir(), config=True, help=
68 68 """
69 69 The name of the IPython directory. This directory is used for logging
70 70 configuration (through profiles), history storage, etc. The default
71 71 is usually $HOME/.ipython. This options can also be specified through
72 72 the environment variable IPYTHON_DIR.
73 73 """
74 74 )
75 75
76 76 # The class to use as the crash handler.
77 77 crash_handler_class = Type(crashhandler.CrashHandler)
78 78
79 79 #-------------------------------------------------------------------------
80 80 # Various stages of Application creation
81 81 #-------------------------------------------------------------------------
82 82
83 83 def init_crash_handler(self):
84 84 """Create a crash handler, typically setting sys.excepthook to it."""
85 85 self.crash_handler = self.crash_handler_class(self)
86 86 sys.excepthook = self.crash_handler
87 87
88 88 def _ipython_dir_changed(self, name, old, new):
89 89 if old in sys.path:
90 90 sys.path.remove(old)
91 91 sys.path.append(os.path.abspath(new))
92 92 if not os.path.isdir(new):
93 93 os.makedirs(new, mode=0777)
94 94 self.config_file_paths = (os.getcwdu(), new, self.builtin_profile_dir)
95 95 self.log.debug("IPYTHON_DIR set to: %s" % new)
96 96
97 97 @property
98 98 def config_file_name(self):
99 99 """Find the config file name for this application."""
100 100 if self.profile_name:
101 101 name_parts = self.default_config_file_name.split('.')
102 102 name_parts.insert(1, u'_' + self.profile_name + u'.')
103 103 return ''.join(name_parts)
104 104 else:
105 105 return self.default_config_file_name
106 106
107 107 def load_config_file(self, suppress_errors=True):
108 108 """Load the config file.
109 109
110 110 By default, errors in loading config are handled, and a warning
111 111 printed on screen. For testing, the suppress_errors option is set
112 112 to False, so errors will make tests fail.
113 113 """
114 114 self.log.debug("Attempting to load config file: %s" %
115 115 self.config_file_name)
116 116 try:
117 117 Application.load_config_file(
118 118 self,
119 119 self.config_file_name,
120 120 path=self.config_file_paths
121 121 )
122 122 except IOError:
123 123 # Only warn if the default config file was NOT being used.
124 124 if not self.config_file_name == self.default_config_file_name:
125 125 self.log.warn("Config file not found, skipping: %s" %
126 126 self.config_file_name, exc_info=True)
127 127 except:
128 128 # For testing purposes.
129 129 if not suppress_errors:
130 130 raise
131 131 self.log.warn("Error loading config file: %s" %
132 132 self.config_file_name, exc_info=True)
133 133
General Comments 0
You need to be logged in to leave comments. Login now