
    cץ              	       `   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dl!m"Z" d Z# G d d ee                    Z$ G d de$          Z% G d de$          Z& G d de'          Z( G d d ee                    Z)d Z* G d de)          Z+ G d  d!e)          Z,d" Z-d# Z.d$ Z/d% Z0d& Z1d' Z2d( Z3d) Z4d5d*Z5d+ Z6dd,edddddd,f	d-Z7d. Z8d/ Z9d0 Z:d1 Z;dedddddd,fd2Z<d3 Z=d6d4Z>dS )7zPrepare a project to run.    )absolute_import)print_function)ABCMetaabstractmethodN)deepcopy)with_metaclass)SimpleStatustoposort_from_dependency_info)	conda_api)	is_string)LocalStateFile)_all_provide_modesPROVIDE_MODE_DEVELOPMENT)ProvideContext)RequirementEnvVarRequirementUserConfigOverrides)CondaEnvRequirement)_remove_env_pathc                 d    |                                 D ]\  }}|| vs| |         |k    r|| |<   dS )z}Overwrite ``environ`` with any additions from the prepared environ.

    Does not remove any variables from ``environ``.
    N)items)destsrckeyvalues       8lib/python3.11/site-packages/anaconda_project/prepare.py_update_environr      sO     iikk  
Ud? 	d3i50 	DI     c                       e Zd 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dS )PrepareResultzEAbstract class describing the result of preparing the project to run.c                 X    t          |          | _        || _        || _        || _        dS )z$Construct an abstract PrepareResult.N)tuple	_statuses_environ
_overrides_env_spec_name)selfstatusesenviron	overridesenv_spec_names        r   __init__zPrepareResult.__init__+   s+    x#+r   c                     | j          S zTrue if we were successful.)failedr(   s    r   __bool__zPrepareResult.__bool__2   s    ;r   c                 *    |                                  S r/   )r2   r1   s    r   __nonzero__zPrepareResult.__nonzero__6   s    }}r   c                     dS )zTrue 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 r1   s    r   r0   zPrepareResult.failed:   	     	r   c                     | j         S )zGet latest RequirementStatus if available.

        If we failed before we even checked statuses, this will be an empty list.
        )r$   r1   s    r   r)   zPrepareResult.statusesD   s     ~r   c                     | j         D ]Y}t          |          r/t          |j        t                    r|j        j        |k    r|c S @t          |j        |          r|c S ZdS )z>Get status for the given env var or class, or None if unknown.N)r)   r   
isinstancerequirementr   env_var)r(   env_var_or_classstatuss      r   
status_forzPrepareResult.status_forL   s    m 	 	F)** f02CDD "%-1AA"!MMMF.0@AA tr   c                     | j         S )zComputed environment variables for the project.

        If ``failed`` is True, this environ dict may be unmodified
        from the original provided to the prepare function.
        )r%   r1   s    r   r*   zPrepareResult.environW   s     }r   c                     | j         S )z.Override object which was passed to prepare().r&   r1   s    r   r+   zPrepareResult.overrides`   s     r   c                     t                      )zGet lines of error output.)NotImplementedErrorr1   s    r   errorszPrepareResult.errorse   s     "###r   c                     | j         S )a  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'   r1   s    r   r,   zPrepareResult.env_spec_namej   s     ""r   c                     |                      t                    }|dS |j        j        }| j                            |d          S )z<The prefix of the prepared env, or None if none was created.N)r?   r   r;   r<   r%   get)r(   r>   varnames      r   
env_prefixzPrepareResult.env_prefixw   sF     !455 	4$,}  $///r   N)__name__
__module____qualname____doc__r-   r2   r4   propertyr   r0   r)   r?   r*   r+   rE   r,   rJ   r6   r   r   r!   r!   )   s       OO, , ,       ^ X   X	 	 	   X   X $ $ X$ 
# 
# X
# 0 0 X0 0 0r   r!   c                   j     e Zd ZdZ fdZed             Zed             Zed             Zd Z	 xZ
S )PrepareSuccesszGClass describing the successful result of preparing the project to run.c                 ~    t          t          |                               ||||           || _        | j        J dS )zAConstruct a PrepareSuccess indicating a successful prepare stage.N)superrQ   r-   _command_exec_infor,   )r(   r)   command_exec_infor*   r+   r,   	__class__s         r   r-   zPrepareSuccess.__init__   sD    nd##,,Xw	=YYY"3!-----r   c                     dS )zGet False for PrepareSuccess.Fr6   r1   s    r   r0   zPrepareSuccess.failed   s	     ur   c                     | j         S )z7``CommandExecInfo`` instance if available, None if not.)rT   r1   s    r   rU   z PrepareSuccess.command_exec_info   s     &&r   c                     g S )zGet empty list of errors.r6   r1   s    r   rE   zPrepareSuccess.errors   s	     	r   c                 0    t          || j                   dS )zOverwrite ``environ`` with any additions from the prepared environ.

        Does not remove any variables from ``environ``.
        N)r   r%   )r(   r*   s     r   update_environzPrepareSuccess.update_environ   s    
 	/////r   )rK   rL   rM   rN   r-   rO   r0   rU   rE   r[   __classcell__rV   s   @r   rQ   rQ      s        QQ. . . . .   X ' ' X'   X0 0 0 0 0 0 0r   rQ   c                   P     e Zd ZdZd fd	Zed             Zed             Z xZS )PrepareFailurezCClass describing the failed result of preparing the project to run.Nc                 l    t          t          |                               ||||           || _        dS )z=Construct a PrepareFailure indicating a failed prepare stage.N)rS   r_   r-   _errors)r(   r)   rE   r*   r+   r,   rV   s         r   r-   zPrepareFailure.__init__   s2    nd##,,Xw	=YYYr   c                     dS )zGet True for PrepareFailure.Tr6   r1   s    r   r0   zPrepareFailure.failed   s	     tr   c                     | j         S )zGet non-empty list of errors.)ra   r1   s    r   rE   zPrepareFailure.errors   s     |r   N)	rK   rL   rM   rN   r-   rO   r0   rE   r\   r]   s   @r   r_   r_      sy        MM     
   X   X    r   r_   c                       e Zd ZdZd ZdS )ConfigurePrepareContextz(Information needed to configure a stage.c                     || _         || _        || _        || _        || _        t          |          dk    rddlm} t          |d         |          sJ dS dS )z$Construct a ConfigurePrepareContext.r   )RequirementStatusN)	r*   local_state_filedefault_env_spec_namer+   r)   len2anaconda_project.requirements_registry.requirementrh   r:   )r(   r*   ri   rj   r+   r)   rh   s          r   r-   z ConfigurePrepareContext.__init__   sw     0%:"" x==1 	>\\\\\\hqk+<=====	> 	>==r   N)rK   rL   rM   rN   r-   r6   r   r   rf   rf      s)        22	> 	> 	> 	> 	>r   rf   c                   H   e Zd 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dS )PrepareStagez*A step in the project preparation process.c                     dS )zHGet a user-visible description of what happens if this step is executed.Nr6   r1   s    r   description_of_actionz"PrepareStage.description_of_action   	     	r   c                     dS )z>Synonym for result.failed, only available after ``execute()``.Nr6   r1   s    r   r0   zPrepareStage.failed   rq   r   c                     dS )zGet a ``ConfigurePrepareContext`` or None if no configuration is needed.

        Configuration should be done before execute().

        Returns:
          a ``ConfigurePrepareContext`` or None
        Nr6   r1   s    r   	configurezPrepareStage.configure   	     	r   c                     dS )zGRun this step and return a new stage, or None if we are done or failed.Nr6   r1   s    r   executezPrepareStage.execute   s	     	r   c                     dS )zHThe ``PrepareResult`` (only available if ``execute()`` has been called).Nr6   r1   s    r   resultzPrepareStage.result   rq   r   c                     dS )zZThe latest environment variables (from the result if any, otherwise the pre-execute ones).Nr6   r1   s    r   r*   zPrepareStage.environ   rq   r   c                     dS )zUser overrides.Nr6   r1   s    r   r+   zPrepareStage.overrides   rq   r   c                     dS )a	  ``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.
        Nr6   r1   s    r   statuses_before_executez$PrepareStage.statuses_before_execute   ru   r   c                     dS )z``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()``.
        Nr6   r1   s    r   statuses_after_executez#PrepareStage.statuses_after_execute   r7   r   N)rK   rL   rM   rN   rO   r   rp   r0   rt   rw   ry   r*   r+   r}   r   r6   r   r   rn   rn      sQ       44  ^ X   ^ X   ^   ^   ^ X   ^ X   ^ X   ^ X   ^ X  r   rn   c                     t                      }|D ]}|||j        <   g }| D ]0}|                    |                    |j        |                     1|S rd   )dictr;   appendrH   )old_statusesrechecked_statuses
new_by_reqr>   updateds        r   _refresh_status_listr   
  sk    J$ 0 0)/
6%&&G C Cz~~f&8&AABBBBNr   c                       e Zd 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dS )_FunctionPrepareStagez^A stage chain where the description and the execute function are passed in to the constructor.Nc                     t          |t                    sJ |t          |t                    sJ || _        || _        d | _        d | _        || _        || _        || _	        || _
        d S rd   )r:   r   rf   r%   r&   _result_statuses_after_execute_description_statuses_before_execute_execute_config_context)r(   r*   r+   descriptionr)   rw   config_contexts          r   r-   z_FunctionPrepareStage.__init__  sv    '4(((((\ND[)\)\\\\#'+$'(0%-r   c                     | j         S rd   )r   r1   s    r   rp   z+_FunctionPrepareStage.description_of_action'  s      r   c                     | j         j        S rd   )ry   r0   r1   s    r   r0   z_FunctionPrepareStage.failed+      {!!r   c                     | j         S rd   )r   r1   s    r   rt   z_FunctionPrepareStage.configure/  s    ##r   c                 ,    |                      |           S rd   )r   r1   s    r   rw   z_FunctionPrepareStage.execute2  s    }}T"""r   c                 <    | j         t          d          | j         S )Nz5result property isn't available until after execute())r   RuntimeErrorr1   s    r   ry   z_FunctionPrepareStage.result5  s$    < 	XVWWW|r   c                 6    | j         | j        S | j        j        S rd   )r   r%   ry   r*   r1   s    r   r*   z_FunctionPrepareStage.environ;  s    < 	'= ;&&r   c                     | j         S rd   rB   r1   s    r   r+   z_FunctionPrepareStage.overridesB  s
    r   c                     | j         S rd   )r   r1   s    r   r}   z-_FunctionPrepareStage.statuses_before_executeF  s    ,,r   c                 <    | j         t          d          | j         S )Nz<statuses_after_execute isn't available until after execute())r   r   r1   s    r   r   z,_FunctionPrepareStage.statuses_after_executeJ  s&    ' 	_]^^^++r   c                 P    |J t          | j        |          | _        || _        d S rd   )r   r   r   r   )r(   ry   r   s      r   
set_resultz _FunctionPrepareStage.set_resultP  s/    !!!';D<Y[m'n'n$r   rd   )rK   rL   rM   rN   r-   rO   rp   r0   rt   rw   ry   r*   r+   r}   r   r   r6   r   r   r   r     s       hh. . . ." ! ! X! " " X"$ $ $# # #   X
 ' ' X'   X - - X- , , X,
    r   r   c                       e Zd 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dS )_AndThenPrepareStagezQA stage chain which runs an ``and_then`` function after it executes successfully.c                 "    || _         || _        d S rd   )_stage	_and_then)r(   stageand_thens      r   r-   z_AndThenPrepareStage.__init__X  s    !r   c                     | j         j        S rd   )r   rp   r1   s    r   rp   z*_AndThenPrepareStage.description_of_action_  s    {00r   c                     | j         j        S rd   )r   r0   r1   s    r   r0   z_AndThenPrepareStage.failedc  r   r   c                 4    | j                                         S rd   )r   rt   r1   s    r   rt   z_AndThenPrepareStage.configureg  s    {$$&&&r   c                     | j                                         }|-| j         j        rd S |                     | j         j                  S t          || j                  S rd   )r   rw   r0   r   r   r   )r(   nexts     r   rw   z_AndThenPrepareStage.executej  sY    {""$$ 	>{! Jt~~dk&HIII'dn===r   c                     | j         j        S rd   )r   ry   r1   s    r   ry   z_AndThenPrepareStage.resultt  r   r   c                     | j         j        S rd   )r   r*   r1   s    r   r*   z_AndThenPrepareStage.environx  s    {""r   c                     | j         j        S rd   )r   r+   r1   s    r   r+   z_AndThenPrepareStage.overrides|  s    {$$r   c                     | j         j        S rd   )r   r}   r1   s    r   r}   z,_AndThenPrepareStage.statuses_before_execute  s    {22r   c                     | j         j        S rd   )r   r   r1   s    r   r   z+_AndThenPrepareStage.statuses_after_execute  s    {11r   N)rK   rL   rM   rN   r-   rO   rp   r0   rt   rw   ry   r*   r+   r}   r   r6   r   r   r   r   V  s       [[" " " 1 1 X1 " " X"' ' '> > > " " X" # # X# % % X% 3 3 X3 2 2 X2 2 2r   r   c                 *    | J t          | |          S )zRun 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.
    )r   )r   r   s     r   _after_stage_successr     s      x000r   c                 D     d }fd} fd}t          ||||          S )Nc                 H    t          | j        d          sJ | j        j        S Nr<   )hasattrr;   r<   r>   s    r   get_node_keyz$_sort_statuses.<locals>.get_node_key  s)     v)955555!))r   c                 j    t                      } |           D ]}|                    |           |S rd   )setadd)r>   config_keysr<   missing_vars_getters      r   get_dependency_keysz+_sort_statuses.<locals>.get_dependency_keys  sA    ee**622 	% 	%GOOG$$$$r   c                     | v S rd   r6   )r   r*   s    r   can_ignore_dependency_on_keyz4_sort_statuses.<locals>.can_ignore_dependency_on_key  s     g~r   r
   )r*   local_stater)   r   r   r   r   s   `  `   r   _sort_statusesr     s]    * * *         )<ATVrsssr   c                     | dS | D ]e}t          |t                    r||u r dS t          |          r$t          |t                    r|j        |k    r dS Rt          ||          r dS fdS )NTF)r:   r   r   r   r<   )provide_whitelistr;   env_var_or_class_or_reqs      r   _in_provide_whitelistr     s     t#4 	 	-{;; 	55 tt.// 	+'899 k>QUl>l tt+'>?? tt5r   c                     	
                       	          	
 fdfd           S )Nc                    d }t          |          }g }|D ]-}|                    |                                         .g }d}t                      }|D ]z}t	          |j                  s|j        r d}t          |j                  }|j	        
                    |j        |          }	|                    |	j                   |	||<   {|rI|}
g }|
D ]B}|                    |                    |                    |                               Cd}|D ]}|s|                    d                    |j                             j                            |d                    |                    d                    |j        	                     j                            |d                    d}t#          |          }d }|D ]}|j        |j        }|r=|                     t)          |||
          |           r | j        |          S d S d }n                              }|                     t/          |||          |           d S )Nc                     | j         j        S rd   )analysismissing_env_vars_to_provider   s    r   get_missing_to_providezM_configure_and_provide.<locals>.provide_stage.<locals>.get_missing_to_provide  s    ?>>r   FTlatest_provide_resultzBmissing requirement to run this project: {requirement.description})r;   z  {why_not})why_notr)   rE   r*   r+   r,   )
extra_args)r)   rU   r*   r+   r,   )r   r   recheckr   r   r;   has_been_providedr   frontendproviderprovideextendrE   rH   formaterrorstatus_descriptionr   r,   r   r_   r   exec_info_for_environmentrQ   )r   r   sorted	recheckedr>   rE   did_any_providingresults_by_statuscontextry   oldr0   result_statusescurrent_env_spec_name	exec_info_start_overall_statusescommandrj   r*   extra_command_argskeep_going_until_successr   moder+   projectr   r)   s                  r   provide_stagez-_configure_and_provide.<locals>.provide_stage  se   	? 	? 	?  h@VWW 	 	e 	eFV^^G[BWYbccdddd! FF 
	3 
	3F():F<NOO 	3) 3$(!(+?TV\^bdkdtuu001CWMMfm,,,,2!&)) 		YCI Y Y  NN7#.#8#,9J9N9Nv9V9V	 # X XY Y Y Y  	 	F bii & 2 j 4 4 5 5 5 &&vbz222m226;T2UUVVV &&vbz222.|YGG $% 		= 		=F# = )/(<% 	&,'.)2-B	D D D FOP P P ( "{5#?KKKt f 		#==gRd=ee	1:'.)2-B	D D D FOP P P 4r   c                 T    t          |          }t          d| |          S )N)r*   ri   rj   r+   r)   zSet up project.)rf   r   )updated_all_statusesupdated_statusesconfigure_contextrj   r*   r   r+   r   s      r   r   z+_configure_and_provide.<locals>._start_over  sM    3GEPJ_>G=M	O O O
 %Wi9JL`bo%68 8 	8r   )!default_env_spec_name_for_command)r   r*   r   r)   r   r   r   r   r+   r   r   r   rj   r   s   ```````````@@@r   _configure_and_provider     s     $EEgNNT T T T T T T T T T T T T T T T Tl8 8 8 8 8 8 8 8 8 ;|X...r   c                    d }t          | |||          }g }g }|                                 |ru|                                }|j                            |j        | |          }t          |          dk    r|                    |           n|                    |           |u|                                 |                    |           ||fS )Nc                     | j         j        S rd   )r   missing_env_vars_to_configurer   s    r   get_missing_to_configurezE_partition_first_group_to_configure.<locals>.get_missing_to_configure$  s    <<r   r   )	r   reversepopr   r   r;   rk   r   r   )	r*   r   r)   r   r   headtailr>   missing_varss	            r   #_partition_first_group_to_configurer   #  s    = = = G[(<TUUF DD
NN
 	 DDVEWY`bmnn|q  	 KKKK  	  NNKK$<r   c           
      F   	
 t          |          \  }	
 f
d}t          |          dk    r:t                    dk    r'	
 f
d}t           ||          |          S t          |          dk    r ||          S J d            )Nc                 6   
 t          	| 
          S rd   )r   )r)   r   r   r*   r   r   r   r   r+   r   r   s    r   _stages_forz2_process_requirement_statuses.<locals>._stages_forP  s2    %gwX|]u&*,=y'Seg g 	gr   r   c                 V   
 t          |           }t          	|| 
          S rd   )r   _process_requirement_statuses)r   r   r   r*   r   r   r   r   r+   r   r   	remainings     r   process_remainingz8_process_requirement_statuses.<locals>.process_remainingV  sE    *96JKKG0';PWYm1I4Qbdmov1CE E Er   Fz'This code should not be reachable, bug!)r   rk   r   )r   r*   r   current_statusesr   r   r   r   r+   r   r   initialr   r  r  s   ``` ```````   @r   r  r  C  sG    ?wUeffWig g g g g g g g g g g g g g 7||a &C	NNQ. &	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E $KK$8$8:KLLL	W	 	&{7### 	@????r   c                    t                      }|D ]-}t          |j        d          sJ |j        ||j        j        <   .t	                      }|D ]j}|                    |j                            |j        ||                     |                    |j                            |j        ||                     k|D ]}	|	|v sJ 	d S r   )	r   r   r;   r<   r   updater   r   r   )
r   r*   r   r+   r   r)   
by_env_varr>   needed_env_varsr<   s
             r   '_assert_no_missing_env_var_requirementsr  m  s    J D D v)955555171C
6%-..eeO v vvLLVM_ahjuvvwwwvJJ6K]_fhsttuuuu # % %*$$$$$% %r   c
                 l    d|v sJ t          | |||||           t          | ||||||||||	          }
|
S )NPROJECT_DIR)r  r  )r   r*   r   r)   r   r   r   r+   r   r   first_stages              r   _first_stager    sb    G####+GWk9V]_ghhh/+xYa0H$Paclnu0BD DK r   c                     |t           j        }d|v sJ t          |                                          }| j        |d<   t          j        |          }t          j        |           t          ||          }||fS )NPATHr  )r,   inherited_env)	osr*   r   copydirectory_pathr   environ_get_prefixenviron_delete_prefix_variablesr   )r   r*   r,   environ_copyexisting_env_prefixr+   s         r   _prepare_environ_and_overridesr    s     *W( GLLNN++L #*"8L $6|DD-l;;;#-ObcccI)$$r   c
                 v   | j         rJ |t          vrt          d|z             ||J ||| j        v s|dk    sJ |j        |j        | j        v sJ ||                     |          }|                     |          }
| j        }t          j
        |          }|	r7|j        p|
}t          | j        |                             |          |           g }|                     |j                  D ]1}|                    |||
|d           }|                    |           2t!          | |||||||||
  
        S )Nzinvalid provide mode defaultr   )problemsr   
ValueErrorcommandsr,   	env_specscommand_for_namer   r  r   load_for_directoryr   pathrequirementscheck_statusr   r  )r   r  r+   r   r   r   command_namer   r   refreshdefault_env_nameour_rootr   env_namer)   r;   r>   s                    r   _internal_prepare_in_stagesr+    s   %% 9047888AWAAAdLG4D$Dd,ZcJcddd"Zi.EIZ.ZZZZ 9**<88 @@II%H 3H==K O *>.>*8499(CCXNNNH++I,CDD    )),*5*:*3@D	 * F F
 	{HF^`dfw!7,>@ @ @r   Fc
                 \    t          | ||          \  }
}t          | |
||||||||	
  
        S )a[  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
        refresh (bool): do a full reinstall of the environment

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

    	r  r+   r   r   r   r&  r   r   r'  )r  r+  )r   r*   r   r   r   r,   r&  r   r   r'  r  r+   s               r   prepare_in_stagesr.    sP    T !?wQ^ _ _\9&w4@1:@X,09J4@/6:L/6	8 	8 	8 	8r   c                    | j         rg }| j         D ]1}|                    |           | j                            |           2d}|                    |           | j                            |           t	          d||||          S d S )NUnable to load the project.r6   r   )r  r   r   r   r_   )r   r*   r+   would_have_used_env_specrE   problemr   s          r   $_project_problems_to_prepare_failurer3     s     ' 	, 	,GMM'"""""7++++-eu%%%r%+&-(1,D	F F F 	F tr   c                 :   |dk    r| j         j        }d S ||| j        vr{d|d| j        j        dd                    t          | j                                                            }| j        	                    |           t          d|g|||          S d S )Nr  zCommand name '' is not in , these names were found: , r6   r   )default_commandnamer  project_filefilenamejoinr   keysr   r   r_   )r   r&  r*   r+   r1  r   s         r   $_prepare_failure_on_bad_command_namer>  3  s    y  .3	 
l':J&J 
 
,, 4 = = =tyyPWP`PePePgPgIhIh?i?i?iku%%%r&+W&-(1,D	F F F 	F tr   c                    ||| j         vr{d|d| j        j        dd                    t	          | j                                                             }| j                            |           t          d|g|||          S d S )NzEnvironment name 'r5  r6  r7  r6   r   )	r   r:  r;  r<  r   r=  r   r   r_   )r   r,   r*   r+   r1  r   s         r   %_prepare_failure_on_bad_env_spec_namer@  C  s     
]':K%K 
 
--!5!>!>!>		&QXQbQgQgQiQiJjJj@k@k@kmu%%%r&+W&-(1,D	F F F 	F tr   c                    ||J ||                      |          }|j        }||| j        }n|                     |          }t	          | |||          }|t          | ||||          }|t          | ||||          }|S rd   )r!  r,   rj   r   r3  r@  r>  )r   r,   r&  r   r*   r+   r1  r0   s           r   _check_prepare_prerequisitesrB  Q  s    AWAAA 9**<88  )6 Z 	Z'.'D$$'.'P'PQX'Y'Y$1'7IOghhF Q6wwXa7OQ Q P5g|WV_6NP PMr   c	                     t          | ||          \  }	}
t          | ||||	|
          }||S t          | |	|
d||||||
  
        }t          |          S )a8  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

    NFr-  )r  rB  r+  #prepare_execute_without_interaction)r   r*   r   r   r,   r&  r   r   r'  r  r+   failurer   s                r   prepare_without_interactionrF  q  s    l !?wQ^ _ _\9*7M<QXZfhqrrG '5A2;AF-1:K5A07;M07	9 	9 	9E /u555r   c                 \    d}| '|                                  }| j        }|j        rn|} | '|S )zrAdvance through the PrepareStage without any interactivity.

    Returns:
       a ``PrepareResult`` instance
    N)rw   ry   r0   )r   ry   
next_stages      r   rD  rD    sH     F
 ]]__
= 	   Mr   c                 \   | j         rMg }| j         D ]1}|                    |           | j                            |           2t	          dd|          S t          j        | j                  }g }g }g }|j        D ]}	|	j	        }
t          ||
          s|	j        }|                    |
|j        ||j        |	          }|s+|                    |
           |                    |           q|                    |           |syt          |          dk    r:d |D             D ]}| j                            |           t	          dd          S t          |          d	k    r|d	         S t	          dd
          S t          |          dk    r2|d	         j        D ]}| j                            |           |d	         S d |D             }t%          d |D                       }|D ]}| j                            |           t	          ddd                    |          z  |          S )a  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
    Fr0  )successr   rE      c                     g | ]	}|j         
S r6   )r   ).0r>   s     r   
<listcomp>zunprepare.<locals>.<listcomp>  s    UUU&F5UUUr   TzSuccess.)rJ  r   r   zNothing to clean up.c                 2    g | ]}|j         |j        gz   }|S r6   )rE   r   )rM  r>   r   s      r   rN  zunprepare.<locals>.<listcomp>  s*    uuuY_YrXsHseeuuur   c                 F    g | ]}t          |t                    |j        S r6   )r:   r   r<   )rM  reqs     r   rN  zunprepare.<locals>.<listcomp>  s+    mmmC*UXZkJlJlmCKmmmr   zFailed to clean up %s.r7  )r  r   r   r   r	   r   r"  r  r)   r;   r   r   	unprovider*   r+   rk   inforE   r   r<  )r   prepare_result	whitelistrE   r2  ri   failed_statusesfailed_requirementssuccess_statusesr>   r;   r   unprovide_statusmessager   
all_errors	all_namess                    r   	unpreparer]    s   $  e' 	, 	,GMM'"""""7++++E7T]cdddd%89OPP O ) 6 6($Y<< 	?#--k>;QSc.<.FP P 	6&&{333""#34444##$45555 /  1$ 	RUUDTUUU / / %%g....*EEEE!""Q& 	R#A&&:PQQQQ	_			" /$Q'. 	* 	*E""5))))q!!uu/uuu
mm3Fmmmnn	 	* 	*E""5))))E)ADIIiDXDX)X#-/ / / 	/r   )NNrd   )?rN   
__future__r   r   abcr   r   r  r  r   #anaconda_project.internal.metaclassr   'anaconda_project.internal.simple_statusr	   "anaconda_project.internal.toposortr   anaconda_project.internalr   $anaconda_project.internal.py2_compatr   !anaconda_project.local_state_filer   anaconda_project.provider   r   /anaconda_project.requirements_registry.providerr   rl   r   r   r   =anaconda_project.requirements_registry.requirements.conda_envr   :anaconda_project.requirements_registry.providers.conda_envr   r   r!   rQ   r_   objectrf   rn   r   r   r   r   r   r   r   r   r  r  r  r  r+  r.  r3  r>  r@  rB  rF  rD  r]  r6   r   r   <module>rk     s'      & & & & & & % % % % % % ' ' ' ' ' ' ' ' 				       > > > > > > @ @ @ @ @ @ L L L L L L / / / / / / : : : : : : < < < < < < S S S S S S S S J J J J J J r r r r r r r r r r ] ] ] ] ] ] W W W W W W	 	 	U0 U0 U0 U0 U0NN7++ U0 U0 U0p0 0 0 0 0] 0 0 0>    ]   $> > > > >f > > >C C C C C>>'** C C CT  ? ? ? ? ?L ? ? ?D02 02 02 02 02< 02 02 02f1 1 1t t t.  $d/ d/ d/N  @$& $& $&T% % %@
 
 
$% $% $% $%N$@ $@ $@P #/43(,$(#'")-#58 58 58 58p  &       B )-%=26.2-1(,37(-G6 G6 G6 G6T   C/ C/ C/ C/ C/ C/r   