ó
Ű¤[c           @  s4  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 m
 Z
 e j j Z d e j d Z e e j j e  d  Z d d d d	  Z d d
  Z d d d d  Z d e e d d d d  Z d d l m Z d e f d     YZ e d k r0e j   n  d S(   s#   The IPython kernel spec for Jupyteri˙˙˙˙(   t   print_functionN(   t   KernelSpecManagers   python%ii    t	   resourcest   ipykernel_launcherc         K  sJ   | d k r t j } n  | p! g  } | d |  d d g } | j |  | S(   sň  Build Popen command list for launching an IPython kernel.

    Parameters
    ----------
    mod : str, optional (default 'ipykernel')
        A string of an IPython module whose __main__ starts an IPython kernel

    executable : str, optional (default sys.executable)
        The Python executable to use for the kernel process.

    extra_arguments : list, optional
        A list of extra arguments to pass when executing the launch code.

    Returns
    -------

    A Popen command list
    s   -ms   -fs   {connection_file}N(   t   Nonet   syst
   executablet   extend(   t   modR   t   extra_argumentst   kwt	   arguments(    (    s3   lib/python2.7/site-packages/ipykernel/kernelspec.pyt   make_ipkernel_cmd   s    c         C  s-   i t  d |   d 6d t j d d 6d d 6S(   s   Construct dict for kernel.jsonR	   t   argvs	   Python %ii    t   display_namet   pythont   language(   R   R   t   version_info(   R	   (    (    s3   lib/python2.7/site-packages/ipykernel/kernelspec.pyt   get_kernel_dict5   s    c      	   C  s   |  d k r0 t j j t j d d  t  }  n  t j t	 |   t
 |  } | rb | j |  n  t t |  d  d   } t j | | d d Wd QX|  S(   s÷   Write a kernel spec directory to `path`
    
    If `path` is not specified, a temporary directory is created.
    If `overrides` is given, the kernelspec JSON is updated before writing.
    
    The path to the kernelspec is always returned.
    t   suffixt   _kernelss   kernel.jsont   wt   indenti   N(   R   t   ost   patht   joint   tempfilet   mkdtempt   KERNEL_NAMEt   shutilt   copytreet	   RESOURCESR   t   updatet   opent   pjoint   jsont   dump(   R   t	   overridesR	   t   kernel_dictt   f(    (    s3   lib/python2.7/site-packages/ipykernel/kernelspec.pyt   write_kernel_spec>   s    $c   
      C  sŘ   |  d
 k r t   }  n  | t k r9 | d
 k r9 | } n  i  } | rR | | d <n  | r d | g } | s d t j d | f | d <q n d
 } t d | d |  } |  j | d | d | d	 | }	 t j |  |	 S(   sŁ  Install the IPython kernelspec for Jupyter
    
    Parameters
    ----------
    
    kernel_spec_manager: KernelSpecManager [optional]
        A KernelSpecManager to use for installation.
        If none provided, a default instance will be created.
    user: bool [default: False]
        Whether to do a user-only install, or system-wide.
    kernel_name: str, optional
        Specify a name for the kernelspec.
        This is needed for having multiple IPython kernels for different environments.
    display_name: str, optional
        Specify the display name for the kernelspec
    profile: str, optional
        Specify a custom profile to be loaded by the kernel.
    prefix: str, optional
        Specify an install prefix for the kernelspec.
        This is needed to install into a non-default location, such as a conda/virtual-env.

    Returns
    -------
    
    The path where the kernelspec was installed.
    R   s	   --profiles   Python %i [profile=%s]i    R%   R	   t   kernel_namet   usert   prefixN(	   R   R   R   R   R   R(   t   install_kernel_specR   t   rmtree(
   t   kernel_spec_managerR*   R)   R   R+   t   profileR%   R	   R   t   dest(    (    s3   lib/python2.7/site-packages/ipykernel/kernelspec.pyt   installV   s"    	!(   t   Applicationt   InstallIPythonKernelSpecAppc           B  s)   e  Z d  Z d Z d d  Z d   Z RS(   s   Dummy app wrapping argparses   ipython-kernel-installc         C  s)   | d  k r t j d } n  | |  _ d  S(   Ni   (   R   R   R   (   t   selfR   (    (    s3   lib/python2.7/site-packages/ipykernel/kernelspec.pyt
   initialize   s    c         C  s­  d d  l  } | j d |  j d d  } | j d d d d d	 | j d
 d t d t d d | j d d t d d | j d d t d d | j d d t d d | j d d d d t j d d d d t j | j |  j	  } y: t
 d | j d | j d | j d | j d | j  } Wnj t k
 r} | j t j k rt | d t j | j r{t d d t j n  |  j d   n    n Xt d! | j | f  d  S("   Ni˙˙˙˙t   progt   descriptions    Install the IPython kernel spec.s   --usert   actiont
   store_truet   helps3   Install for the current user instead of system-wides   --namet   typet   defaultsd   Specify a name for the kernelspec. This is needed to have multiple IPython kernels at the same time.s   --display-namesd   Specify the display name for the kernelspec. This is helpful when you have multiple IPython kernels.s	   --profiles]   Specify an IPython profile to load. This can be used to create custom versions of the kernel.s   --prefixs   Specify an install prefix for the kernelspec. This is needed to install into a non-default location, such as a conda/virtual-env.s   --sys-prefixt   store_constt   constR0   R+   s[   Install to Python's sys.prefix. Shorthand for --prefix='%s'. For use in conda/virtual-envs.R*   R)   R/   R   t   files$   Perhaps you want `sudo` or `--user`?i   s   Installed kernelspec %s in %s(   t   argparset   ArgumentParsert   namet   add_argumentt   strR   R   R+   t
   parse_argsR   R1   R*   R/   R   t   OSErrort   errnot   EACCESt   printt   stderrt   exit(   R4   R@   t   parsert   optsR0   t   e(    (    s3   lib/python2.7/site-packages/ipykernel/kernelspec.pyt   start   s8    	!!	N(   t   __name__t
   __module__t   __doc__RB   R   R5   RO   (    (    (    s3   lib/python2.7/site-packages/ipykernel/kernelspec.pyR3      s   t   __main__(   RR   t
   __future__R    RG   R#   R   R   R   R   t   jupyter_client.kernelspecR   R   R   R"   R   R   t   dirnamet   __file__R   R   R   R   R(   t   FalseR1   t   traitlets.configR2   R3   RP   t   launch_instance(    (    (    s3   lib/python2.7/site-packages/ipykernel/kernelspec.pyt   <module>   s(   	5,