σ
ΌS]c        	   @@  s  d  Z  d d l m Z d d l m Z d d l m Z d d l j Z d d l Z d d l	 Z	 d d l
 Z
 d d l m Z d d l m Z m Z m Z y d d l m Z Wn! e k
 rΜ d d l m Z n Xy d d l m Z Wn! e k
 rd d l m Z n Xd( Z d) Z e e Z d   Z e d d d g  Z e d e  e d e  e d e  e d e  e d e  e d e  e d e  f Z d e  f d     YZ! d e! f d      YZ" d! e! f d"     YZ# d# e  f d$     YZ$ d%   Z% d& e  f d'     YZ& d S(*   s3   Class representing a command from the project file.i    (   t   absolute_import(   t   copy(   t
   namedtupleN(   t   _verbose_logger(   t	   conda_apit   logged_subprocesst
   py2_compat(   t   quotet   descriptiont   env_spect   supports_http_optionst	   bokeh_appt   notebookt   unixt   windowst   conda_app_entryt   registers_fusion_functionc           C@  s   t  j   d k S(   Nt   Windows(   t   platformt   system(    (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyt   _is_windows&   s    t   _ArgSpect   optiont	   has_values   --anaconda-project-hosts   --anaconda-project-addresss   --anaconda-project-ports   --anaconda-project-url-prefixs   --anaconda-project-no-browsers   --anaconda-project-iframe-hostss   --anaconda-project-use-xheaderst   _ArgsTransformerc           B@  s)   e  Z e Z d    Z d   Z d   Z RS(   c         C@  sk  | s
 g  S| d } | d k r$ | Sx)|  j  D]} | j r| j d } | | j k rΥ t |  d k s~ | d j d  r¦ | | j j d  |  j | | d  S| | j j | d  |  j | | d  SqL| j |  rL| | j j | t |   |  j | | d  Sq. | | j k r. t g | | j <|  j | | d  Sq. W| g |  j | | d  S(   Ni    s   --t   =i   t   -t    i   (   t   specsR   R   t   lent
   startswitht   appendt   _parse_args_removing_knownt   True(   t   selft   resultst   argst   argt   spect   with_equals(    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR    7   s*    
	%c         C@  sP   d   |  j  D } |  j | |  } t | j   d d   } |  j | |  S(   Nc         S@  s   i  |  ] } g  | j   q S(    (   R   (   t   .0R&   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pys
   <dictcomp>Z   s   	 t   keyc         S@  s   |  d S(   Ni    (    (   t   x(    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyt   <lambda>]   R   (   R   R    t   sortedt   itemst   add_args(   R"   R$   R#   t   with_removedt   results_list(    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyt   transform_argsY   s    c         C@  s   | S(   N(    (   R"   R#   R$   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR.   `   s    (   t   __name__t
   __module__t
   HTTP_SPECSR   R    R1   R.   (    (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR   4   s   	"	t   _BokehArgsTransformerc           B@  s   e  Z d    Z RS(   c         C@  s  g  } x	| D]\ } } | d k r_ xζ | D], } | j  | j d d   | j  |  q, Wq | d k r x  | D]  } | j  d  | j  |  qr Wq | d k rΎ | s| j  d	  qq | d
 k rσ | r| d t k r| j  d  qq | d k rq t d   q W| | S(   Ns   --anaconda-project-hosts   --anaconda-project-ports   --anaconda-project-addresss   anaconda-project-R   s   --anaconda-project-url-prefixs   --prefixs   --anaconda-project-no-browsers   --shows   --anaconda-project-use-xheadersi    s   --use-xheaderss   --anaconda-project-iframe-hostss#   unhandled http option for bokeh app(   s   --anaconda-project-hosts   --anaconda-project-ports   --anaconda-project-address(   R   t   replaceR!   t   RuntimeError(   R"   R#   R$   t   addedR   t   valuest   v(    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR.   f   s(    (   R2   R3   R.   (    (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR5   e   s   t   _NotebookArgsTransformerc           B@  s   e  Z d    Z d   Z RS(   c         C@  s   | |  _  d  S(   N(   t   command(   R"   R<   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyt   __init__   s    c         C@  sζ  g  } t  j j |  j j  } d t |  } | j |  x | D]\ } } | d k r] qB | d k r£ xn| D], } | j | j d d   | j |  qp WqB | d k rέ x(| D]  } | j d  | j |  qΆ WqB | d k r| rΪ| d	 t k rΪ| j d
  qΪqB | d k rCxΉ | D] } | j d |  q%WqB | d k rt	 |  d	 k rΪd d j
 |  }	 d |	 d }
 | j d |
  qΪqB | d k rΞ| rΪ| d	 t k rΪ| j d  qΪqB t d   qB W| | S(   Ns'   --NotebookApp.default_url=/notebooks/%ss   --anaconda-project-hosts   --anaconda-project-ports   anaconda-project-R   s   --anaconda-project-addresss   --ips   --anaconda-project-no-browseri    s   --no-browsers   --anaconda-project-url-prefixs   --NotebookApp.base_url=s   --anaconda-project-iframe-hostss   'self' t    s;   { 'headers': { 'Content-Security-Policy': "frame-ancestors s   " } }s   --NotebookApp.tornado_settings=s   --anaconda-project-use-xheaderss!   --NotebookApp.trust_xheaders=Trues#   unhandled http option for notebooks(   t   ost   patht   basenameR<   R   t	   url_quoteR   R6   R!   R   t   joinR7   (   R"   R#   R$   R8   t   filenamet   default_url_argR   R9   R:   t	   full_listt   python_dict_literal(    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR.      s>    (   R2   R3   R=   R.   (    (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR;      s   	t   CommandExecInfoc           B@  sk   e  Z d  Z d d d  Z e d    Z e d    Z e d    Z e d    Z	 d   Z
 d   Z RS(	   s'   Class describing an executable command.c         C@  sL   | |  _  | |  _ | |  _ | |  _ | t k sH t |  d k sH t  d S(   s   Construct a CommandExecInfo.i   N(   t   _cwdt   _argst   _shellt   _envt   FalseR   t   AssertionError(   R"   t   cwdR$   t   shellt   envR   R   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR=   Ύ   s
    				c         C@  s   |  j  S(   s(   Working directory to run the command in.(   RI   (   R"   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyRO   Ζ   s    c         C@  s   |  j  S(   s»   Command line argument vector to run the command.

        If the ``shell`` property is True, then pass args[0] as a string to Popen,
        rather than this entire list of args.
        (   RJ   (   R"   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR$   Λ   s    c         C@  s   |  j  S(   s2   Whether the command should be run with shell=True.(   RK   (   R"   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyRP   Τ   s    c         C@  s   |  j  S(   s"   Environment to run the command in.(   RL   (   R"   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyRQ   Ω   s    c      
   K@  st   |  j  r4 t |  j  d k s$ t  |  j d } n	 |  j } t j d | d t j |  j  d |  j	 d |  j  |  S(   s‘   Convenience method runs the command using Popen.

        Args:
            kwargs: passed through to Popen

        Returns:
            Popen instance
        i   i    R$   RQ   RO   RP   (
   RK   R   RJ   RN   R   t   PopenR   t   env_without_unicodeRL   RI   (   R"   t   kwargsR$   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyt   popenή   s    		
		c         C@  sν   t  |  j  } |  j rh t |  d k s0 t  t   rU t j |  j   j	    qh d d g | } n  zp t
 j   } t
 j |  j  t j j   t j j   t   j d d j |   t
 j | d | |  j  Wd t
 j |  Xd S(   s   Convenience method exec's the command replacing the current process.

        Returns:
            Does not return. May raise an OSError though.
        i   s   /bin/shs   -cs   $ %sR>   i    N(   R   RJ   RK   R   RN   R   t   syst   exitRU   t   waitR?   t   getcwdt   chdirRI   t   stderrt   flusht   stdoutR   t   infoRC   t   execvpeRL   (   R"   R$   t   old_dir(    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR_   ω   s    		N(   R2   R3   t   __doc__t   NoneR=   t   propertyRO   R$   RP   RQ   RU   R_   (    (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyRH   »   s   		c         C@  sv   | s
 |  St    rC d d l m } m } | |   } | | |  S|  } x" | D] } | d t |  } qP W| Sd  S(   Ni    (   t   windows_split_command_linet   windows_join_command_lineR>   (   R   t)   anaconda_project.internal.windows_cmdlineRd   Re   R   (   R<   t
   extra_argsRd   Re   R$   t   new_commandR%   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyt"   _append_extra_args_to_command_line  s    	t   ProjectCommandc           B@  sζ   e  Z d  Z d   Z e d    Z e d    Z e d    Z e d    Z e d    Z	 e d    Z
 e d    Z e d	    Z e d
    Z d   Z e d    Z e d    Z d d  Z d d  Z d   Z RS(   s+   Represents a command from the project file.c         C@  s(   d | k s t   | |  _ | |  _ d S(   s±   Construct a command with the given attributes.

        Args:
            name (str): name of the command
            attributes (dict): named attributes of the command
        R	   N(   RN   t   _namet   _attributes(   R"   t   namet
   attributes(    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR=   -  s    	c         C@  s   |  j  S(   s   Get name of the command.(   Rk   (   R"   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyRm   8  s    c         C@  s1   |  j  d k	 p |  j d k	 } |  j j d |  S(   s=   Can accept the --anaconda-project-* options for HTTP servers.R
   N(   R   Rb   R   Rl   t   get(   R"   t   default(    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR
   =  s    c         C@  s   |  j  j d d  S(   s9   Notebook filename relative to project directory, or None.R   N(   Rl   Ro   Rb   (   R"   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR   C  s    c         C@  s   |  j  j d d  S(   s:   Bokeh app filename relative to project directory, or None.R   N(   Rl   Ro   Rb   (   R"   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR   H  s    c         C@  s   |  j  j d d  S(   sμ   Unix shell command line string, or None.

        This property is here to support displaying the command in
        a UI, but shouldn't be used to execute the command; use
        ``exec_info_for_environment()`` for executing.
        R   N(   Rl   Ro   Rb   (   R"   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyt   unix_shell_commandlineM  s    c         C@  s   |  j  j d d  S(   sι   cmd.exe command line string, or None.

        This property is here to support displaying the command in
        a UI, but shouldn't be used to execute the command; use
        ``exec_info_for_environment()`` for executing.
        R   N(   Rl   Ro   Rb   (   R"   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyt   windows_cmd_commandlineW  s    c         C@  s   |  j  j d d  S(   sΓ   Argv to exec directly, or None.

        This isn't allowed in the config file but we do generate
        it on the fly when we run stuff that isn't a configured
        project command.
        R$   N(   Rl   Ro   Rb   (   R"   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR$   a  s    c         C@  s   |  j  j d d  S(   sι   Conda "app entry" style command line.

        This property is here to support displaying the command in
        a UI, but shouldn't be used to execute the command; use
        ``exec_info_for_environment()`` for executing.
        R   N(   Rl   Ro   Rb   (   R"   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR   k  s    c         C@  s   |  j  j d  S(   sT   Get the environment spec name used for this command unless user specified otherwise.R	   (   Rl   Ro   (   R"   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyt   default_env_spec_nameu  s    c         C@  s   t    r d Sd Sd  S(   NR   R   (   R   (   R"   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyt   _shell_fieldz  s    	c         C@  s  |  j  j d d  } | d k rC |  j d k	 rC d |  j } qC n  | d k rq |  j d k	 rq d |  j } qq n  | d k r |  j  j d d  } n  | d k rΉ |  j  j d d  } n  | d k rέ |  j  j d d  } n  | d k rώ t |  d d  } n  | d k	 st  | S(	   s+   Helpful string showing what the command is.R   s   Bokeh app %ss   Notebook %sR   R   R   R<   N(   Rl   Ro   Rb   R   R   t   getattrRN   (   R"   R   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyR     s"    c         C@  sG   t    } x7 |  j j   D]& } | t k r |  j | | | <q q W| S(   s©   Dictionary of extra attributes not covered by other properties.

        These are typically 'plugin specific' (only for notebook, only for bokeh,
        etc.)
        (   t   dictRl   t   keyst   extra_command_attributes(   R"   t   resultt   k(    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyt   extras  s
    	c   
      C@  s=  | d  k s! t | t  s! t  d  } t } |  j sK t   j |  } n  |  j d  k	 r¦ t	 j
 j | d |  j  } d | g } |  j r¦ t |   j |  } q¦ n  |  j d  k	 rt	 j
 j | d |  j  } d d | g } |  j rt   j |  } qn  |  j d  k	 r|  j } n  | d  k	 rK| d  k	 rA| | } n  | t f S|  j j |  j   d   } | d  k	 rt | |  g } t } n  | d  k r3|  j j d d   } | d  k	 r3| j   } g  } xE | D]= }	 d |	 k r|	 j d t j |   }	 n  | j |	  qΣW| d  k	 r0| | } q0q3n  | | f S(   Nt   PROJECT_DIRs   jupyter-notebookt   bokeht   serveR   s	   ${PREFIX}(   Rb   t
   isinstancet   listRN   RM   R
   R   R1   R   R?   R@   RC   R;   R   R5   R$   Rl   Ro   Rt   Ri   R!   t   splitR6   R   t   environ_get_prefixR   (
   R"   t   environRg   R$   RP   R@   R<   t	   app_entryt   parsedR%   (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyt   _choose_args_and_shell§  sJ    !			
	c   	   	   C@  sτ   t  j   } x6 | d d f D]% } | | k r t d |   q q W|  j | |  \ } } | d	 k rm d	 St j j | d | d g  } | sΡ t j	 | d |  } | d	 k	 rΡ t j
 j |  | d <qΡ n  t d | d d | d | d |  S(
   s(  Get a ``CommandExecInfo`` ready to be executed.

        Args:
            environ (dict): the environment containing a CONDA_PREFIX, PATH, and PROJECT_DIR
            extra_args (list of str): extra args to append to the command line
        Returns:
            argv as list of strings
        t   PATHR|   s6   To get a runnable command for the app, %s must be set.i    RO   R$   RQ   RP   N(   R   t   conda_prefix_variablet
   ValueErrorR   Rb   R?   t   pathsepRC   t   spawnt   find_executableR@   t   abspathRH   (	   R"   R   Rg   t	   conda_varRm   R$   RP   R@   t
   executable(    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyt   exec_info_for_environmentέ  s    	 
c         C@  sx   g  } d | j  k rt |  j d k	 rC d | j  k rC | j d  n  |  j d k	 rt d | j  k rt | j d  qt n  | S(   sζ   List packages required by this command which are not in the env spec.

        This is used to be sure if you add a notebook command you depend on
        notebook, and if you add a Bokeh command you depend on bokeh, etc.
        t   anacondaR}   R   N(   t   conda_package_names_setR   Rb   R   R   (   R"   R	   t   missing(    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyt   missing_packages  s    N(   R2   R3   Ra   R=   Rc   Rm   R
   R   R   Rq   Rr   R$   R   Rs   Rt   R   R{   Rb   R   R   R   (    (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyRj   *  s"   	



	6/(   R   R	   R
   R   R   R   R   R   (   R   ('   Ra   t
   __future__R    R   t   collectionsR   t   distutils.spawnR   R?   R   RV   t   anaconda_project.verboseR   t   anaconda_project.internalR   R   R   t   shlexR   t   ImportErrort   pipest   urllib.parseRB   t   urllibt   standard_command_attributesRx   t   all_known_command_attributesR   R   R!   RM   R4   t   objectR   R5   R;   RH   Ri   Rj   (    (    (    s@   lib/python2.7/site-packages/anaconda_project/project_commands.pyt   <module>   sB    
	1;_	