
p[c        	   @  sX  d  Z  d d l m Z d d l 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 j 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 d d l m Z d d l m Z d d l m Z m Z m Z d d	 l m Z m  Z  m! Z! m" Z" d
 d l# m$ Z$ m% Z% m& Z& m' Z' m( Z( m) Z) d
 d l* m+ Z+ m, Z, e j- j. d k  rd d l/ m0 Z0 m1 Z1 m2 Z2 d d l/ m3 Z3 m4 Z4 d d l5 m6 Z6 n8 d d l7 m0 Z0 m1 Z1 m6 Z6 m2 Z2 d d l8 m3 Z3 m4 Z4 e j9 d  Z: e j; e j j< e, d d   Z= d   Z> d   Z? d   Z@ d   ZA eB d  ZC eB d  ZD eB d  ZE eB d  ZF eB eB d  ZG eB eB d  ZH eB eB d  ZI eB eJ eB eB d   ZK eB d!  ZL eB eB eB eB eB d" eB eJ d#  ZM eB eB d$  ZN eB eB d%  ZO eB eB d&  ZP eB eJ eB d'  ZQ eB eB d(  ZR eB eB d)  ZS eB eB d*  ZT eB eB d+  ZU eB d,  ZV eB eB d-  ZW d.   ZX d/ eY f d0     YZZ d1   Z[ d2   Z\ d3   Z] d4   Z^ d5   Z_ d6   Z` d7   Za d8   Zb d9   Zc g  d:  Zd d;   Ze d<   Zf d=   Zg eJ d>  Zh d?   Zi ej d@ k rTeF e,  n  d S(A   s   JupyterLab command handleri(   t   print_functionN(   t   LooseVersion(   t   Event(   t   TemporaryDirectory(   t   jupyter_config_path(   t   whicht   Processt   WatchHelper(   t   GREEN_ENABLEDt   GREEN_OKt   RED_DISABLEDt   RED_Xi   (   t   Ranget   gtet   ltt   ltet   gtt   make_semver(   t	   YARN_PATHt   HEREi   (   t   Requestt   urlopent   quote(   t   URLErrort	   HTTPError(   t   urljoin(   R   R   R   R   s   .*/index.out.jss   ..t   dev_modec          G  s   t  j t  j |     S(   s&   Join paths to create a real path.
    (   t   ospt   realpatht   join(   t   args(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   pjoin0   s    c          C  s>   t  j j d  }  |  p. t t   d d d  }  t j |   S(   s;   Get the configured JupyterLab user settings directory.
    t   JUPYTERLAB_SETTINGS_DIRi    t   labs   user-settings(   t   ost   environt   getR   R   R   R   (   t   settings_dir(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   get_user_settings_dir6   s    	c          C  s>   t  j j d  }  |  p. t t   d d d  }  t j |   S(   s8   Get the configured JupyterLab workspaces directory.
    t   JUPYTERLAB_WORKSPACES_DIRi    R!   t
   workspaces(   R"   R#   R$   R   R   R   R   (   t   workspaces_dir(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   get_workspaces_dir@   s    	c          C  s   t  j j d  r& t j t  j d  St t j d d d  }  t t	 d  rZ t	 j
   n  t t	 d d	  } t j |  r |  j |  r t | d d d  }  n: t j j d  r t j |   r t j d  r d }  n  t j |   S(
   s1   Get the configured JupyterLab app directory.
    t   JUPYTERLAB_DIRt   sharet   jupyterR!   t   getuserbaset	   USER_BASEs   /usrs   /usr/local/share/jupyter/labN(   R"   R#   R$   R   R   R   t   syst   prefixt   hasattrt   siteR.   t   getattrt   NoneR   t
   startswitht   exists(   t   app_dirt   userbase(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   get_app_dirJ   s    	c         C  s  t  t d  } t j t  | d   sR t d t g d | d |  } | j   n  d d g } xf | D]^ } t  | d |  } t j t  | d	   se t d t d
 g d | d |  } | j   qe qe Wt j t  | d d	   st d t d g d | d |  } | j   n  d S(   s.   Ensure that the dev assets are available.
    s   ..t   node_modulest   nodet   cwdt   loggers   theme-light-extensions   theme-dark-extensiont   packagest   statics   build:webpackR   t   buildN(   R   R   R   R7   R   R   t   wait(   R>   t   parentt	   yarn_proct   theme_packagest   themet	   base_path(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt
   ensure_deve   s    		c         C  s   t  t d  } t j t  t d   r+ d St j t  | d   sn t d t g d | d |  } | j   n  t j t  t d   s t d t d g d | d |  } | j   n  d S(	   s/   Ensure that the core assets are available.
    t   stagingR@   NR;   R<   R=   R>   RA   (   R   R   R   R7   R   R   RB   (   R>   RI   RD   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   ensure_core|   s    	c         C  s   t  t d  } t j t  | d   sR t d t g d | d |  } | j   n  |  pd t j d  }  t j	 t j
 t d d d   } d	 } t d t d
 d g d | d |  d | } d } t d t d
 d g d | d |  d | } | | g S(   s   Run watch mode for the source packages.

    Parameters
    ----------
    logger: :class:`~logger.Logger`, optional
        The logger instance.

    Returns
    -------
    A list of `WatchHelper` objects.
    s   ..R;   R<   R=   R>   t
   jupyterlabR?   t   metapackages/   .* Found 0 errors\. Watching for file changes\.t   runt   watcht   startup_regexs!   Watching the metapackage files...s   watch:files(   R   R   R   R7   R   R   RB   t   loggingt	   getLoggerR   R   R   (   R>   RC   RD   t   ts_dirt   ts_regext   ts_proct	   tsf_regext   tsf_proc(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   watch_packages   s    !c         C  sV   |  p t  j d  }  t |   } t d t d d g d t d |  d t } | | g S(   s   Run watch mode in a given directory.

    Parameters
    ----------
    logger: :class:`~logger.Logger`, optional
        The logger instance.

    Returns
    -------
    A list of `WatchHelper` objects.
    RK   R<   RM   RN   R=   R>   RO   (   RP   RQ   RW   R   R   t   DEV_DIRt   WEBPACK_EXPECT(   R>   t   package_procst   wp_proc(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt	   watch_dev   s    	c         C  s    t    t |  |  } | j   S(   s  Watch the application.

    Parameters
    ----------
    app_dir: string, optional
        The application directory.
    logger: :class:`~logger.Logger`, optional
        The logger instance.

    Returns
    -------
    A list of processes to run asynchronously.
    (   t   _node_checkt   _AppHandlerRN   (   R8   R>   t   handler(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRN      s    c         C  s#   t    t | |  } | j |   S(   s   Install an extension package into JupyterLab.

    The extension is first validated.

    Returns `True` if a rebuild is recommended, `False` otherwise.
    (   R]   R^   t   install_extension(   t	   extensionR8   R>   R_   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR`      s    c         C  s#   t    t | |  } | j |   S(   sp   Uninstall an extension by name or path.

    Returns `True` if a rebuild is recommended, `False` otherwise.
    (   R]   R^   t   uninstall_extension(   t   nameR8   R>   R_   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRb      s    c         C  s9   t    t | |  } | t k r, | j   S| j |   S(   s   Update an extension by name, or all extensions.

    Either `name` must be given as a string, or `all_` must be `True`.
    If `all_` is `True`, the value of `name` is ignored.

    Returns `True` if a rebuild is recommended, `False` otherwise.
    (   R]   R^   t   Truet   update_all_extensionst   update_extension(   Rc   t   all_R8   R>   R_   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRf      s
    
c         C  s   |  p t    }  |  t t d  k r3 t d   n  |  t t d  k rW t d   n  x? d g D]4 } t |  |  } t j |  ra t j |  qa qa Wd S(   s+   Clean the JupyterLab application directory.t   devs   Cannot clean the dev appt   cores   Cannot clean the core appRI   N(   R:   R   R   t
   ValueErrorR   R7   t   shutilt   rmtree(   R8   Rc   t   target(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   clean  s    s
   build:prodc   	      C  sD   t    t |  | d | } | j d | d | d | d | d |  S(   s&   Build the JupyterLab application.
    t
   kill_eventRc   t   versiont
   public_urlt   commandt   clean_staging(   R]   R^   RA   (	   R8   Rc   Rp   Rq   R>   Rr   Ro   Rs   R_   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRA     s    c         C  s   t  |  |  } | j S(   s3   Get a dictionary of information about the app.
    (   R^   t   info(   R8   R>   R_   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   get_app_info  s    c         C  s   t  | |  } | j |  t  S(   sg   Enable a JupyterLab extension.

    Returns `True` if a rebuild is recommended, `False` otherwise.
    (   R^   t   toggle_extensiont   False(   Ra   R8   R>   R_   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   enable_extension   s    c         C  s   t  | |  } | j |  t  S(   sf   Disable a JupyterLab package.

    Returns `True` if a rebuild is recommended, `False` otherwise.
    (   R^   Rv   Rd   (   Ra   R8   R>   R_   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   disable_extension)  s    c         C  s   t  | |  } | j |  |  S(   s<   Check if a JupyterLab extension is enabled or disabled.
    (   R^   t   check_extension(   Ra   R8   t	   installedR>   R_   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRz   2  s    c         C  s    t    t |  |  } | j   S(   sS   Determine whether JupyterLab should be built.

    Returns a list of messages.
    (   R]   R^   t   build_check(   R8   R>   R_   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR|   9  s    c         C  s   t  |  |  } | j   S(   s   List the extensions.
    (   R^   t   list_extensions(   R8   R>   R_   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR}   C  s    c         C  s   t  | |  } | j |   S(   su   Link a package against the JupyterLab build.

    Returns `True` if a rebuild is recommended, `False` otherwise.
    (   R^   t   link_package(   t   pathR8   R>   R_   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR~   J  s    c         C  s   t  | |  } | j |   S(   sz   Unlink a package from JupyterLab by path or name.

    Returns `True` if a rebuild is recommended, `False` otherwise.
    (   R^   t   unlink_package(   t   packageR8   R>   R_   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR   S  s    c         C  s&   |  p t    }  t |   } | j d S(   s   Get the application version.Rp   (   R:   R^   Rt   (   R8   R_   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   get_app_version\  s    c         C  s+   | p t    } t | |  } | j |   S(   s=   Get the latest compatible version of a list of packages.
    (   R:   R^   t"   latest_compatible_package_versions(   t   namesR8   R>   R_   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt&   get_latest_compatible_package_versionsc  s    c         C  s}   t  j |  d  } | j d  } t j | j   j d   } g  | j   D] } | j t	 d  ^ qL | d <| j
   | S(   s5   Read the package data in a given target tarball.
    t   rs   package/package.jsont   utf8s   package/t   jupyterlab_extracted_files(   t   tarfilet   opent   extractfilet   jsont   loadst   readt   decodet
   getmembersR   t   lent   close(   Rm   t   tart   ft   data(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   read_packagek  s    0
R^   c           B  s  e  Z d) d) d   Z d) d  Z d) d) d) d e d  Z d   Z d   Z e d  Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z e d  Z d   Z d   Z d   Z d) d) d) e d  Z e d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d    Z# d!   Z$ d"   Z% d#   Z& e d$  Z' d%   Z( d&   Z) d'   Z* d(   Z+ RS(*   c         C  sd   | p t    |  _ t    |  _ | p0 t j d  |  _ |  j   |  _ | pQ t   |  _	 d |  _
 d S(   s(   Create a new _AppHandler object
        RK   s   https://registry.npmjs.orgN(   R:   R8   t   sys_dirRP   RQ   R>   t   _get_app_infoRt   R   Ro   t   registry(   t   selfR8   R>   Ro   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   __init__  s    c         C  sl  t  |  } |  j d } | |  j d k r |  j   } | j d g   } | | k r |  j j d |  | j |  | | d <|  j |  t St S|  j	   t
    } |  j | |  } Wd QX| d } | d r|  j   } | j d t    }	 | d	 |	 | <|  j |  n  | | k rh| | }
 |
 d
 | d
 k rh|
 d d k rht j |
 d
  qhn  t S(   s   Install an extension package into JupyterLab.

        The extension is first validated.

        Returns `True` if a rebuild is recommended, `False` otherwise.
        t
   extensionst   core_extensionst   uninstalled_core_extensionss   Installing core extension %sNRc   t   is_dirt   local_extensionst   sourceR   t   locationt   app(   t   _normalize_pathRt   t   _read_build_configR$   R>   t   removet   _write_build_configRd   Rw   t   _ensure_app_dirsR   t   _install_extensiont
   setdefaultt   dictR"   (   R   Ra   t   existingR   t   configt   uninstalledt   tempdirRt   Rc   t   localt   other(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR`     s4    




$s
   build:prodc      	   C  sy   |  j  } |  j d | d | d | d |  t | d  } |  j d t d g d | |  j d t d	 | g d | d
 S(   s   Build the application.
        Rc   Rp   Rq   Rn   RI   R<   t   installR=   RM   N(   R8   t   _populate_stagingR   t   _runR   (   R   Rc   Rp   Rq   Rr   Rs   R8   RI   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRA     s    		c         C  sx   t  |  j d  } |  j   |  j d t d g d | t d t d d g d t  |  j d  d t d |  j } | g S(	   sX   Start the application watcher and then run the watch in
        the background.
        RI   R<   R   R=   RM   RN   RO   R>   (   R   R8   R   R   R   R   RY   R>   (   R   RI   t   proc(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRN     s    
c         C  s  |  j  } |  j } | j d | d  | d rq |  j   | d <| j d  |  j | d  |  j | d  n | j d  | d	 } | r | j d
  x2 t |  D]! } | j d | | | f  q Wn  | d } | r,| j d  x< t |  D]+ } | | d } | j d | | f  q Wn  | d } | rv| j d  g  t |  D] }	 | j d |	  ^ qVn  | d }
 |
 r| j d  g  t |
  D] }	 | j d |	  ^ qn  |  j d t  } | r| j d  g  | D] }	 | j d |	  ^ qn  d S(   s+   Print an output of the extensions.
        s   JupyterLab v%sRp   R   t   compat_errorss   Known labextensions:R   R0   s   No installed extensionsR   s   
   local extensions:s           %s: %st   linked_packagess   
   linked packages:R   t   uninstalled_cores   
Uninstalled core extensions:s       %st   disabled_cores   
Disabled core extensions:t   fasts3   
Build recommended, please run `jupyter lab build`:N(   R>   Rt   t   _get_extension_compatt   _list_extensionst   sortedR|   Rd   (   R   R>   Rt   R   Rc   R   t   keyR   R   t   itemR   t   messages(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR}     s@    		

"

-
-c         C  s  |  j  } |  j d } |  j d } g  } t | d d  } t j |  sQ d g S|  j d } | d } | j d t    }	 | j d	 d
  }
 | d	 } t |
  t |  k r d } | |
 | f g S|  j d |  } | d } | j d t    } x d d g D]x } x6 | | D]* } | | | k r| j	 d |  qqWx6 | | D]* } | | | k rP| j	 d |  qPqPWqWx | j
   D]w \ } } | |	 k rqn  | | k s| | k rqn  |	 | | k rd } | j	 | | |	 | | | f  qqWx^ | j
   D]P \ } } | r/qn  t | d  } |  j | | |  r| j	 d |  qqWxe | j
   D]W \ } } | rqxn  t | d d  } |  j | | d |  rx| j	 d |  qxqxW| S(   s[   Determine whether JupyterLab should be built.

        Returns a list of messages.
        R   R   R@   s   package.jsons   No built applicationt   static_dataRK   t   dependenciesRp   t    s*   Version mismatch: %s (built), %s (current)t   silentR   t   mimeExtensionss    %s needs to be included in builds!   %s needs to be removed from builds   %s changed from %s to %ss   %s content changedRI   R   (   R8   Rt   R   R   R7   R$   R   R   t   _get_package_templatet   appendt   itemst   _check_local(   R   R   R8   R   t   linkedR   t   pkg_pathR   t   old_jlabt   old_depst   static_versiont   core_versiont   msgt   new_packaget   new_jlabt   new_depst   ext_typet   extt   pkgt   depRc   R   t   dnameR   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR|   	  s\    	


)c   	      C  sg  |  j  d } | |  j  d k r |  j   } | j d g   } | | k r |  j j  d |  | j |  | | d <|  j |  t St S|  j  d } x |  j  d j   D] \ } } | d } | | k r d | t	 j
 |  f } |  j j  |  t j |  | | k rG|  j   } | j d t    } | | =|  j |  n  t Sq W|  j j d	 |  t S(
   sp   Uninstall an extension by name.

        Returns `True` if a rebuild is recommended, `False` otherwise.
        t	   core_dataR   R   s   Uninstalling core extension %sR   R   R   s   Uninstalling %s from %ss$   No labextension named "%s" installed(   Rt   R   R$   R>   R   R   Rd   Rw   R   R   t   dirnameR"   R   R   R   t   warn(	   R   Rc   R   R   R   R   t   extnameR   R   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRb   P  s4    
 
c         C  sb   t  } xU |  j d j   D]@ \ } } | |  j d k r? q n  |  j |  } | pW | } q W| S(   sq   Update all non-local extensions.

        Returns `True` if a rebuild is recommended, `False` otherwise.
        R   R   (   Rw   Rt   R   t   _update_extension(   R   t   should_rebuildR   t   _t   updated(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRe   u  s     c         C  s8   | |  j  d k r+ |  j j d |  t S|  j |  S(   sm   Update an extension by name.

        Returns `True` if a rebuild is recommended, `False` otherwise.
        R   s$   No labextension named "%s" installed(   Rt   R>   R   Rw   R   (   R   Rc   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRf     s    c         C  s   y |  j  |  } Wn t k
 r' t SX| d k r8 t S| |  j d | d k rk |  j j d |  t S|  j j d | | f  |  j d | | f  S(   sm   Update an extension by name.

        Returns `True` if a rebuild is recommended, `False` otherwise.
        R   Rp   s   Extension %r already up to dates   Updating %s to version %ss   %s@%sN(   t"   _latest_compatible_package_versionR   Rw   R5   Rt   R>   R`   (   R   Rc   t   latest(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     s    c   	      C  s  t  |  } t j |  s, t j |  rE d } t | |   n  t    } |  j | |  } Wd QXt | d  } | s |  j |  S|  j	 j
 d |  g  | D] } |  j	 j
 |  ^ q |  j   } | j d t    } | d | | d <|  j |  t S(   sr   Link a package at the given path.

        Returns `True` if a rebuild is recommended, `False` otherwise.
        s,   Can install "%s" only link local directoriesNR   s"   Installing %s as a linked package:R   R   Rc   (   R   R   R7   t   isdirRj   R   t   _extract_packaget   _validate_extensionR`   R>   R   R   R   R   R   Rd   (	   R   R   R   R   Rt   R   t   mR   R   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR~     s      #c         C  s0  t  |  } |  j   } | j d t    } d } x; | j   D]- \ } } | | k sd | | k r@ | } q@ q@ W| r | | =n | j d t    } x; | j   D]- \ } } | | k s | | k r | } q q W| r| | =|  j d | d } t j |  n  | st	 d |   n  |  j
 |  t S(   s   Unlink a package by name or at the given path.

        A ValueError is raised if the path is not an unlinkable package.

        Returns `True` if a rebuild is recommended, `False` otherwise.
        R   R   R   R   s   No linked package for %sN(   R   R   R   R   R5   R   Rt   R"   R   Rj   R   Rd   (   R   R   R   R   t   foundRc   R   R   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     s*    
c         C  s   |  j    } | j d g   } t } | rL | | k rL | j |  t } n) | ru | | k ru | j |  t } n  | r |  j |  n  | S(   ss   Enable or disable a lab extension.

        Returns `True` if a rebuild is recommended, `False` otherwise.
        t   disabledExtensions(   t   _read_page_configR   Rw   R   Rd   R   t   _write_page_config(   R   Ra   t   valueR   t   disabledt   did_something(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRv     s    		c         C  sm   |  j  } | | d k r, |  j | | |  S| | d k rZ |  j j  d | t f  t S|  j | | |  S(   s8   Check if a lab extension is enabled or disabled
        R   R   s   %s:%s(   Rt   t   _check_core_extensionR>   R   Rd   t   _check_common_extension(   R   Ra   t   check_installed_onlyRt   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRz     s    	c         C  s   | | d k r. |  j  j d | t f  t S| rR |  j  j d | t f  t S| | d k r |  j  j d | t f  t S|  j  j d | t f  t S(   s9   Check if a core extension is enabled or disabled
        R   s   %s:%ss   %s: %sR   (   R>   Rt   R   Rw   R	   Rd   R
   R   (   R   Ra   Rt   R   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR      s    c         C  s   | | d k r. |  j  j d | t f  t S|  j   | } | rb |  j  j d | t f  t S| r |  j  j d | t f  t St | | d  r |  j  j d | t f  t S|  j  j d | t	 f  t S(   sF   Check if a common (non-core) extension is enabled or disabled
        R   s   %s:%ss   %s:%s (compatibility errors)s   %s: %sR   (
   R>   Rt   R   Rw   R   R	   Rd   t   _is_disabledR
   R   (   R   Ra   Rt   R   t   errors(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     s    c         C  s  t    } t   | d <} |  j |  | d <} |  j   } | j d g   | d <|  j   | d <|  j   | d <g  | d <} g  | d <} x[ | j   D]M \ } } | | d k | d	 <| d
 d k r | j |  q | j |  q W|  j	   | d <t
 |  j  | d <| d p| }	 |	 d d | d <|	 d j d d  | d <|  j | d <|  j | d <t   | d <}
 g  } x. |
 D]& } | | d k r| j |  qqW| | d <| S(   s'   Get information about the app.
        R   R   R   R   R   R   t   app_extensionst   sys_extensionst   is_localR   R   R   R   RK   Rp   t	   publicUrlR   R   R8   R   R   (   R   t   _get_core_datat   _get_extensionsR   R$   t   _get_local_extensionst   _get_linked_packagesR   R   t    _get_uninstalled_core_extensionst   _get_static_dataR8   R   t   _get_core_extensions(   R   Rt   R   R   t   page_configR   R0   Rc   R   t   app_dataR   R   R   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR   &  s8    	
c      
   C  s  |  j  } t | d  } | rP t j |  rP |  j j d |  t j |  n  |  j   | sx |  j d d d } n  t | d  } t j |  r t	 |   } t
 j |  }	 Wd QX|	 d j d d  | k r t j |  t j |  q n  xH d	 d
 d d d g D]1 }
 t | |
  } t j t t d |
  |  qWt j t | d   rrt j t | d   n  t | d  } t j |  rt j |  n  t j t t d d  |  t | d  } t j |  rt j |  n  t j |  |  j d } t } x |  j d j   D] \ } } | | k rw|  j   } | j d t    }	 |	 | =|  j |  t } qn  t | d  } |  j | | | | | d  qW| r|  j   |  j d <n  |  j d } xF | j   D]8 \ } } t | d  } |  j | | d | | d  qW|  j   }	 | r<| |	 d d <n  | rS| |	 d d <n  | rj| |	 d d <n  t | d  } t	 | d   } t
 j |	 | d d Wd QXd S(   s4   Set up the assets in the staging directory.
        RI   s   Cleaning %sR   RK   Rp   s   package.jsonNR   s   index.jss   webpack.config.jss   webpack.prod.config.jss   .yarnrcs   yarn.jss	   yarn.lockt	   templatesR   R   R   R   Rc   R   t   wt   indenti   (   R8   R   R   R7   R>   Rt   Rk   Rl   R   R   R   t   loadR$   R"   t   makedirst   copyR   R   t   copytreeRw   R   R   R   R   R   Rd   t   _update_localR   R   t   dump(   R   Rc   Rp   Rq   Rn   R8   RI   R   t   fidR   t   fnameRm   R   t
   linked_dirR   t   removedR   R   R   R   R   R   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR   N  sx    	
	  c           sP    j  }   j d }   j d }   j d }   j d } | d }   f d   } t   | d <x( | j   D] \ }	 }
 |
 | d |	 <qp Wxh | j   D]Z \ }	 } t   j d d  } t | | d	  } | |  | d
 |	 <| d | d |	 <q W  j   } x | j   D] \ }	 } | |	 } | rdt |	 | d |  } | s| j | d  qqn  | | d  | d
 |	 <| d } xY d d g D]K } | j	 | t
  } | sqn  | t k rd } n  | | | d |	 <qWqWxc   j d D]T } | | d k r"| d d j |  n | d d j |  | d
 j |  qW| S(   s<   Get the template the for staging package.json file.
        R   R   R   R   RK   c           sY   t  j |  t   j d   }  d |  j t j d  }  t j d k rU |  j   }  n  |  S(   NRI   s   file:t   /t   nt(	   R   t   relpathR   R8   t   replaceR"   t   sepRc   t   lower(   R   (   R   (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   format_path  s
    t   linkedPackagesRI   t   filenameR   R   Rp   s   
R   Ra   t   mimeExtensionR   t   sR   R   (   R>   Rt   R   R   R   R8   R   t   _format_compatibility_errorsR   R$   Rw   Rd   t   pop(   R   R   R>   R   R   R   R   t   jlabR  R   R   R   R   R   R   R   R   t	   jlab_dataR   (    (   R   s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     sN    	


	c         C  sI   t    : } |  j | |  } t | | d  } t j |  SWd QXd S(   sw   Check if a local package has changed.

        `dname` is the directory name of existing package tar archives.
        R  N(   R   R   R   R   R7   (   R   Rc   R   R   R   Rt   Rm   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     s    c   	   
   C  s   | d } t    N } |  j | |  } | d | k r< | St j | d t | | d   Wd QX| r t j t | |   n  | d | d <t | d | d  | d <| d S(   s>   Update a local dependency.  Return `True` if changed.
        R  R   Nt   tar_dir(   R   R   Rk   t   moveR   R"   R   (	   R   Rc   R   R   R   t   dtypeR   R   Rt   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR    s    
'c         C  s   |  j  } t   } t |  j d  } t |  j  d  } |  j |  j |  } t | d  } | | k sv t j |  rz | S| j |  j | |   | S(   s0   Get the extensions for the application.
        R   (   R8   R   R   R   t   _get_extensions_in_dirR   R7   t   update(   R   R   R8   R   t   sys_patht   app_path(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     s    		c         C  s   t    } | |  j k r d n d } x t j t | d d   D] } t |  } | j d t     } | d } | j d t     }	 t j |  }
 t  d |
 d	 t j |
  d
 | d
 d |	 d | d t j	 |
  d |  | | <q@ W| S(   s1   Get the extensions in a given directory.
        R   R0   R   s   *.tgzR   Rc   RK   R   R  Rp   R  R   (
   R   R8   t   globR   R   R$   R   R   t   basenameR   (   R   R   R   R   R   Rm   R   t   depsRc   R  R   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR  %  s     	"

c         C  s^   t    } |  j d } xA |  j d j   D], \ } } | d } t | | |  | | <q* W| S(   s.   Get the extension compatibility info.
        R   R   R   (   R   Rt   R   t   _validate_compatibility(   R   t   compatR   Rc   R   R%  (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR   9  s    	 
c         C  s   |  j  d  S(   s.   Get the locally installed extensions.
        R   (   t   _get_local_data(   R   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR   C  s    c         C  s1  |  j  d  } t |  j d d  } x9 | j   D]+ \ } } t d | d d d |  | | <q1 Wt j |  ss | Sx t j t | d   D] } t j |  } t	 |  } | d } | | k r |  j
 j d	 |  t j |  q n  | | } t j |  | d <| | d
 <| d | d <| | d <q W| S(   s!   Get the linked packages.
        R   RI   R   R  R   R  s   *.tgzRc   s#   Removing orphaned linked package %sR   Rp   R   (   R(  R   R8   R   R   R   R7   R#  R   R   R>   R   R"   R   R$  (   R   Rt   R   Rc   R   R   R   R   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR   H  s(    #


c         C  s   |  j    } | j d g   S(   s-   Get the uninstalled core extensions.
        R   (   R   R$   (   R   R   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR   b  s    c         C  s   d d d d d g } xq | D]i } t  |  j |  } t j |  s y t j |  Wq t k
 r } | j t j k r   q q Xq q Wd S(   s-   Ensure that the application directories existR   t   settingsRI   t   schemast   themesN(	   R   R8   R   R7   R"   R  t   OSErrort   errnot   EEXIST(   R   t   dirsR   R   t   e(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR   h  s    c         C  sN  |  j  } | d | } | s! d S| d | } | j d | | f  xt |  D] } | j |  | d | } | d } | d | }	 d }
 t | | d	  r |
 d
 t 7}
 n |
 d
 t 7}
 |	 r |
 d
 t 7}
 n |
 d
 t 7}
 | d r |
 d 7}
 n  | j d | | |
 f  |	 rS t | | |	  } | j	 | d  qS qS Wd S(   s-   List the extensions of a given type.
        s   %s_extensionsNs   %s_dirs      %s dir: %sR   Rp   R   R   R   s    %sR   t   *s           %s v%s%ss   
(
   R>   Rt   R   R   R
   R   R   R	   R  R   (   R   Rt   R   R>   R   R   Rc   R   Rp   R   t   extraR   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR   t  s2    	

c         C  sN   t  |  j d d  } t j |  s( i  St |   } t j |  SWd QXd S(   s3   Get the build config data for the app dir.
        R)  s   build_config.jsonN(   R   R8   R   R7   R   R   R  (   R   Rm   R	  (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     s
    c      	   C  sQ   |  j    t |  j d d  } t | d   } t j | | d d Wd QXd S(   s/   Write the build config to the app dir.
        R)  s   build_config.jsonR  R  i   N(   R   R   R8   R   R   R  (   R   R   Rm   R	  (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     s    
c         C  sN   t  |  j d d  } t j |  s( i  St |   } t j |  SWd QXd S(   s2   Get the page config data for the app dir.
        R)  s   page_config.jsonN(   R   R8   R   R7   R   R   R  (   R   Rm   R	  (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     s
    c      	   C  sQ   |  j    t |  j d d  } t | d   } t j | | d d Wd QXd S(   s/   Write the build config to the app dir.
        R)  s   page_config.jsonR  R  i   N(   R   R   R8   R   R   R  (   R   R   Rm   R	  (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     s    
c         C  s   |  j    } | j | t    } g  } x9 | j   D]+ \ } } t j |  s4 | j |  q4 q4 WxG | D]? } | j d d  } d | | f } |  j j	 |  | | =qj W| r |  j
 |  n  | S(   s>   Get the local data for extensions or linked packages.
        R   t    s   **Note: Removing dead %s "%s"(   R   R   R   R   R   R7   R   R  R>   R   R   (   R   R   R   R   t   deadRc   t	   link_typeR   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR(    s    c         C  s  |  j  | |  } | d } t |  } | rV d } t | | d j |  f   n  t   } | j d t    } t | | |  }	 |	 rt | d | d |	  } d | d k r| d	 r| d }
 y |  j	 |
  } Wn t
 k
 r t |   n X| r_|
 r_|  j j d
 |  |  j j d |  t   ! } |  j d |
 | f |  SWd QXn  d j | j   d  } d j |  j |
  d | f  } n  t |   n  t |  j d | d  } t j |  rt j |  n  t j | d |  | | d <| S(   sK   Install an extension with validation and return the name and path.
        R   s!   "%s" is not a valid extension:
%ss   
R   Rc   Rp   t   @i   R   s   Incompatible extension:
%ss   Found compatible version: %ss   %s@%sNi   R   s   

R   R  R   (   R   R   Rj   R   R   R$   R   R&  R  R   R   R>   t   warningR   R   t
   splitlinest%   _format_no_compatible_package_versionR   R8   R   R7   R"   R   Rk   R  (   R   Ra   R   Rt   R   R   R   R   R%  R   Rc   Rp   t   tempdir2t	   conflictsRm   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     sH    
"	

c         C  s  t  j |  o t  j |  } | rb t  j t | d   rb |  j d t d g d | d | n  t d | d |  } |  j t d  d	 | g d | d | } | d
 k r d } t | |   n  t	 j	 t | d   d
 } t
 |  | d <| r?t |  | d <}	 | j d d |	  }
 t j | |
  |
 | d <n
 | | d <t  j | d  | d <| d d | d <| d d | d <| S(   s   Call `npm pack` for an extension.

        The pack command will download the package tar if `source` is
        a package name, or run `npm pack` locally if `source` is a
        directory.
        R;   R<   R   R=   t   quietR   R   t   npmt   packi    s   "%s" is not a valid npm packages   *.tgzR   t   shas   .tgzs   -%s.tgzR   R  Rc   Rp   (   R   R7   R   R   R   R   R   R   Rj   R#  R   t   _tarsumR  Rk   R  R$  (   R   R   R   R<  R   Rt   t   retR   R   R?  Rm   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR   
  s(    %*
c      
   C  s  |  j  d } y t |  j | |  j  } Wn t k
 r= d SX| j d g   } d   } x t | j   d | d t D] \ } } | j d i   } t	 | | |  }	 |	 sx t
   ) }
 |  j d | | f |
 d	 t } Wd QXt | d
  r d S| Sqx Wd S(   s.   Get the latest compatible version of a packageR   Nt   versionsc         S  s   t  |  d d t S(   Ni    t   prerelease_first(   t   _semver_keyRd   (   t	   key_value(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   sort_key7  s    R   t   reverseR   s   %s@%sR<  R   (   Rt   t   _fetch_package_metadataR   R>   R   R$   R   R   Rd   R&  R   R   R   (   R   Rc   R   t   metadataRB  RF  Rp   R   R%  R   R   Rt   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR   -  s&    	"c      
   C  s  |  j  d } g  } x | D] } y t |  j | |  j  } Wn t k
 rR q n X| j d g   } d   } xq t | j   d | d t D]Q \ } }	 |	 j d i   }
 t	 | |
 |  } | s | j
 d | | f  Pq q Wq Wi  } | s | St    } |  j t d  d	 g | d
 | d t } | d k rRd } t | |   n  x | D]x } | d j d d  | d j d d  j d d  d } t t j j | |   }	 t |	  sY|	 d | | <qYqYWWd QX| S(   s   Get the latest compatible versions of several packages

        Like _latest_compatible_package_version, but optimized for
        retrieving the latest version for several packages in one go.
        R   RB  c         S  s   t  |  d d t S(   Ni    RC  (   RD  Rd   (   RE  (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRF  \  s    R   RG  R   s   %s@%sR=  R>  R=   R<  i    s   "%s" is not a valid npm packageR6  R   i   t   -R  s   .tgzRp   N(   Rt   RH  R   R>   R   R$   R   R   Rd   R&  R   R   R   R   Rj   R  R   R"   R   R   R   (   R   R   R   t   keysRc   RI  RB  RF  Rp   R   R%  R   R   RA  R   R   R
  (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR   K  s>    	+:c         C  s_  |  j  d } t } t } y t |  j | |  j  } Wn t k
 rH n X| j d g   } d   } t t | j	   d | d t
  } | d d j d i   }	 | d }
 | d	 d
 } x` |	 j	   D]R \ } } | | k r t |
 | |  } | p| d k  } | p| d k } q q W| r'd Sd g } | rF| j d  n  d j |  j d |  S(   s.   Get the latest compatible version of a packageR   RB  c         S  s   t  |  d d t S(   Ni    RC  (   RD  Rd   (   RE  (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRF    s    R   RG  i    i   R   RK   t   singletonPackagessG   This extension does not yet support the current version of JupyterLab.
sc   No version of {extension} could be found that is compatible with the current version of JupyterLab.s9   However, it seems to support a new version of JupyterLab.s   Consider upgrading JupyterLab.R3  Ra   (   s9   However, it seems to support a new version of JupyterLab.s   Consider upgrading JupyterLab.(   Rt   Rw   RH  R   R>   R   R$   t   tupleR   R   Rd   t   _compare_rangest   extendR   t   format(   R   Rc   R   t   lab_newer_than_latestt   latest_newer_than_labRI  RB  RF  t   storet   latest_depst	   core_depst
   singletonsR   R   t   ct   parts(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR9  |  s2    	$
	
c         K  sQ   |  j  j   r t d   n  |  j | d <|  j  | d <t | |  } | j   S(   s]   Run the command using our logger and abort callback.

        Returns the exit code.
        s   Command was killedR>   Ro   (   Ro   t   is_setRj   R>   R   RB   (   R   t   cmdt   kwargsR   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     s    N(,   t   __name__t
   __module__R5   R   R`   Rw   RA   RN   R}   R|   Rb   Re   Rf   R   R~   R   Rv   Rz   R   R   R   R   R   R   R  R   R  R   R   R   R   R   R   R   R   R   R   R(  R   R   R   R   R9  R   (    (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR^   }  sT   .			,G	%		
			"				(	[A					
					"	
		
			:#		1	-c          C  sO   t  d d g d t d t }  |  j   } | d k rK d } t |   n  d S(   s@   Check for the existence of nodejs with the correct version.
    R<   s   node-version-check.jsR=   R<  i   s|   Please install nodejs 5+ and npm before continuing. nodejs may be installed using conda or directly from the nodejs website.N(   R   R   Rd   RB   Rj   (   R   t   return_codeR   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR]     s
    c         C  s4   t  j |   }  t  j |   r0 t  j |   }  n  |  S(   s1   Normalize a given extension if it is a path.
    (   R   t
   expanduserR7   t   abspath(   Ra   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     s    c           s/  |  j  d d  } | d k r% d g St | t  s; d g S| j  d t  } | j  d t  } | j  d d   | j  d d    g  } | r | r | j d	  n  | | k r d
 } | j |  n  |  d } |  j  d d  } | j d  s| d 7} n  | t k r| } n# | r9| j d  r9| d 7} n  | t k rN| } n# | rq| j d  rq| d 7} n  | r| | k r| j d |  n  | r| | k r| j d |  n   rt  f d   | D  r| j d   n    r+t   f d   | D  r+| j d    n  | S(   s`   Detect if a package is an extension using its metadata.

    Returns any problems it finds.
    RK   s   No `jupyterlab` keys*   The `jupyterlab` key must be a JSON objectRa   R  t   themeDirR   t	   schemaDirs-   No `extension` or `mimeExtension` key presents?   `mimeExtension` and `extension` must point to different modulesR   t   mains   index.jss   .jss   Missing extension module "%s"s!   Missing mimeExtension module "%s"c         3  s   |  ] } | j     Vq d  S(   N(   R6   (   t   .0R   (   Ra  (    s2   lib/python2.7/site-packages/jupyterlab/commands.pys	   <genexpr>  s    s   themeDir is empty: "%s"c         3  s   |  ] } | j     Vq d  S(   N(   R6   (   Rd  R   (   Rb  (    s2   lib/python2.7/site-packages/jupyterlab/commands.pys	   <genexpr>  s    s   schemaDir is empty: "%s"N(	   R$   R5   t
   isinstanceR   Rw   R   t   endswithRd   t   any(   R   R  Ra   t   mime_extensionR   R   t   filesRc  (    (   Rb  Ra  s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     sH    
		##c         C  s   t  j |  d  } d } t j d  } xg | D]_ } | j   sF q. n  | j |  } | j |  } x& | r | j |  | j |  } qg Wq. W| j   S(   s6   
    Compute the recursive sha sum of a tar file.
    R   id   i   t   sha1i  (	   R   R   t   hashlibt   newt   isfileR   R   R   t	   hexdigest(   t
   input_fileR   t
   chunk_sizet   ht   memberR   R   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR@    s    	c          C  s2   t  t t d d    }  t j |   SWd QXd S(   s'   Get the data for the app template.
    RI   s   package.jsonN(   R   R   R   R   R  (   R	  (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     s    c         C  sQ   t  |  d d  } t j j |  rI t |   } t j |  SWd QXn d Sd S(   s)   Get the data for the app static dir.
    R@   s   package.jsonN(   R   R"   R   R7   R   R   R  R5   (   R8   Rm   R	  (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     s
    c   	      C  s   | d } | d d } g  } xe | j    D]W \ } } | | k r+ t | | |  } | t k r | j | | | | f  q q+ q+ W| S(   s0   Validate the compatibility of an extension.
    R   RK   RL  (   R   t   _test_overlapRw   R   (	   Ra   R%  R   RU  RV  R   R   R   t   overlap(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR&  $  s    
$c         C  s)   t  |  |  } | d k r d S| d k S(   s   Test whether two version specs overlap.

    Returns `None` if we cannot determine compatibility,
    otherwise whether there is an overlap
    Ni    (   RN  R5   (   t   spec1t   spec2t   cmp(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRs  5  s    c         C  sQ  t  |  t  } t  | t  } | j s2 | j r6 d S| j d d j } | j d d j } | j d d j } | j d d j } | j d d j } | j d d j }	 | j d  s |	 j d  r d S| | k r t n t }
 | | k r t n t } | | k rt	 n t
 } | | k r*t	 n t
 } d   } | | k r]| j d  r]| }
 n  | | k r|	 j d  r| } n  t	 | | t  r| | | t  s| | | t  r| | | t  st	 | | t  r|
 | | t  s| | | t  r|
 | | t  rd St	 | | t  r+d St	 | | t  rAd St d   d S(	   s   Test whether two version specs overlap.

    Returns `None` if we cannot determine compatibility,
    otherwise return 0 if there is an overlap, 1 if
    spec1 is lower/older than spec2, and -1 if spec1
    is higher/newer than spec2.
    Ni    it   <c         S  s   t  S(   N(   Rd   (   t   xt   yt   z(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   noopd  s    t   >i   s(   Unexpected case comparing version ranges(   R   Rd   t   ranget   sett   semvert   operatorR6   R   R   R   R   t   AssertionError(   Ru  Rv  t   r1t   r2t   x1t   x2t   y1t   y2t   o1t   o2t   lxt   lyt   gxt   gyR|  (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRN  A  s>    				$$$$c         C  sG   x@ | D]8 } |  | k r t  St j |  j |   d k	 r t  Sq Wt S(   s*   Test whether the package is disabled.
    N(   Rd   t   ret   compilet   matchR5   Rw   (   Rc   R   t   pattern(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR   z  s    c         C  s:  g  } d } d } x | D] } | \ } } }	 t  t | t   } t  t |	 t   }	 | j | | |	 f  t | t |  d  } t | t |  d  } q Wd }
 |
 |  | f }
 |
 d 7}
 |
 d j |  7}
 |
 d j |  7}
 |
 d 7}
 x? | D]7 \ } } }	 |
 | j |  |	 j |  | d 7}
 q W|
 S(	   s/   Format a message for compatibility errors.
    i
   i   s6   
"%s@%s" is not compatible with the current JupyterLabs   
Conflicting Dependencies:
t
   JupyterLabt	   Extensions   Package
s   
(   t   strR   Rd   R   t   maxR   t   ljust(   Rc   Rp   R   t   msgst   l0t   l1t   errorR   R  R   R   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR    s&    

,c          C  s)   t    d }  t |  d  t |  d  S(   s   Get the core extensions.
    RK   R   R   (   R   t   list(   R   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyR     s    c         c  s:   x3 |  D]+ } t  | t  r* d | f Vq | f Vq Wd S(   sz  Sort key for prereleases.

    Precedence for two pre-release versions with the same
    major, minor, and patch version MUST be determined by
    comparing each dot separated identifier from left to
    right until a difference is found as follows:
    identifiers consisting of only digits are compare
    numerically and identifiers with letters or hyphens
    are compared lexically in ASCII sort order. Numeric
    identifiers always have lower precedence than non-
    numeric identifiers. A larger set of pre-release
    fields has a higher precedence than a smaller set,
    if all of the preceding identifiers are equal.
    R   N(   Re  t   int(   t
   prereleaset   entry(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   _semver_prerelease_key  s    c         C  s   t  |  t  } | r- | j r$ d n d } n d } | | j | j | j f } | sq | j rh | d n d } n  | j r | t t | j   } n  | S(   s  A sort key-function for sorting semver version string.

    The default sorting order is ascending (0.x -> 1.x -> 2.x).

    If `prerelease_first`, pre-releases will come before
    ALL other semver keys (not just those with same version).
    I.e (1.0-pre, 2.0-pre -> 0.x -> 1.x -> 2.x).

    Otherwise it will sort in the standard way that it simply
    comes before any release with shared version string
    (0.x -> 1.0-pre -> 1.x -> 2.0-pre -> 2.x).
    i    i   (   i    (   i   (    (   i    (   i   (   R   Rd   R  t   majort   minort   patchRM  R  (   Rp   RC  t   vR   (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRD    s    		c         C  s   t  t |  t | d d  d i d d 6} y | j d | j  Wn( t k
 rp | j d | j    n Xy> t j t	 |   # } t
 j | j   j d   SWd QXWn) t k
 r } | j d	 | |    n Xd S(
   s6   Fetch the metadata for a package from the npm registryt   safeR6  t   headerssH   application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*t   Accepts   Fetching URL: %ss   utf-8Ns+   Failed to fetch package metadata for %r: %r(   R   R   R   t   debugt   full_urlt   AttributeErrort   get_full_urlt
   contextlibt   closingR   R   R   R   R   R   R7  (   R   Rc   R>   t   reqt   responset   exc(    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyRH    s     &
t   __main__(k   t   __doc__t
   __future__R    R  t   distutils.versionR   R-  R#  Rk  R   RP   R"   t   os.pathR   R   R  Rk   R3   R0   R   t	   threadingR   t   ipython_genutils.tempdirR   t   jupyter_core.pathsR   t   jupyterlab_launcher.processR   R   R   t   notebook.nbextensionsR   R	   R
   R   R  R   R   R   R   R   R   t   jlpmappR   R   t   version_infoR  t   urllib2R   R   R   R   R   t   urlparseR   t   urllib.requestt   urllib.errorR  RY   R   R   RX   R   R&   R*   R:   R5   RH   RJ   RW   R\   RN   R`   Rb   Rw   Rf   Rn   RA   Ru   Rx   Ry   Rz   R|   R}   R~   R   R   R   R   t   objectR^   R]   R   R   R@  R   R   R&  Rs  RN  R   R  R   R  RD  RH  R\  (    (    (    s2   lib/python2.7/site-packages/jupyterlab/commands.pyt   <module>   s   "."!		
	
	"
				
			    >	
			5						9				