Show More
@@ -34,7 +34,7 b' import os' | |||
|
34 | 34 | import sys |
|
35 | 35 | |
|
36 | 36 | from IPython.core import release |
|
37 | from IPython.utils.genutils import get_ipython_dir | |
|
37 | from IPython.utils.genutils import get_ipython_dir, get_ipython_package_dir | |
|
38 | 38 | from IPython.config.loader import ( |
|
39 | 39 | PyFileConfigLoader, |
|
40 | 40 | ArgParseConfigLoader, |
@@ -82,15 +82,22 b' class Application(object):' | |||
|
82 | 82 | |
|
83 | 83 | name = u'ipython' |
|
84 | 84 | description = 'IPython: an enhanced interactive Python shell.' |
|
85 | ||
|
85 | 86 | config_file_name = u'ipython_config.py' |
|
87 | # Track the default and actual separately because some messages are | |
|
88 | # only printed if we aren't using the default. | |
|
89 | default_config_file_name = config_file_name | |
|
86 | 90 | default_log_level = logging.WARN |
|
91 | # Set by --profile option | |
|
92 | profile_name = None | |
|
93 | # User's ipython directory, typically ~/.ipython/ | |
|
94 | ipython_dir = None | |
|
95 | ||
|
96 | # Private attributes | |
|
97 | _exiting = False | |
|
87 | 98 | |
|
88 | 99 | def __init__(self): |
|
89 | self._exiting = False | |
|
90 | 100 | self.init_logger() |
|
91 | # Track the default and actual separately because some messages are | |
|
92 | # only printed if we aren't using the default. | |
|
93 | self.default_config_file_name = self.config_file_name | |
|
94 | 101 | |
|
95 | 102 | def init_logger(self): |
|
96 | 103 | self.log = logging.getLogger(self.__class__.__name__) |
@@ -197,10 +204,10 b' class Application(object):' | |||
|
197 | 204 | def find_ipython_dir(self): |
|
198 | 205 | """Set the IPython directory. |
|
199 | 206 | |
|
200 | This sets ``self.ipython_dir``, but the actual value that is passed | |
|
201 |
t |
|
|
207 | This sets ``self.ipython_dir``, but the actual value that is passed to | |
|
208 | the application is kept in either ``self.default_config`` or | |
|
202 | 209 | ``self.command_line_config``. This also adds ``self.ipython_dir`` to |
|
203 |
``sys.path`` so config files there can be reference |
|
|
210 | ``sys.path`` so config files there can be referenced by other config | |
|
204 | 211 | files. |
|
205 | 212 | """ |
|
206 | 213 | |
@@ -230,8 +237,7 b' class Application(object):' | |||
|
230 | 237 | config file are set in :meth:`find_config_file_paths` and then passed |
|
231 | 238 | to the config file loader where they are resolved to an absolute path. |
|
232 | 239 | |
|
233 | If a profile has been set at the command line, this will resolve | |
|
234 | it. | |
|
240 | If a profile has been set at the command line, this will resolve it. | |
|
235 | 241 | """ |
|
236 | 242 | |
|
237 | 243 | try: |
@@ -241,11 +247,12 b' class Application(object):' | |||
|
241 | 247 | |
|
242 | 248 | try: |
|
243 | 249 | self.profile_name = self.command_line_config.Global.profile |
|
250 | except AttributeError: | |
|
251 | pass | |
|
252 | else: | |
|
244 | 253 | name_parts = self.config_file_name.split('.') |
|
245 | 254 | name_parts.insert(1, u'_' + self.profile_name + u'.') |
|
246 | 255 | self.config_file_name = ''.join(name_parts) |
|
247 | except AttributeError: | |
|
248 | pass | |
|
249 | 256 | |
|
250 | 257 | def find_config_file_paths(self): |
|
251 | 258 | """Set the search paths for resolving the config file. |
@@ -253,7 +260,11 b' class Application(object):' | |||
|
253 | 260 | This must set ``self.config_file_paths`` to a sequence of search |
|
254 | 261 | paths to pass to the config file loader. |
|
255 | 262 | """ |
|
256 | self.config_file_paths = (os.getcwd(), self.ipython_dir) | |
|
263 | # Include our own profiles directory last, so that users can still find | |
|
264 | # our shipped copies of builtin profiles even if they don't have them | |
|
265 | # in their local ipython directory. | |
|
266 | prof_dir = os.path.join(get_ipython_package_dir(), 'config', 'profile') | |
|
267 | self.config_file_paths = (os.getcwd(), self.ipython_dir,prof_dir) | |
|
257 | 268 | |
|
258 | 269 | def pre_load_file_config(self): |
|
259 | 270 | """Do actions before the config file is loaded.""" |
@@ -266,7 +277,8 b' class Application(object):' | |||
|
266 | 277 | ``CONFIG_FILE`` config variable is set to the resolved config file |
|
267 | 278 | location. If not successful, an empty config is used. |
|
268 | 279 | """ |
|
269 |
self.log.debug("Attempting to load config file: %s" % |
|
|
280 | self.log.debug("Attempting to load config file: %s" % | |
|
281 | self.config_file_name) | |
|
270 | 282 | loader = PyFileConfigLoader(self.config_file_name, |
|
271 | 283 | path=self.config_file_paths) |
|
272 | 284 | try: |
@@ -275,11 +287,11 b' class Application(object):' | |||
|
275 | 287 | except IOError: |
|
276 | 288 | # Only warn if the default config file was NOT being used. |
|
277 | 289 | if not self.config_file_name==self.default_config_file_name: |
|
278 |
self.log.warn("Config file not found, skipping: %s" % |
|
|
290 | self.log.warn("Config file not found, skipping: %s" % | |
|
279 | 291 | self.config_file_name, exc_info=True) |
|
280 | 292 | self.file_config = Config() |
|
281 | 293 | except: |
|
282 |
self.log.warn("Error loading config file: %s" % |
|
|
294 | self.log.warn("Error loading config file: %s" % | |
|
283 | 295 | self.config_file_name, exc_info=True) |
|
284 | 296 | self.file_config = Config() |
|
285 | 297 | |
@@ -299,7 +311,8 b' class Application(object):' | |||
|
299 | 311 | |
|
300 | 312 | def log_file_config(self): |
|
301 | 313 | if hasattr(self.file_config.Global, 'config_file'): |
|
302 |
self.log.debug("Config file loaded: %s" % |
|
|
314 | self.log.debug("Config file loaded: %s" % | |
|
315 | self.file_config.Global.config_file) | |
|
303 | 316 | self.log.debug(repr(self.file_config)) |
|
304 | 317 | |
|
305 | 318 | def merge_configs(self): |
@@ -292,6 +292,24 b' class IPythonAppCLConfigLoader(BaseAppArgParseConfigLoader):' | |||
|
292 | 292 | |
|
293 | 293 | arguments = cl_args |
|
294 | 294 | |
|
295 | def load_config(self): | |
|
296 | """Do actions just before loading the command line config.""" | |
|
297 | ||
|
298 | # Special hack: there are countless uses of 'ipython -pylab' (with one | |
|
299 | # dash) in the wild, including in printed books. Since argparse does | |
|
300 | # will interpret -pylab as '-p ylab', sending us in a search for a | |
|
301 | # profile named 'ylab', instead we special-case here -pylab as the | |
|
302 | # first or second option only (this is how old ipython used to work) | |
|
303 | # and convert this use to --pylab. Ugly, but needed for this one | |
|
304 | # very widely used case. | |
|
305 | firstargs = sys.argv[:3] | |
|
306 | try: | |
|
307 | idx = firstargs.index('-pylab') | |
|
308 | except ValueError: | |
|
309 | pass | |
|
310 | else: | |
|
311 | sys.argv[idx] = '--pylab' | |
|
312 | return super(IPythonAppCLConfigLoader, self).load_config() | |
|
295 | 313 | |
|
296 | 314 | default_config_file_name = u'ipython_config.py' |
|
297 | 315 | |
@@ -303,22 +321,25 b' class IPythonApp(Application):' | |||
|
303 | 321 | |
|
304 | 322 | def create_default_config(self): |
|
305 | 323 | super(IPythonApp, self).create_default_config() |
|
306 | self.default_config.Global.display_banner = True | |
|
324 | # Eliminate multiple lookups | |
|
325 | Global = self.default_config.Global | |
|
326 | # Set all default values | |
|
327 | Global.display_banner = True | |
|
307 | 328 | |
|
308 | 329 | # If the -c flag is given or a file is given to run at the cmd line |
|
309 | 330 | # like "ipython foo.py", normally we exit without starting the main |
|
310 | 331 | # loop. The force_interact config variable allows a user to override |
|
311 | 332 | # this and interact. It is also set by the -i cmd line flag, just |
|
312 | 333 | # like Python. |
|
313 |
|
|
|
334 | Global.force_interact = False | |
|
314 | 335 | |
|
315 | 336 | # By default always interact by starting the IPython mainloop. |
|
316 |
|
|
|
337 | Global.interact = True | |
|
317 | 338 | |
|
318 | 339 | # No GUI integration by default |
|
319 |
|
|
|
320 |
|
|
|
321 |
|
|
|
340 | Global.wthread = False | |
|
341 | Global.q4thread = False | |
|
342 | Global.gthread = False | |
|
322 | 343 | |
|
323 | 344 | def create_command_line_config(self): |
|
324 | 345 | """Create and return a command line config loader.""" |
@@ -46,11 +46,6 b' from IPython.utils import platutils' | |||
|
46 | 46 | from IPython.utils.generics import result_display |
|
47 | 47 | from IPython.external.path import path |
|
48 | 48 | |
|
49 | try: | |
|
50 | set | |
|
51 | except: | |
|
52 | from sets import Set as set | |
|
53 | ||
|
54 | 49 | |
|
55 | 50 | #**************************************************************************** |
|
56 | 51 | # Exceptions |
@@ -824,6 +819,12 b' def get_ipython_dir():' | |||
|
824 | 819 | return ipdir.decode(sys.getfilesystemencoding()) |
|
825 | 820 | |
|
826 | 821 | |
|
822 | def get_ipython_package_dir(): | |
|
823 | """Get the base directory where IPython itself is installed.""" | |
|
824 | ipdir = os.path.dirname(IPython.__file__) | |
|
825 | return ipdir.decode(sys.getfilesystemencoding()) | |
|
826 | ||
|
827 | ||
|
827 | 828 | #**************************************************************************** |
|
828 | 829 | # strings and text |
|
829 | 830 |
General Comments 0
You need to be logged in to leave comments.
Login now