ó
q]c           @  s#  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 m	 Z	 y d d l
 m Z Wn! e k
 r™ d d l m Z n Xd d l m Z d d l m Z d	 e j f d
 „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d k re ƒ  n  d S(   sg   The root `jupyter` command.

This does nothing other than dispatch to subcommands or output path info.
iÿÿÿÿ(   t   print_functionN(   t   Popen(   t   whichi   (   t   paths(   t   __version__t   JupyterParserc           B  s)   e  Z e d  „  ƒ Z e j d „  ƒ Z RS(   c         C  s   d d j  t ƒ  ƒ S(   s}   Add subcommands to epilog on request

        Avoids searching PATH for subcommands unless help output is requested.
        s   Available subcommands: %st    (   t   joint   list_subcommands(   t   self(    (    s3   lib/python2.7/site-packages/jupyter_core/command.pyt   epilog   s    c         C  s   d S(   s$   Ignore epilog set in Parser.__init__N(    (   R	   t   x(    (    s3   lib/python2.7/site-packages/jupyter_core/command.pyR
   %   s    (   t   __name__t
   __module__t   propertyR
   t   setter(    (    (    s3   lib/python2.7/site-packages/jupyter_core/command.pyR      s   c          C  sÚ   t  d d ƒ }  |  j d t ƒ } | j d d d d d ƒ| j d	 d
 t d d d d ƒ| j d d d d d ƒ| j d d d d d ƒ| j d d d d d ƒ| j d d d d d ƒ|  j d d d d d ƒ|  S(   Nt   descriptions   Jupyter: Interactive Computingt   requireds	   --versiont   actiont
   store_truet   helps+   show the jupyter command's version and exitt
   subcommandt   typet   nargst   ?s   the subcommand to launchs   --config-dirs   show Jupyter config dirs
   --data-dirs   show Jupyter data dirs   --runtime-dirs   show Jupyter runtime dirs   --pathss?   show all Jupyter paths. Add --json for machine-readable format.s   --jsons%   output paths as machine-readable json(   R   t   add_mutually_exclusive_groupt   Truet   add_argumentt   str(   t   parsert   group(    (    s3   lib/python2.7/site-packages/jupyter_core/command.pyt   jupyter_parser*   s"    	c            s   t  ƒ  ‰ x© t ƒ  D]ž }  y t j |  ƒ } Wn t k
 rB q n Xxk | D]c } | j d ƒ rJ t j j d ƒ rŠ t j j	 | ƒ d } n  ˆ j
 t | j d ƒ d ƒ ƒ qJ qJ Wq Wt  ƒ  } xU ˆ D]M ‰  t ‡  ‡ f d †  t d t ˆ  ƒ ƒ Dƒ ƒ sÅ | j
 d j ˆ  ƒ ƒ qÅ qÅ Wt | ƒ S(   sÙ   List all jupyter subcommands

    searches PATH for `jupyter-name`

    Returns a list of jupyter's subcommand names, without the `jupyter-` prefix.
    Nested children (e.g. jupyter-sub-subsub) are not included.
    s   jupyter-t   wini    t   -i   c         3  s   |  ] } ˆ  |  ˆ k Vq d  S(   N(    (   t   .0t   i(   t   sub_tupt   subcommand_tuples(    s3   lib/python2.7/site-packages/jupyter_core/command.pys	   <genexpr>[   s    (   t   sett   _path_with_selft   ost   listdirt   OSErrort
   startswitht   syst   platformt   patht   splitextt   addt   tuplet   splitt   anyt   ranget   lenR   t   sorted(   t   dt   namest   namet   subcommands(    (   R$   R%   s3   lib/python2.7/site-packages/jupyter_core/command.pyR   B   s     	+	.c         C  så   t  j j d ƒ rÑ y d d l m } Wn! t k
 rI d d l m } n X| |  ƒ } | d k r{ t d |  t	 j
 ƒ ‚ n  t | g | d ƒ } d d l } | j | j | j ƒ | j ƒ  t  j | j ƒ n t j |  | ƒ d S(   s   execvp, except on Windows where it uses Popen

    Python provides execvp on Windows, but its behavior is problematic (Python bug#9148).
    R    iÿÿÿÿ(   R   i   s   %r not foundN(   R,   R-   R+   t   shutilR   t   ImportErrort   utils.shutil_whicht   NoneR*   t   errnot   ENOENTR   t   signalt   SIGINTt   SIG_IGNt   waitt   exitt
   returncodeR(   t   execvp(   t   cmdt   argvR   t   cmd_patht   pRA   (    (    s3   lib/python2.7/site-packages/jupyter_core/command.pyt   _execvp`   s    
c         C  s‹   t  j j t ƒ  ƒ } d j |  ƒ } t | d | ƒ} | d k rZ t d j | ƒ ƒ ‚ n  t  j | t  j	 ƒ s‡ t d j | ƒ ƒ ‚ n  | S(   s_   This method get the abspath of a specified jupyter-subcommand with no 
    changes on ENV.
    s
   jupyter-{}R.   s   Jupyter command `{}` not found.s'   Jupyter command `{}` is not executable.N(
   R(   t   pathsepR   R'   t   formatR   R>   t	   Exceptiont   accesst   X_OK(   R   t   search_patht   jupyter_subcommandt   abs_path(    (    s3   lib/python2.7/site-packages/jupyter_core/command.pyt   _jupyter_abspathz   s    c          C  sÎ   t  j d g }  t j j |  d ƒ rF |  j t j j |  d ƒ ƒ n  t j j d ƒ p^ t j	 j
 t j ƒ } xZ |  D]R } t j j | ƒ } t j j | ƒ rt t j | t j ƒ rt | j d | ƒ qt qt W| S(   sÀ   Put `jupyter`'s dir at the front of PATH

    Ensures that /path/to/jupyter subcommand
    will do /path/to/jupyter-subcommand
    even if /other/jupyter-subcommand is ahead of it on PATH
    i    t   PATH(   R,   RI   R(   R.   t   islinkt   appendt   realpatht   environt   gett   defpathR2   RM   t   dirnamet   isdirRP   RQ   t   insert(   t   scriptst	   path_listt   scriptt   bindir(    (    s3   lib/python2.7/site-packages/jupyter_core/command.pyR'      s     'c          C  s²  t  t j ƒ d k r< t j d j d ƒ r< t j d }  nøt ƒ  } | j ƒ  \ } } | j }  | j rt d j	 d ƒ t
 ƒ x d d d d  d! d" d# d$ d% d& g
 D][ \ } } d  } y t | ƒ } | j
 } Wn t k
 rè d } n Xt d j	 | ƒ | ƒ q¤ Wd  S| j r*| j r*t j d ƒ n  | j rGt t j ƒ  ƒ d  S| j rdt t j ƒ  ƒ d  S| j rt t j ƒ  ƒ d  S| j r4i  } t j ƒ  g | d <t j ƒ  | d <t j ƒ  | d <| j rât t j | ƒ ƒ nN xK t | ƒ D]= } | | }	 t d | ƒ x |	 D] }
 t d |
 ƒ qWqïWd  S|  s]| j d t j ƒ t j d ƒ n  t |  ƒ } y t | t j d ƒ Wn* t k
 r­} t j d |  | f ƒ n Xd  S('   Ni   R!   s   {:<17}:s   jupyter coret   notebooks   jupyter-notebookt	   qtconsolet   IPythont   ipythont	   ipykernelt   jupyter_clients   jupyter clientt
   jupyterlabs   jupyter labt	   nbconvertt
   ipywidgetst   nbformatt	   traitletss   not installeds    --json is only used with --pathst   runtimet   configt   datas   %s:s       t   files   subcommand is requireds&   Error executing Jupyter command %r: %s(   Rd   s   jupyter-notebook(   Re   Re   (   Rf   Rg   (   Rh   Rh   (   Ri   s   jupyter client(   Rj   s   jupyter lab(   Rk   Rk   (   Rl   Rl   (   Rm   Rm   (   Rn   Rn   (    R5   R,   RI   R+   R   t   parse_known_argsR   t   versiont   printRN   R   R>   t
   __import__R<   t   jsonR   RE   t
   config_dirt   jupyter_config_dirt   data_dirt   jupyter_data_dirt   runtime_dirt   jupyter_runtime_dirt   jupyter_config_patht   jupyter_patht   dumpsR6   t   print_usaget   stderrRU   RL   R*   (   R   R   t   argst   optst   packageR9   Rt   t   modRq   R.   RK   t   commandt   e(    (    s3   lib/python2.7/site-packages/jupyter_core/command.pyt   main©   st    ,			
					
t   __main__(   t   __doc__t
   __future__R    t   argparseR?   Rw   R(   R,   t
   subprocessR   R;   R   R<   R=   t    R   Rt   R   t   ArgumentParserR   R   R   RL   RU   R'   R‰   R   (    (    (    s3   lib/python2.7/site-packages/jupyter_core/command.pyt   <module>   s,   						E