
1Xc           @   sE   d  Z  d d l Z d d l m Z d d l m Z d d d  Z d S(   s0   Simple function for embedding an IPython kernel
iN(   t   extract_module_localsi   (   t   IPKernelAppc         K   s   t  j   r t  j   } nP t  j |   } | j g   | j j j } | d k	 rk | t j	 | j j j
 <n  t d  \ } } |  d k r | }  n  | d k r | } n  |  | j _ | | j _ | j j   | j   d S(   s  Embed and start an IPython kernel in a given scope.

    Parameters
    ----------
    module : ModuleType, optional
        The module to load into IPython globals (default: caller)
    local_ns : dict, optional
        The namespace to load into IPython user namespace (default: caller)

    kwargs : various, optional
        Further keyword args are relayed to the IPKernelApp constructor,
        allowing configuration of the Kernel.  Will only have an effect
        on the first embed_kernel call for a given process.

    i   N(   R   t   initializedt   instancet
   initializet   kernelt   shellt   _orig_sys_modules_main_modt   Nonet   syst   modulest   _orig_sys_modules_main_nameR    t   user_modulet   user_nst   set_completer_framet   start(   t   modulet   local_nst   kwargst   appt   maint   caller_modulet   caller_locals(    (    s.   lib/python2.7/site-packages/ipykernel/embed.pyt   embed_kernel   s     		(   t   __doc__R	   t   IPython.utils.frameR    t	   kernelappR   R   R   (    (    (    s.   lib/python2.7/site-packages/ipykernel/embed.pyt   <module>   s   