
    c6                         d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ  G d d	e          Z G d
 de          Z G d d e	e                    ZdZ G d de          ZdS )z&Types related to project requirements.    )absolute_import)ABCMetaabstractmethod)deepcopy)with_metaclass)	is_string)Statusc                   f    e Zd ZdZddZed             Zed             Zej        d             ZdS )UserConfigOverrideszCClass containing user-forced configuration for the prepare process.Nc                 "    || _         || _        dS )z:Construct a set of user overrides for the prepare process.N)_inherited_env_env_spec_name)selfinherited_envenv_spec_names      Rlib/python3.11/site-packages/anaconda_project/requirements_registry/requirement.py__init__zUserConfigOverrides.__init__   s    ++    c                     | j         S )zWThe user-specified name of the conda environment spec to use, or None if not specified.r   r   s    r   r   z!UserConfigOverrides.env_spec_name        ""r   c                     | j         S )zBThe environment we started with before we ran the prepare process.)r   r   s    r   r   z!UserConfigOverrides.inherited_env   r   r   c                     || _         dS )z+Change the conda environment name override.Nr   r   values     r   r   z!UserConfigOverrides.env_spec_name$   s     $r   NN)	__name__
__module____qualname____doc__r   propertyr   r   setter r   r   r   r      s        MM, , , ,
 # # X# # # X# $ $ $ $ $r   r   c                       e Zd ZdZd Zd 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ddZdS )RequirementStatuszClass describing the status of a requirement.

    Values of this class are immutable; to get updated status, you
    would call ``recheck()`` to get a new status.

    c                 h    || _         || _        || _        || _        || _        || _        || _        dS )z(Construct an abstract RequirementStatus.N)_requirement_has_been_provided_status_description	_provider	_analysis_latest_provide_resultr   )r   requirementhas_been_providedstatus_descriptionprovideranalysislatest_provide_resultr   s           r   r   zRequirementStatus.__init__1   s@     ("3#5 !!&;#+r   c                 8    d| j         d| j        d| j        dS )zRepr of the status.zRequirementStatus(,))r/   r0   r.   r   s    r   __repr__zRequirementStatus.__repr__<   s-     040F0F0FH_H_H_aeaqaqaqrrr   c                     | j         S zTrue if the requirement is met.)r/   r   s    r   __bool__zRequirementStatus.__bool__@   s    %%r   c                 *    |                                  S r9   )r:   r   s    r   __nonzero__zRequirementStatus.__nonzero__D   s    }}r   c                     | j         S )z)Get the requirement we are the status of.)r(   r   s    r   r.   zRequirementStatus.requirementH   s       r   c                     | j         S )z)Get True if the requirement has been met.)r)   r   s    r   r/   z#RequirementStatus.has_been_providedM   s     &&r   c                     | j         S )zNGet a description of how the requirement has been met (or why it hasn't been).)r*   r   s    r   r0   z$RequirementStatus.status_descriptionR   s     ''r   c                     | j         S )z&Get the provider for this requirement.)r+   r   s    r   r1   zRequirementStatus.providerW        ~r   c                     | j         S )z*Get the provider's analysis of the status.)r,   r   s    r   r2   zRequirementStatus.analysis\   rA   r   c                     | j         S )zDGet the latest ``ProvideResult`` or None if we haven't provided yet.)r-   r   s    r   r3   z'RequirementStatus.latest_provide_resulta   s     **r   c                 ,    | j         g S | j         j        S )z_Get error logs relevant to the status, from either checking status or attempting to provide it.)r3   errorsr   s    r   rE   zRequirementStatus.errorsf   s      % 	5I-44r   c                     | j         S )zZGet the env spec name used to meet the requirement, None if not a ``CondaEnvRequirement``.r   r   s    r   r   zRequirementStatus.env_spec_namen   r   r   Nc                 P    || j         }| j                            |||||          S )zGet a new ``RequirementStatus`` reflecting the current state.

        This calls ``Requirement.check_status()`` which can do network and filesystem IO,
        so be cautious about where you call it.
        )r-   r.   check_statusr   environlocal_state_filedefault_env_spec_name	overridesr3   s         r   recheckzRequirementStatus.rechecks   sB     ! 	@$($?!,,W6FH]_h-BD D 	Dr   r   )r   r   r    r!   r   r7   r:   r<   r"   r.   r/   r0   r1   r2   r3   rE   r   rN   r$   r   r   r&   r&   *   sO        	, 	, 	,s s s& & &   ! ! X! ' ' X' ( ( X(   X   X + + X+ 5 5 X5 # # X#	D 	D 	D 	D 	D 	Dr   r&   c                       e Zd ZdZd Zeed                         Zd Zeed                         Z	ed             Z
d Zd Zedd
            Zd	S )RequirementaT  Describes a requirement of the project (from the project config).

    Note that this is not specifically a package requirement;
    this class is more general, it can be a requirement for any
    condition at all (that a service is running, that a file
    exists, or even that a package is intalled - anything you can
    think of).

    c                 @   || _         |t                      | _        dS t          |          | _        d| j        v r^t	          | j        d                   sFt          | j        d         t                    s(t          | j        d                   | j        d<   dS dS dS dS )zConstruct a Requirement.

        Args:
            registry (RequirementsRegistry): the plugin registry we came from
            options (dict): dict of requirement options from the project config
        Ndefault)registrydictoptionsr   r   
isinstancestr)r   rS   rU   s      r   r   zRequirement.__init__   s     ! 		G66DLLL#G,,DL DL( G)DL<S2T2T G5?Y@WY]5^5^G*-dl9.E*F*FY'''G G G G G Gr   c                     dS )z-Human-readable short name of the requirement.Nr$   r   s    r   titlezRequirement.title   	     	r   c                 2    d| j         v r| j         d         S |S )z=Use this in subclasses to implement the description property.description)rU   )r   rR   s     r   _descriptionzRequirement._description   s#    DL( 	<..Nr   c                     dS )zFHuman-readable about-one-sentence hint or tooltip for the requirement.Nr$   r   s    r   r\   zRequirement.description   rZ   r   c                     t                      S )zPSet of ignore patterns for files this requirement's provider might autogenerate.)setr   s    r   ignore_patternszRequirement.ignore_patterns   s     uur   c	           	          | j                             |          }	|	                    | ||||          }
|
j                            dd           }t          | |||	|
||          S Nenv_name)r/   r0   r1   r2   r3   r   rS   find_provider_by_class_nameanalyzeconfiggetr&   )r   rJ   rK   rL   rM   r3   r/   r0   provider_class_namer1   r2   r   s               r   _create_statuszRequirement._create_status   sx    =<<=PQQ##D'3CEZ\eff ++J== 3D4F*2*27L/<> > > 	>r   c           	          | j                             |          }|                    | ||||          }	 ||||	          \  }
}|	j                            dd           }t          | |
|||	||          S rc   re   )r   rJ   rK   rL   rM   r3   rj   status_getterr1   r2   r/   r0   r   s                r   _create_status_from_analysisz(Requirement._create_status_from_analysis   s    =<<=PQQ##D'3CEZ\eff2?-IY[c2d2d/	. ++J== 3D4F*2*27L/<> > > 	>r   Nc                     dS )a  Check on the requirement and return a ``RequirementStatus`` with the current status.

        This may attempt to talk to servers, check that files
        exist on disk, and other work of that nature to verify the
        requirement's status, so be careful about when and how
        often this gets called.

        Args:
            environ (dict): use this rather than the system environment directly
            local_state_file (LocalStateFile): project local state
            default_env_spec_name (str): fallback env spec name
            overrides (UserConfigOverrides): user-supplied forced choices
            latest_provide_result (ProvideResult): most recent result of ``provide()`` or None

        Returns:
            a ``RequirementStatus``

        Nr$   rI   s         r   rH   zRequirement.check_status   s	    ( 	r   N)r   r   r    r!   r   r"   r   rY   r]   r\   ra   rk   rn   rH   r$   r   r   rP   rP      s         G G G(   ^ X     ^ X   X> > >> > >    ^  r   rP   )	_PASSWORD_SECRET_KEY_SECRETc                        e Zd ZdZed             Zd fd	Zd Zed             Z	ed             Z
ed             Zed	             Zd
 Zd Zd ZddZ xZS )EnvVarRequirementz9A requirement that a certain environment variable be set.c                 h   t          |t                    sJ |                    dd           }|d}nHt          |t                    rd}n0t	          |          st          |t
          t          f          rd}nd}d|v r||d= |rdS |                    d                    ||                     dS )NrR   TFzVdefault value for variable {env_var} must be null, a string, or a number, not {value}.env_varr   )	rV   rT   ri   boolr   intfloatappendformat)r   rU   rx   problemsraw_defaultgood_defaults         r   _parse_defaultz EnvVarRequirement._parse_default   s    7D))***kk)T22 	!LLT** 	! LL{## 	!z+U|'L'L 	!LL L 	#K 	#	" 	4OOhoo#; p 8 89 9 9 5r   Nc                 p    t          t          |                               ||           |J || _        dS )zPConstruct an EnvVarRequirement for the given ``env_var`` with the given options.N)superru   r   rx   )r   rS   rx   rU   	__class__s       r   r   zEnvVarRequirement.__init__
  s;    &&//'BBB"""r   c                 0    | j         j        d| j        dS )z!Custom repr of EnvVarRequirement.z
(env_var='z'))r   r   rx   r   s    r   r7   zEnvVarRequirement.__repr__  s    %)^%<%<%<dlllKKr   c                     | j         S )zOverride superclass title.rx   r   s    r   rY   zEnvVarRequirement.title  s     |r   c                 <    |                      d| j        z            S )z Override superclass description.z$%s environment variable must be set.)r]   rx   r   s    r   r\   zEnvVarRequirement.description  s        !G4<!XYYYr   c                 p     d j         v r j         d         S t           fdt          D                       S )zJGet whether this is a password-type value we should encrypt when possible.	encryptedc              3   L   K   | ]}j                             |          V  d S rp   )rx   endswith).0suffixr   s     r   	<genexpr>z.EnvVarRequirement.encrypted.<locals>.<genexpr>$  s3      TTt|,,V44TTTTTTr   )rU   any_secret_suffixesr   s   `r   r   zEnvVarRequirement.encrypted  sF     $,& 	U<,,TTTTCSTTTTTTr   c                 ^    | j                             dd          }|dS t          |          S )z*Get the default, forced to string or None.rR   N)rU   ri   rW   r   s     r   default_as_stringz#EnvVarRequirement.default_as_string&  s6       D11 	4 u::r   c                 L    |                     | j        d          }|dk    rd}|S ))A "protected" method for subtypes to use.N )ri   rx   )r   rJ   r   s      r   _get_value_of_env_varz'EnvVarRequirement._get_value_of_env_var1  s-    DL$//B; 	Er   c                 8    d                     | j                  S )r   z*Environment variable {env_var} is not set.r   )r}   rx   r   s    r   _unset_messagez EnvVarRequirement._unset_message8  s    ;BB4<BXXXr   c                     | j         rd                    | j                  S d                    | j        |                     |                    S )r   z&Environment variable {env_var} is set.r   z/Environment variable {env_var} set to '{value}'rw   )r   r}   rx   r   )r   rJ   s     r   _set_messagezEnvVarRequirement._set_message<  s_    > 	w;BB4<BXXXDKKTXT`RVRlRlmtRuRu L w w wr   c           
          |                      |          }|du}|r|                     |          }n|                                 }|                     ||||||d|          S )z&Override superclass to get our status.NEnvVarProvider)rL   rM   r/   r0   rj   r3   )r   r   r   rk   )	r   rJ   rK   rL   rM   r3   r   r/   r0   s	            r   rH   zEnvVarRequirement.check_statusE  s    **733!- 	7!%!2!27!;!;!%!4!4!6!6""7#39N-65F6H7G9N # P P 	Pr   rp   )r   r   r    r!   classmethodr   r   r7   r"   rY   r\   r   r   r   r   r   rH   __classcell__)r   s   @r   ru   ru      s/       CC  [6     L L L   X Z Z XZ U U XU   X  Y Y Yw w wP P P P P P P Pr   ru   N)r!   
__future__r   abcr   r   copyr   #anaconda_project.internal.metaclassr   $anaconda_project.internal.py2_compatr   anaconda_project.statusr	   objectr   r&   rP   r   ru   r$   r   r   <module>r      sq   - , & & & & & & ' ' ' ' ' ' ' '       > > > > > > : : : : : : * * * * * *$ $ $ $ $& $ $ $.RD RD RD RD RD RD RD RDjf f f f f..)) f f fT ; jP jP jP jP jP jP jP jP jP jPr   