ó
¼S]c        	   @@ sž  d  Z  d d l m Z d d l m Z d d l m Z m 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 d d
 l m Z d d l m Z d d l m Z d d l m Z m Z d d l m Z d d l m Z m Z m Z d d l m  Z  d „  Z! d e e ƒ f d „  ƒ  YZ" d e" f d „  ƒ  YZ# d e" f d „  ƒ  YZ$ d e% f d „  ƒ  YZ& d e e ƒ f d „  ƒ  YZ' d „  Z( d e' f d „  ƒ  YZ) d e' f d  „  ƒ  YZ* d! „  Z+ d" „  Z, d# „  Z- d$ „  Z. d% „  Z/ d& „  Z0 d' „  Z1 d( „  Z2 d d d) „ Z4 d* „  Z5 d e6 e d d d d d d+ „ Z7 d, „  Z8 d- „  Z9 d. „  Z: d/ „  Z; d e d d d d d d0 „ Z< d1 „  Z= d d2 „ Z> d S(3   s   Prepare a project to run.i    (   t   absolute_import(   t   print_function(   t   ABCMetat   abstractmethodN(   t   deepcopy(   t   with_metaclass(   t   SimpleStatus(   t   toposort_from_dependency_info(   t	   conda_api(   t	   is_string(   t   LocalStateFile(   t   _all_provide_modest   PROVIDE_MODE_DEVELOPMENT(   t   ProvideContext(   t   Requirementt   EnvVarRequirementt   UserConfigOverrides(   t   CondaEnvRequirementc         C@ sJ   xC | j  ƒ  D]5 \ } } | |  k s5 |  | | k r | |  | <q q Wd S(   s}   Overwrite ``environ`` with any additions from the prepared environ.

    Does not remove any variables from ``environ``.
    N(   t   items(   t   destt   srct   keyt   value(    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   _update_environ   s    t   PrepareResultc           B@ s¡   e  Z d  Z d „  Z d „  Z d „  Z e e d „  ƒ ƒ Z e d „  ƒ Z	 d „  Z
 e d „  ƒ Z e d „  ƒ Z e d	 „  ƒ Z e d
 „  ƒ Z e d „  ƒ Z RS(   sE   Abstract class describing the result of preparing the project to run.c         C@ s.   t  | ƒ |  _ | |  _ | |  _ | |  _ d S(   s$   Construct an abstract PrepareResult.N(   t   tuplet	   _statusest   _environt
   _overridest   _env_spec_name(   t   selft   statusest   environt	   overridest   env_spec_name(    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   __init__+   s    		c         C@ s   |  j  S(   s   True if we were successful.(   t   failed(   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   __bool__2   s    c         C@ s
   |  j  ƒ  S(   s   True if we were successful.(   R%   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   __nonzero__6   s    c         C@ s   d S(   sÕ   True if we failed to do what this stage was intended to do.

        If ``execute()`` returned non-None, the failure may not be fatal; stages
        can continue to be executed and may resolve the issue.
        N(    (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR$   :   s    c         C@ s   |  j  S(   s†   Get latest RequirementStatus if available.

        If we failed before we even checked statuses, this will be an empty list.
        (   R   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR   D   s    c         C@ se   x^ |  j  D]S } t | ƒ rG t | j t ƒ r] | j j | k r] | Sq
 t | j | ƒ r
 | Sq
 Wd S(   s>   Get status for the given env var or class, or None if unknown.N(   R   R	   t
   isinstancet   requirementR   t   env_vart   None(   R   t   env_var_or_classt   status(    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt
   status_forL   s    c         C@ s   |  j  S(   s¸   Computed environment variables for the project.

        If ``failed`` is True, this environ dict may be unmodified
        from the original provided to the prepare function.
        (   R   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR    W   s    c         C@ s   |  j  S(   s.   Override object which was passed to prepare().(   R   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR!   `   s    c         C@ s   t  ƒ  ‚ d S(   s   Get lines of error output.N(   t   NotImplementedError(   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   errorse   s    c         C@ s   |  j  S(   s  The env spec name we used for the prepare.

        If the project was broken or the user provided bad input
        before we could ask CondaEnvRequirement for the env spec
        name, at the moment we sort of take a guess at the right
        name in order to guarantee this is never None. The
        guessing is a little bit broken. But it would be a very
        obscure scenario where it matters.
        (   R   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR"   j   s    c         C@ s>   |  j  t ƒ } | d k r d S| j j } |  j j | d ƒ S(   s<   The prefix of the prepared env, or None if none was created.N(   R-   R   R*   R(   R)   R   t   get(   R   R,   t   varname(    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt
   env_prefixw   s
    (   t   __name__t
   __module__t   __doc__R#   R%   R&   t   propertyR   R$   R   R-   R    R!   R/   R"   R2   (    (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR   (   s   						t   PrepareSuccessc           B@ sM   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z RS(   sG   Class describing the successful result of preparing the project to run.c         C@ sA   t  t |  ƒ j | | | | ƒ | |  _ |  j d k	 s= t ‚ d S(   sA   Construct a PrepareSuccess indicating a successful prepare stage.N(   t   superR7   R#   t   _command_exec_infoR"   R*   t   AssertionError(   R   R   t   command_exec_infoR    R!   R"   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR#   „   s    	c         C@ s   t  S(   s   Get False for PrepareSuccess.(   t   False(   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR$   Š   s    c         C@ s   |  j  S(   s7   ``CommandExecInfo`` instance if available, None if not.(   R9   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR;      s    c         C@ s   g  S(   s   Get empty list of errors.(    (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR/   ”   s    c         C@ s   t  | |  j ƒ d S(   s…   Overwrite ``environ`` with any additions from the prepared environ.

        Does not remove any variables from ``environ``.
        N(   R   R   (   R   R    (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   update_environ™   s    (	   R3   R4   R5   R#   R6   R$   R;   R/   R=   (    (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR7      s   	t   PrepareFailurec           B@ s8   e  Z d  Z d d „ Z e d „  ƒ Z e d „  ƒ Z RS(   sC   Class describing the failed result of preparing the project to run.c         C@ s,   t  t |  ƒ j | | | | ƒ | |  _ d S(   s=   Construct a PrepareFailure indicating a failed prepare stage.N(   R8   R>   R#   t   _errors(   R   R   R/   R    R!   R"   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR#   ¤   s    c         C@ s   t  S(   s   Get True for PrepareFailure.(   t   True(   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR$   ©   s    c         C@ s   |  j  S(   s   Get non-empty list of errors.(   R?   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR/   ®   s    N(   R3   R4   R5   R*   R#   R6   R$   R/   (    (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR>   ¡   s   t   ConfigurePrepareContextc           B@ s   e  Z d  Z d „  Z RS(   s(   Information needed to configure a stage.c         C@ so   | |  _  | |  _ | |  _ | |  _ | |  _ t | ƒ d k rk d d l m } t | d | ƒ sk t	 ‚ n  d S(   s$   Construct a ConfigurePrepareContext.i    (   t   RequirementStatusN(
   R    t   local_state_filet   default_env_spec_nameR!   R   t   lent2   anaconda_project.requirements_registry.requirementRB   R'   R:   (   R   R    RC   RD   R!   R   RB   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR#   ·   s    					(   R3   R4   R5   R#   (    (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRA   ´   s   t   PrepareStagec           B@ s¿   e  Z d  Z e e d „  ƒ ƒ Z e e d „  ƒ ƒ Z e d „  ƒ Z e d „  ƒ Z e e d „  ƒ ƒ Z	 e e d „  ƒ ƒ Z
 e e d „  ƒ ƒ Z e e d „  ƒ ƒ Z e e d	 „  ƒ ƒ Z RS(
   s*   A step in the project preparation process.c         C@ s   d S(   sH   Get a user-visible description of what happens if this step is executed.N(    (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   description_of_actionÆ   s    c         C@ s   d S(   s>   Synonym for result.failed, only available after ``execute()``.N(    (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR$   Ì   s    c         C@ s   d S(   sË   Get a ``ConfigurePrepareContext`` or None if no configuration is needed.

        Configuration should be done before execute().

        Returns:
          a ``ConfigurePrepareContext`` or None
        N(    (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt	   configureÒ   s    	c         C@ s   d S(   sG   Run this step and return a new stage, or None if we are done or failed.N(    (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   executeÝ   s    c         C@ s   d S(   sH   The ``PrepareResult`` (only available if ``execute()`` has been called).N(    (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   resultâ   s    c         C@ s   d S(   sZ   The latest environment variables (from the result if any, otherwise the pre-execute ones).N(    (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR    è   s    c         C@ s   d S(   s   User overrides.N(    (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR!   î   s    c         C@ s   d S(   s	  ``RequirementStatus`` list before execution.

        This list includes all known requirements and their statuses, while the list
        in the ``configure()`` context only includes those that should be configured
        prior to this stage's execution.
        N(    (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   statuses_before_executeô   s    	c         C@ s   d S(   sÕ   ``RequirementStatus`` list after execution.

        This list includes all known requirements and their statuses, as changed
        by ``execute()``. This property cannot be read prior to ``execute()``.
        N(    (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   statuses_after_executeÿ   s    (   R3   R4   R5   R6   R   RH   R$   RI   RJ   RK   R    R!   RL   RM   (    (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRG   Ã   s"   
c         C@ s^   t  ƒ  } x | D] } | | | j <q Wg  } x* |  D]" } | j | j | j | ƒ ƒ q4 W| S(   N(   t   dictR(   t   appendR0   (   t   old_statusest   rechecked_statusest
   new_by_reqR,   t   updated(    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   _refresh_status_list  s    	 t   _FunctionPrepareStagec           B@ sž   e  Z d  Z d d „ Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z	 e d „  ƒ Z
 e d „  ƒ Z e d „  ƒ Z e d	 „  ƒ Z e d
 „  ƒ Z d „  Z RS(   s^   A stage chain where the description and the execute function are passed in to the constructor.c         C@ s‚   t  | t ƒ s t ‚ | d  k s6 t  | t ƒ s6 t ‚ | |  _ | |  _ d  |  _ d  |  _ | |  _	 | |  _
 | |  _ | |  _ d  S(   N(   R'   RN   R:   R*   RA   R   R   t   _resultt   _statuses_after_executet   _descriptiont   _statuses_before_executet   _executet   _config_context(   R   R    R!   t   descriptionR   RJ   t   config_context(    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR#     s    !							c         C@ s   |  j  S(   N(   RX   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRH   ,  s    c         C@ s
   |  j  j S(   N(   RK   R$   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR$   0  s    c         C@ s   |  j  S(   N(   R[   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRI   4  s    c         C@ s   |  j  |  ƒ S(   N(   RZ   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRJ   7  s    c         C@ s%   |  j  d  k r t d ƒ ‚ n  |  j  S(   Ns5   result property isn't available until after execute()(   RV   R*   t   RuntimeError(   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRK   :  s    c         C@ s$   |  j  d  k r |  j S|  j j Sd  S(   N(   RV   R*   R   RK   R    (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR    @  s    c         C@ s   |  j  S(   N(   R   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR!   G  s    c         C@ s   |  j  S(   N(   RY   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRL   K  s    c         C@ s%   |  j  d  k r t d ƒ ‚ n  |  j  S(   Ns<   statuses_after_execute isn't available until after execute()(   RW   R*   R^   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRM   O  s    c         C@ s4   | d  k	 s t ‚ t |  j | ƒ |  _ | |  _ d  S(   N(   R*   R:   RT   RY   RW   RV   (   R   RK   RQ   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt
   set_resultU  s    N(   R3   R4   R5   R*   R#   R6   RH   R$   RI   RJ   RK   R    R!   RL   RM   R_   (    (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRU     s   		t   _AndThenPrepareStagec           B@ s’   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z e d	 „  ƒ Z e d
 „  ƒ Z RS(   sQ   A stage chain which runs an ``and_then`` function after it executes successfully.c         C@ s   | |  _  | |  _ d  S(   N(   t   _staget	   _and_then(   R   t   staget   and_then(    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR#   ^  s    	c         C@ s
   |  j  j S(   N(   Ra   RH   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRH   e  s    c         C@ s
   |  j  j S(   N(   Ra   R$   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR$   i  s    c         C@ s   |  j  j ƒ  S(   N(   Ra   RI   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRI   m  s    c         C@ sU   |  j  j ƒ  } | d  k rA |  j  j r+ d  S|  j |  j  j ƒ Sn t | |  j ƒ Sd  S(   N(   Ra   RJ   R*   R$   Rb   RM   R`   (   R   t   next(    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRJ   p  s    c         C@ s
   |  j  j S(   N(   Ra   RK   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRK   z  s    c         C@ s
   |  j  j S(   N(   Ra   R    (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR    ~  s    c         C@ s
   |  j  j S(   N(   Ra   R!   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR!   ‚  s    c         C@ s
   |  j  j S(   N(   Ra   RL   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRL   †  s    c         C@ s
   |  j  j S(   N(   Ra   RM   (   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRM   Š  s    (   R3   R4   R5   R#   R6   RH   R$   RI   RJ   RK   R    R!   RL   RM   (    (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR`   [  s   			
c         C@ s   |  d k	 s t ‚ t |  | ƒ S(   s°   Run and_then function after stage executes successfully.

    and_then may return another stage, or None. It takes
    the current list of updated statuses as a parameter.
    N(   R*   R:   R`   (   Rc   Rd   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   _after_stage_success  s    c         @ s:   d „  } ‡ f d †  } ‡  f d †  } t  | | | | ƒ S(   Nc         S@ s"   t  |  j d ƒ s t ‚ |  j j S(   NR)   (   t   hasattrR(   R:   R)   (   R,   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   get_node_keyš  s    c         @ s1   t  ƒ  } x! ˆ  |  ƒ D] } | j | ƒ q W| S(   N(   t   sett   add(   R,   t   config_keysR)   (   t   missing_vars_getter(    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   get_dependency_keys¡  s    	c         @ s
   |  ˆ  k S(   N(    (   R   (   R    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   can_ignore_dependency_on_key§  s    (   R   (   R    t   local_stateR   Rl   Rh   Rm   Rn   (    (   R    Rl   s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   _sort_statuses™  s    	c         C@ s‹   |  d  k r t Sxt |  D]l } t | t ƒ r? | | k rƒ t Sq t | ƒ rp t | t ƒ rƒ | j | k rƒ t Sq t | | ƒ r t Sq Wt S(   N(   R*   R@   R'   R   R	   R   R)   R<   (   t   provide_whitelistR(   t   env_var_or_class_or_req(    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   _in_provide_whitelist°  s    c         @ sj   ˆ
 j  ˆ ƒ ‰ ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡	 ‡
 ‡ ‡ f d †  ‰ ‡ ‡ ‡ ‡	 ‡ f d †  ‰  ˆ  ˆ ˆ ƒ S(   Nc         @ sÉ  d „  } t  ˆ ˆ ˆ | ƒ } g  } x- | D]% } | j | j ˆ ˆ ˆ ˆ	 ƒ ƒ q+ Wg  } t } t ƒ  } x‹ | D]ƒ } t ˆ | j ƒ sŽ qp qp | j r qp qp t } t	 ˆ ˆ ˆ | ˆ ˆ
 j
 ƒ } | j j | j | ƒ }	 | j |	 j ƒ |	 | | <qp W| rK| }
 g  } x? |
 D]4 } | j | j ˆ ˆ ˆ ˆ	 d | j | ƒ ƒƒ qWn  t } x} | D]u } | sX| j d j d | j ƒ ƒ ˆ
 j
 j | d ƒ | j d j d | j ƒ ƒ ˆ
 j
 j | d ƒ t } qXqXWt ˆ | ƒ } d  } x) | D]! } | j d  k	 rí| j } qíqíW| rf|  j t d | d	 | d
 ˆ d ˆ	 d | ƒ | ƒ ˆ r_ˆ  |  j | ƒ Sd  Sn_ ˆ d  k r{d  } n ˆ j ˆ d ˆ ƒ} |  j t d | d | d
 ˆ d ˆ	 d | ƒ | ƒ d  Sd  S(   Nc         S@ s
   |  j  j S(   N(   t   analysist   missing_env_vars_to_provide(   R,   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   get_missing_to_provideÈ  s    t   latest_provide_resultsB   missing requirement to run this project: {requirement.description}R(   iÿÿÿÿs     {why_not}t   why_notR   R/   R    R!   R"   t
   extra_argsR;   (   Rp   RO   t   recheckR<   RN   Rs   R(   t   has_been_providedR@   R   t   frontendt   providert   providet   extendR/   R0   t   formatt   errort   status_descriptionRT   R*   R"   R_   R>   RM   t   exec_info_for_environmentR7   (   Rc   Rv   t   sortedt	   recheckedR,   R/   t   did_any_providingt   results_by_statust   contextRK   t   oldR$   t   result_statusest   current_env_spec_namet	   exec_info(   t   _start_overt   all_statusest   commandRD   R    t   extra_command_argst   keep_going_until_successRo   t   modeR!   t   projectRq   R   (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   provide_stageÇ  s‚    	#			c         @ s@   t  d ˆ d ˆ d ˆ  d ˆ d | ƒ } t ˆ ˆ d |  ˆ | ƒ S(   NR    RC   RD   R!   R   s   Set up project.(   RA   RU   (   t   updated_all_statusest   updated_statusest   configure_context(   RD   R    Ro   R!   R”   (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR      s    	(   t!   default_env_spec_name_for_command(   R“   R    Ro   R   RŽ   R‘   R’   Rq   R!   R   R   (    (   R   RŽ   R   RD   R    R   R‘   Ro   R’   R!   R“   R”   Rq   R   s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   _configure_and_provideÂ  s    3Y
c   	      C@ s¹   d „  } t  |  | | | ƒ } g  } g  } | j ƒ  xa | r— | j ƒ  } | j j | j |  | ƒ } t | ƒ d k r‡ | j | ƒ Pq7 | j | ƒ q7 W| j ƒ  | j | ƒ | | f S(   Nc         S@ s
   |  j  j S(   N(   Rt   t   missing_env_vars_to_configure(   R,   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   get_missing_to_configure.  s    i    (	   Rp   t   reverset   popR}   Rš   R(   RE   RO   R   (	   R    Ro   R   R›   R„   t   headt   tailR,   t   missing_vars(    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt#   _partition_first_group_to_configure-  s    	
	
c      
   @ sß   t  ˆ ˆ | ƒ \ } ‰
 ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡	 f
 d †  } t | ƒ d k r£ t ˆ
 ƒ d k r£ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡	 ‡
 f
 d †  } t | | ƒ | ƒ St | ƒ d k r¿ | | ƒ St sÑ t d ƒ ‚ | ˆ
 ƒ Sd  S(   Nc         @ s(   t  ˆ ˆ ˆ |  ˆ  ˆ ˆ ˆ	 ˆ ˆ ˆ ƒ S(   N(   R™   (   R   (
   RŽ   R   R    R   R‘   Ro   R’   R!   R“   Rq   (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   _stages_forZ  s    i    c         @ s7   t  ˆ	 |  ƒ } t ˆ ˆ ˆ | |  ˆ ˆ ˆ ˆ ˆ  ˆ ƒ S(   N(   RT   t   _process_requirement_statuses(   R•   RS   (
   R   R    R   R‘   Ro   R’   R!   R“   Rq   t	   remaining(    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   process_remaining`  s    s'   This code should not be reachable, bug!(   R¡   RE   Rf   R<   R:   (   R“   R    Ro   t   current_statusesRŽ   R‘   R’   Rq   R!   R   R   t   initialR¢   R¥   (    (   RŽ   R   R    R   R‘   Ro   R’   R!   R“   Rq   R¤   s7   lib/python2.7/site-packages/anaconda_project/prepare.pyR£   M  s    
*$*
c   
      C@ sÊ   t  ƒ  } x9 | D]1 } t | j d ƒ s. t ‚ | j | | j j <q Wt ƒ  } xR | D]J } | j | j j | j | | ƒ ƒ | j | j j	 | j | | ƒ ƒ qU Wx  | D] }	 |	 | k sª t ‚ qª Wd  S(   NR)   (
   RN   Rg   R(   R:   R)   Ri   t   updateR}   Rš   Ru   (
   R“   R    Ro   R!   R   R   t
   by_env_varR,   t   needed_env_varsR)   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt'   _assert_no_missing_env_var_requirementsw  s    		"&c
         C@ sY   d | k s t  ‚ t |  | | | | | ƒ t |  | | | | | | | | | |	 ƒ }
 |
 S(   Nt   PROJECT_DIR(   R:   R«   R£   (   R“   R    Ro   R   R‘   R’   Rq   R!   R   R   t   first_stage(    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   _first_stage—  s    	c         C@ s„   | d  k r t j } n  d | k s* t ‚ t | j ƒ  ƒ } |  j | d <t j | ƒ } t j	 | ƒ t
 d | d | ƒ } | | f S(   Nt   PATHR¬   R"   t   inherited_env(   R*   t   osR    R:   R   t   copyt   directory_pathR   t   environ_get_prefixt   environ_delete_prefix_variablesR   (   R“   R    R"   t   environ_copyt   existing_env_prefixR!   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   _prepare_environ_and_overrides¤  s    c	         C@ sB  |  j  s t ‚ | t k r/ t d | ƒ ‚ n  | d  k	 oD | d  k	 sN t ‚ | d  k so | |  j k so t ‚ | j d  k s– | j |  j k s– t ‚ | d  k r´ |  j | ƒ } n  t	 j
 |  j ƒ }	 g  }
 xN |  j | j ƒ D]: } | j | |	 |  j | ƒ | d d  ƒ} |
 j | ƒ qß Wt |  | |	 |
 | | | | | | ƒ
 S(   Ns   invalid provide mode Rw   (   t   problemsR:   R   t
   ValueErrorR*   t   commandsR"   t	   env_specst   command_for_nameR
   t   load_for_directoryR³   t   requirementst   check_statusR˜   RO   R®   (   R“   R¶   R!   R‘   R’   Rq   t   command_nameR   R   Ro   R   R(   R,   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   _internal_prepare_in_stagesË  s(    !'	c	         C@ sR   t  |  | | ƒ \ }	 }
 t |  d |	 d |
 d | d | d | d | d | d | ƒS(	   s  Get a chain of all steps needed to get a project ready to execute.

    This function does not immediately do anything; it returns a
    ``PrepareStage`` object which can be executed. Executing each
    stage may return a new stage, or may return ``None``. If a
    stage returns ``None``, preparation is done and the ``failed``
    property of the stage indicates whether it failed.

    Executing a stage may ask the user questions, may start
    services, run scripts, load configuration, install
    packages... it can do anything. Expect side effects.

    Before calling this function, command_name must be validated
    (must be in ``project.commands``, or be ``None``) and
    ``project.problems`` must be empty.

    Args:
        project (Project): the project
        environ (dict): the environment to start from (None to use os.environ)
        keep_going_until_success (bool): keep returning new stages until all requirements are met
        mode (str): One of ``PROVIDE_MODE_PRODUCTION``, ``PROVIDE_MODE_DEVELOPMENT``, ``PROVIDE_MODE_CHECK``
        provide_whitelist (iterable of str): ONLY call provide() for the listed env vars' requirements
        env_spec_name (str): the environment spec name to require, or None for default
        command_name (str): which named command to choose from the project, None for default
        command (ProjectCommand): command object, None for default
        extra_command_args (list of str): extra args for the command we prepare

    Returns:
        The first ``PrepareStage`` in the chain of steps.

    R¶   R!   R‘   R’   Rq   RÁ   R   R   (   R¸   RÂ   (   R“   R    R‘   R’   Rq   R"   RÁ   R   R   R¶   R!   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   prepare_in_stagesê  s    (c         C@ s   |  j  rˆ g  } x. |  j  D]# } | j | ƒ |  j j | ƒ q Wd } | j | ƒ |  j j | ƒ t d d d | d | d | d | ƒ Sd  Sd  S(   Ns   Unable to load the project.R   R/   R    R!   R"   (    (   R¹   RO   R|   R   R>   R*   (   R“   R    R!   t   would_have_used_env_specR/   t   problemR   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt$   _project_problems_to_prepare_failure   s    	c         C@ sŒ   | d  k	 r„ | |  j k r„ d | |  j j d j t |  j j ƒ  ƒ ƒ f } |  j j | ƒ t	 d d d | g d | d | d | ƒ Sd  Sd  S(	   Ns:   Command name '%s' is not in %s, these names were found: %ss   , R   R/   R    R!   R"   (    (
   R*   R»   t   project_filet   filenamet   joinR„   t   keysR|   R   R>   (   R“   RÁ   R    R!   RÄ   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt$   _prepare_failure_on_bad_command_name0  s    ."c         C@ sŒ   | d  k	 r„ | |  j k r„ d | |  j j d j t |  j j ƒ  ƒ ƒ f } |  j j | ƒ t	 d d d | g d | d | d | ƒ Sd  Sd  S(	   Ns>   Environment name '%s' is not in %s, these names were found: %ss   , R   R/   R    R!   R"   (    (
   R*   R¼   RÇ   RÈ   RÉ   R„   RÊ   R|   R   R>   (   R“   R"   R    R!   RÄ   R   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt%   _prepare_failure_on_bad_env_spec_name;  s    ."c         C@ sã   | d  k	 o | d  k	 s t ‚ | d  k r= |  j | ƒ } n  | j } | d  k r| | d  k rj |  j } q| |  j | ƒ } n  t |  | | | ƒ } | d  k r¸ t |  | | | | ƒ } n  | d  k rß t |  | | | | ƒ } n  | S(   N(	   R*   R:   R½   R"   RD   R˜   RÆ   RÌ   RË   (   R“   R"   RÁ   R   R    R!   RÄ   R$   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   _check_prepare_prerequisitesF  s     	c         C@ s‰   t  |  | | ƒ \ } }	 t |  | | | | |	 ƒ }
 |
 d	 k	 rC |
 St |  d | d |	 d t d | d | d | d | d | ƒ} t | ƒ S(
   s8  Prepare a project to run one of its commands.

    This method doesn't ask the user any questions, so the
    ``provide_mode`` lets you specify defaults suitable for a
    local workstation, a production deployment, or "check only"
    defaults ("check only" means don't do anything just check
    status).

    This method returns a result object. The result object has
    a ``failed`` property.  If the result is failed, the
    ``errors`` property has the errors.  If the result is not
    failed, the ``command_exec_info`` property has the stuff
    you need to run the project's default command, and the
    ``environ`` property has the updated environment. The
    passed-in ``environ`` is not modified in-place.

    You can update your original environment with
    ``result.update_environ()`` if you like, but it's probably
    a bad idea to modify ``os.environ`` in that way because
    the calling app won't want to have the project
    environment.

    The ``environ`` should usually be kept between
    preparations, starting out as ``os.environ`` but then
    being modified by the user.

    If the project has a non-empty ``problems`` attribute,
    this function returns the project problems inside a failed
    result. So ``project.problems`` does not need to be checked in
    advance.

    Args:
        project (Project): from the ``load_project`` method
        environ (dict): os.environ or the previously-prepared environ; not modified in-place
        mode (str): mode from ``PROVIDE_MODE_PRODUCTION``, ``PROVIDE_MODE_DEVELOPMENT``, ``PROVIDE_MODE_CHECK``
        provide_whitelist (iterable of str): ONLY call provide() for the listed env vars' requirements
        env_spec_name (str): the environment spec name to require, or None for default
        command_name (str): which named command to choose from the project, None for default
        command (ProjectCommand): command object, None for default
        extra_command_args (list): extra args to include in the returned command argv

    Returns:
        a ``PrepareResult`` instance, which has a ``failed`` flag

    R¶   R!   R‘   R’   Rq   RÁ   R   R   N(   R¸   RÍ   R*   RÂ   R<   t#   prepare_execute_without_interaction(   R“   R    R’   Rq   R"   RÁ   R   R   R¶   R!   t   failureRc   (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   prepare_without_interactionf  s    5	c         C@ sE   d } x8 |  d k	 r@ |  j ƒ  } |  j } | j r7 Pn  | }  q	 W| S(   sr   Advance through the PrepareStage without any interactivity.

    Returns:
       a ``PrepareResult`` instance
    N(   R*   RJ   RK   R$   (   Rc   RK   t
   next_stage(    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyRÎ   ¯  s    		
c         C@ s  |  j  rY g  } x. |  j  D]# } | j | ƒ |  j j | ƒ q Wt d t d d d | ƒ St j |  j ƒ } g  } g  } g  } x‰ | j	 D]~ }	 |	 j
 }
 t | |
 ƒ s« q‡ n  |	 j } | j |
 | j | | j |	 ƒ } | sø | j |
 ƒ | j | ƒ q‡ | j | ƒ q‡ W| s›t | ƒ d k rkx4 g  | D] }	 |	 j ^ q+D] } |  j j | ƒ q>Wt d t d d ƒ St | ƒ d k r…| d St d t d d ƒ Snð t | ƒ d k rÝx% | d j D] } |  j j | ƒ q»W| d Sg  | D]) }	 |	 j |	 j g g D] } | ^ qþqä} t g  | D] } t | t ƒ r| j ^ qƒ } x | D] } |  j j | ƒ qKWt d t d d	 d
 j | ƒ d | ƒ Sd S(   s  Attempt to clean up project-scoped resources allocated by prepare().

    This will retain any user configuration choices about how to
    provide requirements, but it stops project-scoped services.
    Global system services or other services potentially shared
    among projects will not be stopped.

    To stop a single service, use ``whitelist=["SERVICE_VARIABLE"]``.

    Args:
        project (Project): the project
        prepare_result (PrepareResult): result from the previous prepare
        whitelist (iterable of str or type): ONLY call shutdown commands for the listed env vars' requirements

    Returns:
        a ``Status`` instance
    t   successR\   s   Unable to load the project.R/   i   s   Success.i    s   Nothing to clean up.s   Failed to clean up %s.s   , N(   R¹   RO   R|   R   R   R<   R
   R¾   R³   R   R(   Rs   R}   t	   unprovideR    R!   RE   R‚   t   infoR@   R/   R„   R'   R   R)   RÉ   (   R“   t   prepare_resultt	   whitelistR/   RÅ   RC   t   failed_statusest   failed_requirementst   success_statusesR,   R(   R}   t   unprovide_statust   messageR   t
   all_errorst   reqt	   all_names(    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt	   unprepare¿  sN    			#61(?   R5   t
   __future__R    R   t   abcR   R   R±   R²   R   t#   anaconda_project.internal.metaclassR   t'   anaconda_project.internal.simple_statusR   t"   anaconda_project.internal.toposortR   t   anaconda_project.internalR   t$   anaconda_project.internal.py2_compatR	   t!   anaconda_project.local_state_fileR
   t   anaconda_project.provideR   R   t/   anaconda_project.requirements_registry.providerR   RF   R   R   R   t=   anaconda_project.requirements_registry.requirements.conda_envR   R   R   R7   R>   t   objectRA   RG   RT   RU   R`   Rf   Rp   Rs   R™   R¡   R£   R«   R®   R*   R¸   RÂ   R<   RÃ   RÆ   RË   RÌ   RÍ   RÐ   RÎ   Rß   (    (    (    s7   lib/python2.7/site-packages/anaconda_project/prepare.pyt   <module>   sn   	Y K	
C4	
			k	 	*	 	'	 .				!B	