Show More
@@ -100,7 +100,7 b" shell_aliases['cache-size'] = 'InteractiveShell.cache_size'" | |||||
100 |
|
100 | |||
101 | class InteractiveShellApp(Configurable): |
|
101 | class InteractiveShellApp(Configurable): | |
102 | """A Mixin for applications that start InteractiveShell instances. |
|
102 | """A Mixin for applications that start InteractiveShell instances. | |
103 |
|
103 | |||
104 | Provides configurables for loading extensions and executing files |
|
104 | Provides configurables for loading extensions and executing files | |
105 | as part of configuring a Shell environment. |
|
105 | as part of configuring a Shell environment. | |
106 |
|
106 | |||
@@ -126,7 +126,7 b' class InteractiveShellApp(Configurable):' | |||||
126 |
|
126 | |||
127 | # Extensions that are always loaded (not configurable) |
|
127 | # Extensions that are always loaded (not configurable) | |
128 | default_extensions = List(Unicode(), [u'storemagic']).tag(config=False) |
|
128 | default_extensions = List(Unicode(), [u'storemagic']).tag(config=False) | |
129 |
|
129 | |||
130 | hide_initial_ns = Bool(True, |
|
130 | hide_initial_ns = Bool(True, | |
131 | help="""Should variables loaded at startup (by startup files, exec_lines, etc.) |
|
131 | help="""Should variables loaded at startup (by startup files, exec_lines, etc.) | |
132 | be hidden from tools like %who?""" |
|
132 | be hidden from tools like %who?""" | |
@@ -166,7 +166,7 b' class InteractiveShellApp(Configurable):' | |||||
166 | pylab_import_all = Bool(True, |
|
166 | pylab_import_all = Bool(True, | |
167 | help="""If true, IPython will populate the user namespace with numpy, pylab, etc. |
|
167 | help="""If true, IPython will populate the user namespace with numpy, pylab, etc. | |
168 | and an ``import *`` is done from numpy and pylab, when using pylab mode. |
|
168 | and an ``import *`` is done from numpy and pylab, when using pylab mode. | |
169 |
|
169 | |||
170 | When False, pylab mode should not import any names into the user namespace. |
|
170 | When False, pylab mode should not import any names into the user namespace. | |
171 | """ |
|
171 | """ | |
172 | ).tag(config=True) |
|
172 | ).tag(config=True) | |
@@ -174,7 +174,7 b' class InteractiveShellApp(Configurable):' | |||||
174 | allow_none=True) |
|
174 | allow_none=True) | |
175 | # whether interact-loop should start |
|
175 | # whether interact-loop should start | |
176 | interact = Bool(True) |
|
176 | interact = Bool(True) | |
177 |
|
177 | |||
178 | user_ns = Instance(dict, args=None, allow_none=True) |
|
178 | user_ns = Instance(dict, args=None, allow_none=True) | |
179 | @observe('user_ns') |
|
179 | @observe('user_ns') | |
180 | def _user_ns_changed(self, change): |
|
180 | def _user_ns_changed(self, change): | |
@@ -203,10 +203,10 b' class InteractiveShellApp(Configurable):' | |||||
203 | elif self.gui: |
|
203 | elif self.gui: | |
204 | enable = shell.enable_gui |
|
204 | enable = shell.enable_gui | |
205 | key = self.gui |
|
205 | key = self.gui | |
206 |
|
206 | |||
207 | if not enable: |
|
207 | if not enable: | |
208 | return |
|
208 | return | |
209 |
|
209 | |||
210 | try: |
|
210 | try: | |
211 | r = enable(key) |
|
211 | r = enable(key) | |
212 | except ImportError: |
|
212 | except ImportError: | |
@@ -217,7 +217,7 b' class InteractiveShellApp(Configurable):' | |||||
217 | self.log.warning("GUI event loop or pylab initialization failed") |
|
217 | self.log.warning("GUI event loop or pylab initialization failed") | |
218 | self.shell.showtraceback() |
|
218 | self.shell.showtraceback() | |
219 | return |
|
219 | return | |
220 |
|
220 | |||
221 | if isinstance(r, tuple): |
|
221 | if isinstance(r, tuple): | |
222 | gui, backend = r[:2] |
|
222 | gui, backend = r[:2] | |
223 | self.log.info("Enabling GUI event loop integration, " |
|
223 | self.log.info("Enabling GUI event loop integration, " | |
@@ -263,16 +263,16 b' class InteractiveShellApp(Configurable):' | |||||
263 | self._run_startup_files() |
|
263 | self._run_startup_files() | |
264 | self._run_exec_lines() |
|
264 | self._run_exec_lines() | |
265 | self._run_exec_files() |
|
265 | self._run_exec_files() | |
266 |
|
266 | |||
267 | # Hide variables defined here from %who etc. |
|
267 | # Hide variables defined here from %who etc. | |
268 | if self.hide_initial_ns: |
|
268 | if self.hide_initial_ns: | |
269 | self.shell.user_ns_hidden.update(self.shell.user_ns) |
|
269 | self.shell.user_ns_hidden.update(self.shell.user_ns) | |
270 |
|
270 | |||
271 | # command-line execution (ipython -i script.py, ipython -m module) |
|
271 | # command-line execution (ipython -i script.py, ipython -m module) | |
272 | # should *not* be excluded from %whos |
|
272 | # should *not* be excluded from %whos | |
273 | self._run_cmd_line_code() |
|
273 | self._run_cmd_line_code() | |
274 | self._run_module() |
|
274 | self._run_module() | |
275 |
|
275 | |||
276 | # flush output, so itwon't be attached to the first cell |
|
276 | # flush output, so itwon't be attached to the first cell | |
277 | sys.stdout.flush() |
|
277 | sys.stdout.flush() | |
278 | sys.stderr.flush() |
|
278 | sys.stderr.flush() | |
@@ -333,7 +333,7 b' class InteractiveShellApp(Configurable):' | |||||
333 | """Run files from profile startup directory""" |
|
333 | """Run files from profile startup directory""" | |
334 | startup_dir = self.profile_dir.startup_dir |
|
334 | startup_dir = self.profile_dir.startup_dir | |
335 | startup_files = [] |
|
335 | startup_files = [] | |
336 |
|
336 | |||
337 | if self.exec_PYTHONSTARTUP and os.environ.get('PYTHONSTARTUP', False) and \ |
|
337 | if self.exec_PYTHONSTARTUP and os.environ.get('PYTHONSTARTUP', False) and \ | |
338 | not (self.file_to_run or self.code_to_run or self.module_to_run): |
|
338 | not (self.file_to_run or self.code_to_run or self.module_to_run): | |
339 | python_startup = os.environ['PYTHONSTARTUP'] |
|
339 | python_startup = os.environ['PYTHONSTARTUP'] | |
@@ -343,12 +343,12 b' class InteractiveShellApp(Configurable):' | |||||
343 | except: |
|
343 | except: | |
344 | self.log.warning("Unknown error in handling PYTHONSTARTUP file %s:", python_startup) |
|
344 | self.log.warning("Unknown error in handling PYTHONSTARTUP file %s:", python_startup) | |
345 | self.shell.showtraceback() |
|
345 | self.shell.showtraceback() | |
346 |
|
346 | |||
347 | startup_files += glob.glob(os.path.join(startup_dir, '*.py')) |
|
347 | startup_files += glob.glob(os.path.join(startup_dir, '*.py')) | |
348 | startup_files += glob.glob(os.path.join(startup_dir, '*.ipy')) |
|
348 | startup_files += glob.glob(os.path.join(startup_dir, '*.ipy')) | |
349 | if not startup_files: |
|
349 | if not startup_files: | |
350 | return |
|
350 | return | |
351 |
|
351 | |||
352 | self.log.debug("Running startup files from %s...", startup_dir) |
|
352 | self.log.debug("Running startup files from %s...", startup_dir) | |
353 | try: |
|
353 | try: | |
354 | for fname in sorted(startup_files): |
|
354 | for fname in sorted(startup_files): | |
@@ -388,6 +388,8 b' class InteractiveShellApp(Configurable):' | |||||
388 | # Like Python itself, ignore the second if the first of these is present |
|
388 | # Like Python itself, ignore the second if the first of these is present | |
389 | elif self.file_to_run: |
|
389 | elif self.file_to_run: | |
390 | fname = self.file_to_run |
|
390 | fname = self.file_to_run | |
|
391 | if os.path.isdir(fname): | |||
|
392 | fname = os.path.join(fname, "__main__.py") | |||
391 | try: |
|
393 | try: | |
392 | self._exec_file(fname, shell_futures=True) |
|
394 | self._exec_file(fname, shell_futures=True) | |
393 | except: |
|
395 | except: |
General Comments 0
You need to be logged in to leave comments.
Login now