##// END OF EJS Templates
Rename user_local_ns back to user_ns for simplicity.
Thomas Kluyver -
Show More
@@ -372,7 +372,7 b' class InteractiveShell(SingletonConfigurable, Magic):'
372 _post_execute = Instance(dict)
372 _post_execute = Instance(dict)
373
373
374 def __init__(self, config=None, ipython_dir=None, profile_dir=None,
374 def __init__(self, config=None, ipython_dir=None, profile_dir=None,
375 user_module=None, user_local_ns=None,
375 user_module=None, user_ns=None,
376 custom_exceptions=((), None)):
376 custom_exceptions=((), None)):
377
377
378 # This is where traits with a config_key argument are updated
378 # This is where traits with a config_key argument are updated
@@ -387,7 +387,7 b' class InteractiveShell(SingletonConfigurable, Magic):'
387 self.init_environment()
387 self.init_environment()
388
388
389 # Create namespaces (user_ns, user_global_ns, etc.)
389 # Create namespaces (user_ns, user_global_ns, etc.)
390 self.init_create_namespaces(user_module, user_local_ns)
390 self.init_create_namespaces(user_module, user_ns)
391 # This has to be done after init_create_namespaces because it uses
391 # This has to be done after init_create_namespaces because it uses
392 # something in self.user_ns, but before init_sys_modules, which
392 # something in self.user_ns, but before init_sys_modules, which
393 # is the first thing to modify sys.
393 # is the first thing to modify sys.
@@ -639,17 +639,14 b' class InteractiveShell(SingletonConfigurable, Magic):'
639 def save_sys_module_state(self):
639 def save_sys_module_state(self):
640 """Save the state of hooks in the sys module.
640 """Save the state of hooks in the sys module.
641
641
642 This has to be called after self.user_ns is created.
642 This has to be called after self.user_module is created.
643 """
643 """
644 self._orig_sys_module_state = {}
644 self._orig_sys_module_state = {}
645 self._orig_sys_module_state['stdin'] = sys.stdin
645 self._orig_sys_module_state['stdin'] = sys.stdin
646 self._orig_sys_module_state['stdout'] = sys.stdout
646 self._orig_sys_module_state['stdout'] = sys.stdout
647 self._orig_sys_module_state['stderr'] = sys.stderr
647 self._orig_sys_module_state['stderr'] = sys.stderr
648 self._orig_sys_module_state['excepthook'] = sys.excepthook
648 self._orig_sys_module_state['excepthook'] = sys.excepthook
649 try:
649 self._orig_sys_modules_main_name = self.user_module.__name__
650 self._orig_sys_modules_main_name = self.user_ns['__name__']
651 except KeyError:
652 pass
653
650
654 def restore_sys_module_state(self):
651 def restore_sys_module_state(self):
655 """Restore the state of the sys module."""
652 """Restore the state of the sys module."""
@@ -659,10 +656,7 b' class InteractiveShell(SingletonConfigurable, Magic):'
659 except AttributeError:
656 except AttributeError:
660 pass
657 pass
661 # Reset what what done in self.init_sys_modules
658 # Reset what what done in self.init_sys_modules
662 try:
659 sys.modules[self.user_module.__name__] = self._orig_sys_modules_main_name
663 sys.modules[self.user_ns['__name__']] = self._orig_sys_modules_main_name
664 except (AttributeError, KeyError):
665 pass
666
660
667 #-------------------------------------------------------------------------
661 #-------------------------------------------------------------------------
668 # Things related to hooks
662 # Things related to hooks
@@ -860,7 +854,7 b' class InteractiveShell(SingletonConfigurable, Magic):'
860 # Things related to IPython's various namespaces
854 # Things related to IPython's various namespaces
861 #-------------------------------------------------------------------------
855 #-------------------------------------------------------------------------
862
856
863 def init_create_namespaces(self, user_module=None, user_local_ns=None):
857 def init_create_namespaces(self, user_module=None, user_ns=None):
864 # Create the namespace where the user will operate. user_ns is
858 # Create the namespace where the user will operate. user_ns is
865 # normally the only one used, and it is passed to the exec calls as
859 # normally the only one used, and it is passed to the exec calls as
866 # the locals argument. But we do carry a user_global_ns namespace
860 # the locals argument. But we do carry a user_global_ns namespace
@@ -899,9 +893,9 b' class InteractiveShell(SingletonConfigurable, Magic):'
899 # properly initialized namespaces.
893 # properly initialized namespaces.
900 self.user_module = self.prepare_user_module(user_module)
894 self.user_module = self.prepare_user_module(user_module)
901
895
902 if user_local_ns is None:
896 if user_ns is None:
903 user_local_ns = self.user_module.__dict__
897 user_ns = self.user_module.__dict__
904 self.user_local_ns = user_local_ns
898 self.user_ns = user_ns
905
899
906 # An auxiliary namespace that checks what parts of the user_ns were
900 # An auxiliary namespace that checks what parts of the user_ns were
907 # loaded at startup, so we can list later only variables defined in
901 # loaded at startup, so we can list later only variables defined in
@@ -944,8 +938,8 b' class InteractiveShell(SingletonConfigurable, Magic):'
944
938
945 # A table holding all the namespaces IPython deals with, so that
939 # A table holding all the namespaces IPython deals with, so that
946 # introspection facilities can search easily.
940 # introspection facilities can search easily.
947 self.ns_table = {'user_global':user_module.__dict__,
941 self.ns_table = {'user_global':self.user_module.__dict__,
948 'user_local':user_local_ns,
942 'user_local':user_ns,
949 'internal':self.internal_ns,
943 'internal':self.internal_ns,
950 'builtin':builtin_mod.__dict__
944 'builtin':builtin_mod.__dict__
951 }
945 }
@@ -1073,7 +1067,7 b' class InteractiveShell(SingletonConfigurable, Magic):'
1073 # stuff, not our variables.
1067 # stuff, not our variables.
1074
1068
1075 # Finally, update the real user's namespace
1069 # Finally, update the real user's namespace
1076 self.user_local_ns.update(ns)
1070 self.user_ns.update(ns)
1077
1071
1078 def reset(self, new_session=True):
1072 def reset(self, new_session=True):
1079 """Clear all internal namespaces, and attempt to release references to
1073 """Clear all internal namespaces, and attempt to release references to
@@ -172,13 +172,13 b' class TerminalInteractiveShell(InteractiveShell):'
172 )
172 )
173
173
174 def __init__(self, config=None, ipython_dir=None, profile_dir=None, user_ns=None,
174 def __init__(self, config=None, ipython_dir=None, profile_dir=None, user_ns=None,
175 user_global_ns=None, custom_exceptions=((),None),
175 user_module=None, custom_exceptions=((),None),
176 usage=None, banner1=None, banner2=None,
176 usage=None, banner1=None, banner2=None,
177 display_banner=None):
177 display_banner=None):
178
178
179 super(TerminalInteractiveShell, self).__init__(
179 super(TerminalInteractiveShell, self).__init__(
180 config=config, profile_dir=profile_dir, user_ns=user_ns,
180 config=config, profile_dir=profile_dir, user_ns=user_ns,
181 user_global_ns=user_global_ns, custom_exceptions=custom_exceptions
181 user_module=user_module, custom_exceptions=custom_exceptions
182 )
182 )
183 # use os.system instead of utils.process.system by default,
183 # use os.system instead of utils.process.system by default,
184 # because piped system doesn't make sense in the Terminal:
184 # because piped system doesn't make sense in the Terminal:
General Comments 0
You need to be logged in to leave comments. Login now