
    si;                    V   S r SSKJr  SSKrSSKrSSKJr  SSKJr  SSK	J
r
  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJrJr  SSKJr  SSKJr  SSKJrJrJrJrJr  SSK J!r!  SSK"J#r#  SSK$J%r%  SSK&J'r(  SSK&J)r)  SSK*J+r+  \(       a  SSKJ,r,  \-" S5      r.\-" S5      r/\-" / \.Q\/Q75      r0S4S jr1S5S jr2S6S jr3S7S jr4S8S jr5S9S jr6\3\2\4\5\6S.r7S:S  jr8S! r9 S;S" jr:S<S$ jr;S% r<S& r=S' r> " S( S)\?5      r@ " S* S#5      rA\" S+S,S-S.9 " S/ S0\A5      5       r'\" S1S+5      S2 5       rBS3 rCg)=z>Environment object describing the conda environment.yaml file.    )annotationsN)chain)TYPE_CHECKING   )context)common)dashlist)unique)expand)jsonyaml)
PrefixData)
deprecated)CondaMultiErrorEnvironmentFileEmptyEnvironmentFileInvalidEnvironmentFileNotFoundInvalidMatchSpec)download_text)CONDA_SESSION_SCHEMES)History)Environment)EnvironmentConfig)	MatchSpec)Any)dependencies)nameprefixchannels	variablesc                Z    [        X5      (       d  [        SU  SUR                   35      eg)zValidates the type of a valuezInvalid type for 'z', expected a N)
isinstancer   __name__)
field_namevalue
value_types      -lib/python3.13/site-packages/conda/env/env.pyfield_type_validationr(   1   s6    e(($ N:;N;N:OP
 	
 )    c                &    [        SU [        5        g)zPValidate the contents of the prefix field.

Will ensure:
  * prefix is a string
r   Nr(   str)r   s    r'   prefix_validationr-   9   s     (FC0r)   c                &    [        SU [        5        g)zLValidate the contents of the name field.

Will ensure:
  * name is a string
r   Nr+   )r   s    r'   name_validationr/   B   s     &$,r)   c           	        [        SU [        5        / nU  H[  n[        U[        5      (       a   [	        U5        M&  [        U[        5      (       a  M=  UR                  [        SU S35      5        M]     U(       a  [        U5      eg! [
         a.  nUR                  [        [        U5      5      5         SnAM  SnAff = f)zValidate the contents of the dependencies field.

Will ensure:
  * dependencies are a list
  * all string dependencies are MatchSpec compatible
  * the only other type allowed is a dict
r   N'z'' is an invalid type for a 'dependency')
r(   listr"   r,   r   r   appendr   dictr   )r   errors
dependencyerrs       r'   dependencies_validationr8   K   s     .,=F"
j#&&@*% 
D))  MM&
|#JK #( f%%  $ @4SX>??@s   B
C #B;;C c                x    [        SU [        5        U  H#  n[        U[        5      (       a  M  [	        S5      e   g)znValidate the contents of the channels field.

Will ensure:
  * channels is a list
  * all entries are strings
r   z;`channels` key must only contain strings. Found '{channel}'N)r(   r2   r"   r,   r   )r   channels     r'   channels_validationr;   n   s7     *h5'3''(M  r)   c                &    [        SU [        5        g)zpValidate the contents of the variables field.

Will ensure:
  * variables is a dict
  * all entries are strings
r    N)r(   r4   )r    s    r'   variables_validationr=   ~   s     +y$7r)   )r   r   r   r   r    c                8   / n[         R                  U 5       H!  nUR                  [        SU S35      5        M#     [        R                  5        H  u  p4 U" X   5        M     U$ ! [         a     M#  [         a  nUR                  U5         SnAMC  SnAff = f)a9  Parses environment.yaml data to build a list of schema errors

Will produce errors to ensure:
  * all required fields are present
  * all fields contain valid data

:param dict data: The contents of the environment.yaml
:returns errors: A list of EnvironmentFileInvalid exceptions that occurred during validation
zMissing required field 'r1   N)REQUIRED_KEYS
differencer3   r   SCHEMA_VALIDATORSitemsKeyError)datar5   fieldkey	validatorr7   s         r'   get_schema_errorsrH      s     F))$/,/Gwa-PQR 0 ,113	di  4 M  	% 	MM#	s   
A''
B4	B=BBc           	       ^^ / nU (       a  U R                  5       O0 nU R                  5        H1  nU[        ;  d  M  UR                  U5        UR	                  U5        M3     U(       am  UR                  S5      n[        U5      S:w  a  SOSn[        U5      S:w  a  SOSn[        SU SU S	U S
35        U H  n[        SU 35        M     [        5         U R                  S5      =(       d    / n[        R                  " S5      mU4S jm[        U4S jU 5       5      n	U HL  n
[        U
[        5      (       d  M  SU
;   d  M"  U	(       a  M+  [        S5        US   R                  SS5          U$    U$ )z7Check for unknown keys, remove them and print a warningfilename   areiss z2
EnvironmentSectionNotValid: The following sectionz on 'z' z invalid and will be ignored:z - r   z[<>~\s=]c                P   > STR                  U 5      S   R                  S5      ;   $ )Npipr   z::)split)depdepsplits    r'   <lambda>validate_keys.<locals>.<lambda>   s#    (.."5a"8">">t"DDr)   c              3  b   >#    U  H$  n[        U[        5      (       a  M  T" U5      v   M&     g 7fN)r"   r4   ).0rS   is_pips     r'   	<genexpr> validate_keys.<locals>.<genexpr>   s"     M4Cz#t7LKF3KK4s   //rQ   aE  Warning: you have pip-installed dependencies in your environment file, but you do not list pip itself as one of your conda dependencies.  Conda may not use the correct pip to install your packages, and they may end up in the wrong place.  Please add an explicit pip dependency.  I'm adding one for you, but still nagging you.r   )copykeys
VALID_KEYSr3   popgetlenprintrecompileanyr"   r4   insert)rD   kwargsinvalid_keysnew_datarF   rJ   verbpluraldeps	lists_piprS   rT   rZ   s              @@r'   validate_keysro      sT   L"tyy{Hyy{j $LL 
 ::j)L)Q.uDL)Q.BA& JzD6!>@	
  CCu+  88N#)rDzz+&HDFM4MMIc4  Uc\))3 ^$++Au5O  Or)   c           	         [        USS9nUR                  5       nU(       af  [        U5      R                  5       nUR	                  5        Vs/ s H  n[        U5      PM     n	n[        U U	[        [        R                  5      UUS9$ UR                  5       n
UR                  5       nU
 Vs/ s H"  nU(       a  UR                  OUR                  PM$     nnU(       a=  UR                  SU Vs/ s H  nUR                   SUR                    3PM      sn05        [        [        R                  5      nU(       d9  U
 H3  nUR"                  R$                  nUU;  d  M!  UR'                  SU5        M5     [        U UUUUS9$ s  snf s  snf s  snf )aN  
    Get ``EnvironmentYaml`` object from prefix
Args:
    name: The name of environment
    prefix: The path of prefix
    no_builds: Whether has build requirement
    ignore_channels: whether ignore_channels
    from_history: Whether environment file should be based on explicit specs in history

Returns:     EnvironmentYaml object
T)interoperability)r   r   r   r   r    rQ   z==r   )r   get_environment_env_varsr   get_requested_specs_mapvaluesr,   EnvironmentYamlr2   r   r   get_conda_packagesget_python_packagesspec_no_buildspecr3   r   versionr:   canonical_namerg   )r   r   	no_buildsignore_channelsfrom_historypdr    historypackagerm   conda_precspython_precs
conda_precr   python_precr   r{   s                    r'   from_environmentr      s    
FT	2B++-I&/99;,3NN,<=,<G,<='**+
 	
 '')K))+L &%J %.
  :??B%   '3'3 #''(;+>+>*?@'3	
 G$$%H%J'//>>NX->2 &
 ! C >s   F,)F.%F
ru   c           	     b   [         R                  " U 5      nUR                  S5      nUc  [        U5      e[	        U5      nU(       a(  [
        R                  " SSSS[        U5       3[        S9  [        X!5      nUb  UR                  5        H	  u  pVXbU'   M     [        U5        [        S0 UD6$ )a-  Load and return a ``EnvironmentYaml`` from a given ``yaml`` string

:param yamlstr: The contents of the environment.yaml
:param raise_validation_errors: Indicates if an error should be raised if the yamlstr
    is found to be invalid
:returns EnvironmentYaml: A representation of the environment file
rJ   26.326.9z2The environment file is not fully CEP 24 compliantz~In the future, this configuration will be rejected. Please fix the following errors in order to make the configuration valid: )topicaddendumdeprecation_type )r   loadsra   r   rH   r   r   r	   FutureWarningro   rB   _expand_channelsru   )yamlstrrh   rD   rJ   r5   rF   r%   s          r'   	from_yamlr     s     ::gDzz*%H|"8,, t$FFDF#$& +
	
 &D ,,.JCI )T"T""r)   c                    U R                  S/ 5       Vs/ s H"  n[        R                  R                  U5      PM$     snU S'   gs  snf )zQExpands ``EnvironmentYaml`` variables for the channels found in the ``yaml`` datar   N)ra   ospath
expandvars)rD   r:   s     r'   r   r   6  sB     4888J3K3K7#3KD s   )Ac                   U R                  SS5      S   nU[        ;   a  [        U 5      nU$ [        R                  R                  U 5      (       d  [        U 5      e[        U S5       nUR                  5       n UR                  S5      nSSS5        U$ ! [         a    UR                  S5      n N'f = f! , (       d  f       W$ = f)z0Load and return an yaml string from a given file://rK   r   rbzutf-8zutf-16N)rR   r   r   r   r   existsr   openreaddecodeUnicodeDecodeError)rJ   
url_schemer   fpyamlbs        r'   	load_filer   =  s    q)!,J**) N WW^^H%%%h//(D!RGGIE1,,w/ " N & 1,,x01	 "! Ns*   (B6:BB30B62B33B66
Cc                *    [        U 5      n[        XS9$ )z8Load and return an ``EnvironmentYaml`` from a given file)rJ   )r   r   )rJ   r   s     r'   	from_filer   N  s    !GW00r)   c                  8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )DependenciesiT  zNA ``dict`` subclass that parses the raw dependencies into a conda and pip listc                R   > [         TU ]  " U0 UD6  Xl        U R                  5         g rX   )super__init__rawparse)selfr   argsrh   	__class__s       r'   r   Dependencies.__init__W  s#    $)&)

r)   c                   U R                   (       d  gU R                  S/ 05        U R                    HQ  n[        U[        5      (       a  U R                  U5        M+  U S   R	                  [        [        U5      5      5        MS     SU ;   a=  U S   (       d  U S	 [        S U S    5       5      (       d  U S   R	                  S5        ggg)z4Parse the raw dependencies into a conda and pip listNcondarQ   c              3  R   #    U  H  n[        U5      R                  S :H  v   M     g7f)rQ   N)r   r   )rY   rN   s     r'   r[   %Dependencies.parse.<locals>.<genexpr>l  s     I=ay|((E1=s   %')r   updater"   r4   r3   r,   r   rf   )r   lines     r'   r   Dependencies.parse\  s    xxWbM"HHD$%%D!W$$S4%9:	  D=;KI4=IIIW$$U+ J r)   c                Z    U R                   R                  U5        U R                  5         g)z(Add a package to the ``EnvironmentYaml``N)r   r3   r   )r   package_names     r'   addDependencies.addp  s    %

r)   )r   )
r#   
__module____qualname____firstlineno____doc__r   r   r   __static_attributes____classcell__)r   s   @r'   r   r   T  s    X
,( r)   r   c                  ^    \ rS rSrSr      SS jrS rS rSS jrSS jr	S	 r
SS
 jrSrg)ru   iv  1A class representing an ``environment.yaml`` fileNc                j    Xl         X l        XPl        [        U5      U l        X`l        Uc  / nX0l        g rX   )r   rJ   r   r   r   r    r   )r   r   rJ   r   r   r   r    s          r'   r   EnvironmentYaml.__init__y  s5     	 (6"H r)   c                t    [        [        [        R                  " XR                  45      5      5      U l        g)z'Add channels to the ``EnvironmentYaml``N)r2   r
   r   from_iterabler   )r   r   s     r'   add_channelsEnvironmentYaml.add_channels  s%    VE$7$7==8Q$RSTr)   c                    / U l         g)z0Remove all channels from the ``EnvironmentYaml``Nr   )r   s    r'   remove_channelsEnvironmentYaml.remove_channels  s	    r)   c                   SU R                   0nU R                  (       a  U R                  US'   U R                  (       a  U R                  R                  US'   U R                  (       a  U R                  US'   U R
                  (       a  U R
                  US'   Uc  U$ UR                  [        R                  " U5      5        g)zHConvert information related to the ``EnvironmentYaml`` into a dictionaryr   r   r   r    r   N)	r   r   r   r   r    r   writer   dumpsr   streamds      r'   to_dictEnvironmentYaml.to_dict  s    TYY== MMAjM $ 1 1 5 5An>>!^^AkN;;++AhK>HTZZ]#r)   c                J    U R                  5       n[        R                  " X!S9$ )zMConvert information related to the ``EnvironmentYaml`` into a ``yaml`` string)r   )r   r   r   r   s      r'   to_yamlEnvironmentYaml.to_yaml  s    LLNzz!''r)   c                    [        U R                  S5       nU R                  US9  SSS5        g! , (       d  f       g= f)z4Save the ``EnvironmentYaml`` data to a ``yaml`` filewb)r   N)r   rJ   r   )r   r   s     r'   saveEnvironmentYaml.save  s,    $--&"LLL# '&&s   0
>c           
        [        [        U R                  5      S9n0 nU R                  R	                  S5      =n(       a  X2S'   U R                  R	                  S/ 5       Vs/ s H  n[        U5      PM     nn[        U R                  =(       d    [        R                  [        R                  U R                  UU R                  UUS9$ s  snf )z?Convert the ``Environment`` into a ``model.Environment`` objectr   rQ   r   )r   platformr   configr    external_packagesrequested_packages)r   tupler   r   ra   r   EnvironmentModelr   r   target_prefixsubdirr   r    )r   r   r   pip_dependenciesry   r   s         r'   to_environment_model$EnvironmentYaml.to_environment_model  s    "E$--,@A#0044U;;;'7e$ )-(9(9(=(=gr(J
(JIdO(J 	 
  ;;7'"7"7^^nn/1
 	
	
s   #C)r   r   rJ   r   r   r    )NNNNNNrX   )returnr   )r#   r   r   r   r   r   r   r   r   r   r   r   r   r   r)   r'   ru   ru   v  s=    ; !&U$(
$

r)   r   r   z,Use `conda.env.env.EnvironmentYaml` instead.)r   c                      \ rS rSrSrSrg)r   i  r   r   N)r#   r   r   r   r   r   r   r)   r'   r   r     s    ;r)   r   z25.9c                Z    U R                  SS5      S   nU[        ;   a  U $ [        U 5      $ )z3Expand filename if local path or return the ``url``r   rK   r   )rR   r   r   )rJ   r   s     r'   get_filenamer     s2     q)!,J**hr)   c                $   [         R                  (       aR  US   c  US   c  [        R                  " SS9  gUS   b  US   nO0 nUS   b  US   US'   [        R                  " XS9  g[        R                  " U R
                  =(       d    U5        g)z(Print the result of an install operationr   NrQ   z)All requested packages already installed.)messagePIP)r   actions)r   r   r   stdout_json_successprint_activater   )r   r   resultr   s       r'   print_resultr     s    ||'?"ve}'<&&C g* /e}(!'&&fFdii162r)   )r$   r,   r%   r   r&   r   r   None)r   r,   )r   r,   )r   r2   )r   r2   )r    zdict[str, str])rD   r4   r   zlist[EnvironmentFileInvalid])FFF)r   r,   r   ru   )Dr   
__future__r   r   rd   	itertoolsr   typingr   base.contextr   clir   	common.ior	   common.iteratorsr
   common.pathr   common.serializer   r   core.prefix_datar   deprecationsr   
exceptionsr   r   r   r   r   gateways.connection.downloadr   gateways.connection.sessionr   r   r   models.environmentr   r   r   models.match_specr   r   	frozensetr?   OPTIONAL_KEYSr_   r(   r-   r/   r8   r;   r=   rA   rH   ro   r   r   r   r   r   r4   r   ru   r   r   r   r)   r'   <module>r     sL   E " 	 	    "    %   ) ) %  9 ?  @ 2 )+, 7778

1- &F 8 +#% 6$P HM:z##L"14 DK
 K
\ FF%ST</ < U< FF   3r)   