
    si1T                       S r SSKJr  SSK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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Jr  SSK J!r!  SSK"J#r#  SSK$J%r%  \(       a2  SSK&J'r'  SSK(J)r)  SSKJ*r*  SSKJ+r+J,r,J-r-J.r.  SSK/J0r0  SSK1J2r2  \*" S5      r3\" \45      r5\ " S S5      5       r6\" SS9 " S S5      5       r7g )!z)EXPERIMENTAL Conda environment data model    )annotations)	dataclassfieldfieldsreplace)reduce)chain)	getLogger)TYPE_CHECKING   )EXPLICIT_MARKER	PLATFORMSUNKNOWN_CHANNEL)context)specs_from_url)groupby_to_dict)
PrefixData)
CondaErrorCondaValueError)History)!get_package_records_from_explicit   )	MatchSpec)	Namespace)Iterable)TypeVar)ChannelPriorityDepsModifierSatSolverChoiceUpdateModifier)PathType)PackageRecordTc                  f   \ rS rSr% Sr\" \S9rS\S'   Sr	S\S'   \" \S9r
S\S	'   \" \S9rS
\S'   SrS\S'   \" \S9rS\S'   \" \S9rS\S'   \" \S9rS\S'   SrS\S'   SrS\S'   \" \S9rS\S'   SrS\S'   SrS\S'         S S jr      S!S jrS"S jr\S#S j5       r\S$S j5       rSrg)%EnvironmentConfig-   z
**Experimental** While experimental, expect both major and minor changes across minor releases.

Data model for a conda environment config.
default_factoryztuple[str, ...]aggressive_update_packagesNzChannelPriority | Nonechannel_prioritychannelstuple[dict[str, str], ...]channel_settingszDepsModifier | Nonedeps_modifierdisallowed_packagespinned_packagesrepodata_fnszSatSolverChoice | None
sat_solver
str | Nonesolvertrack_featureszUpdateModifier | Noneupdate_modifierzbool | Noneuse_only_tar_bz2c           	     ^    [        [        R                  S [        X5       5       5      5      $ )Nc              3  $   #    U  H  ov   M     g 7fN ).0items     8lib/python3.13/site-packages/conda/models/environment.py	<genexpr>?EnvironmentConfig._append_without_duplicates.<locals>.<genexpr>R   s     "I4HD44Hs   )tupledictfromkeysr	   )selffirstseconds      r>   _append_without_duplicates,EnvironmentConfig._append_without_duplicatesO   s#     T]]"IE%4H"IIJJ    c                n    [        S [        X5      5      n[        S UR                  5        5       5      $ )zMerge channel settings.

An individual channel setting is a dict that may have the key "channels". Settings
with matching "channels" should be merged together.
c                $    U R                  S5      $ )Nchannel)get)xs    r>   <lambda>;EnvironmentConfig._merge_channel_settings.<locals>.<lambda>^   s    aeeI&rI   c           	   3     #    U  H7  u  pU VVVs0 s H  o3R                  5         H  u  pEXE_M	     M      snnnv   M9     g s  snnnf 7fr:   )items)r<   rL   configsconfigkvs         r>   r?   <EnvironmentConfig._merge_channel_settings.<locals>.<genexpr>a   sB      
$D  !(CfLLNDAQTNQCC$D Ds   A%A
A)groupbyr	   rA   rR   )rD   rE   rF   grouped_channel_settingss       r>   _merge_channel_settings)EnvironmentConfig._merge_channel_settingsT   s>     $+&e(<$
   
$<$B$B$D
 
 	
rI   c                   Uc  U $ [        XR                  5      (       d  [        S5      eU R                  U R                  UR                  5      U l        UR
                  b  UR
                  U l        U R                  U R                  UR                  5      U l        U R                  U R                  UR                  5      U l        UR                  b  UR                  U l	        U R                  U R                  UR                  5      U l
        U R                  U R                  UR                  5      U l        U R                  U R                  UR                  5      U l        UR                  b  UR                  U l        UR                  b  UR                  U l        U R                  U R                  UR                  5      U l        UR                   b  UR                   U l        UR"                  b  UR"                  U l        U $ )a  
**Experimental** While experimental, expect both major and minor changes across minor releases.

Merges an EnvironmentConfig into this one. Merging rules are:
* Primitive types get clobbered if subsequent configs have a value, otherwise keep the last set value
* Lists get appended to and deduplicated
* Dicts get updated
* Special cases:
  * channel settings is a list of dicts, it merges inner dicts, keyed on "channel"
z9Cannot merge EnvironmentConfig with non-EnvironmentConfig)
isinstance	__class__r   rG   r)   r*   r+   rZ   r-   r.   r/   r0   r1   r2   r4   r5   r6   r7   )rD   others     r>   _mergeEnvironmentConfig._mergef   s    =K %00!K  +/*I*I++U-M-M+
' !!-$)$:$:D!77u~~V $ < <!!5#9#9!
 *!&!4!4D#'#B#B$$e&?&?$
   $>>  %"7"7 
 !;;u11
 '#..DO<<#,,DK"==!5!5
   ,#(#8#8D !!-$)$:$:D!rI   c                    [        U 5       Vs1 s H  oR                  iM     nn[        R                  R	                  5        VVs0 s H  u  p4X2;   d  M  X4_M     nnnU " S0 UD6$ s  snf s  snnf )z
**Experimental** While experimental, expect both major and minor changes across minor releases.

Create an EnvironmentConfig from the current context
r;   )r   namer   environment_settingsrR   )clsr   field_nameskeyvaluerd   s         r>   from_contextEnvironmentConfig.from_context   sv     06c{;{ezz{; &::@@B 
B
! CJB 	  

 *)** < 
s   A&A+A+c                b    U(       d  g[        U5      S:X  a  US   $ [        S USS US   5      $ )aO  
**Experimental** While experimental, expect both major and minor changes across minor releases.

Merges a list of EnvironmentConfigs into a single one. Merging rules are:
* Primitive types get clobbered if subsequent configs have a value, otherwise keep the last set value
* Lists get appended to and deduplicated
* Dicts get updated
Nr   r   c                $    U R                  U5      $ r:   )r`   )resultrT   s     r>   rO   )EnvironmentConfig.merge.<locals>.<lambda>   s    6==#8rI   )lenr   )re   rS   s     r>   mergeEnvironmentConfig.merge   sB      w<11: 8'!"+wqz
 	
rI   )r)   r*   r-   r+   r.   r/   r0   r1   r2   r4   r5   r6   r7   )rE   Iterable[T]rF   rr   returnztuple[T, ...])rE   r,   rF   r,   rs   r,   )r_   r%   rs   r%   )rs   r%   )rS   r%   rs   r%   )__name__
__module____qualname____firstlineno____doc__r   rA   r)   __annotations__r*   r+   r-   r.   r/   r0   r1   r2   r4   r5   r6   r7   rG   rZ   r`   classmethodri   rp   __static_attributes__r;   rI   r>   r%   r%   -   s%    382NN/3,3 %e <Ho<383O0O)-M&-+0+GG',U'CO_C$)%$@L/@)-J&-FJ&+E&BNOB-1O*1$(k(K K*5K	K

/
9S
	#
$AF + + 
 
rI   r%   T)kw_onlyc                  l   \ rS rSr% SrS\S'    \" \S9rS\S'    \" \	S9r
S\S	'    \" \S9rS
\S'    SrS\S'    SrS\S'    \" \S9rS\S'    \" \	S9rS\S'    \" \S9rS
\S'   S r\S 5       r\SSSSS.               SS jj5       r\ S     S S jj5       r\S!S j5       rS"S jrSrg)#Environment   z
**Experimental** While experimental, expect both major and minor changes across minor releases.

Data model for a conda environment.
strplatformr'   r%   rT   zdict[str, list[str]]external_packageszlist[PackageRecord]explicit_packagesNr3   rc   prefixlist[MatchSpec]requested_packageszdict[str, str]	variablesvirtual_packagesc                h   U R                   (       d  [        S5      eU R                   [        ;  a   [        SU R                    S[         S35      e[        U R                  5      S:  aG  [        [        S U R                   5       5      5      [        U R                  5      :w  a  [        S5      e[        U R                  5      S:  ai  [        U R                  5      S:  aO  [        S	 U R                   5       5      nU R                   H"  nUR                  U;  d  M  [        S
U S35      e   g g g )Nz!'Environment' needs a 'platform'.zInvalid platform 'z'. Valid platforms are .r   c              3  8   #    U  H  oR                   v   M     g 7fr:   rc   r<   pkgs     r>   r?   ,Environment.__post_init__.<locals>.<genexpr>
  s     ;$:S$:   z0Duplicate packages found in 'explicit_packages'.r   c              3  8   #    U  H  oR                   v   M     g 7fr:   r   r   s     r>   r?   r     s     (T=Sc=Sr   zRequested package 'z&' is not found in 'explicit_packages'.)r   r   r   ro   r   setr   rc   )rD   explicit_package_namesrequested_packages      r>   __post_init__Environment.__post_init__   s   }}!"EFF ==	)!$T]]O3J9+UVW 
 t%%&*s;D$:$:;;0
''(0) ""TUU t&&'!+D4J4J0Ka0O%((TT=S=S(T%T"%)%<%<!$))1GG)-.?-@@fg  &= 1P+rI   c                D   SnSnSnU Vs/ s H!  oUR                   (       d  M  UR                   PM#     nnU Vs/ s H!  oUR                  (       d  M  UR                  PM#     nnU(       a*  US   n[        U5      S:  a  [        R	                  SXb5        U(       a*  US   n[        U5      S:  a  [        R	                  SXs5        U Vs/ s H!  oUR
                  (       d  M  UR
                  PM#     nn[        [        U5      5      S:X  a  US   nO[        SU 35      e[        [        R                  S U 5       5      5      n	[        [        R                  S U 5       5      5      n
[        [        R                  S	 U 5       5      5      nU VVVs0 s H(  oUR                  R                  5         H  u  pX_M	     M*     nnnn0 nU Hn  nUR                  R                  5        HM  u  pX;   a(  U H   nUX   ;  d  M  X   R                  U5        M"     M2  [        U[        5      (       d  MI  XU'   MO     Mp     [         R"                  " U Vs/ s H  oUR$                  c  M  UR$                  PM     sn6 nU " UUU
UUUU	UUS
9	$ s  snf s  snf s  snf s  snnnf s  snf )a5  
**Experimental** While experimental, expect both major and minor changes across minor releases.

Merges multiple environments into a single environment following the rules:
* Keeps first name and/or prefix.
* Concatenates and deduplicates requirements.
* Reduces configuration and variables (last key wins).
Nr   r   z-Several names passed %s. Picking first one %sz0Several prefixes passed %s. Picking first one %sz_Conda can not merge environments of different platforms. Received environments with platforms: c              3  N   #    U  H  nUR                     H  nUv   M	     M     g 7fr:   )r   r<   envrequirements      r>   r?   $Environment.merge.<locals>.<genexpr>>  s*      'C#&#9#9K #9 '   #%c              3  N   #    U  H  nUR                     H  nUv   M	     M     g 7fr:   )r   r   s      r>   r?   r   F  s*      'C#&#8#8K #8 'r   c              3  N   #    U  H  nUR                     H  nUv   M	     M     g 7fr:   )r   )r<   r   virtual_packages      r>   r?   r   N  s*      'C'*';';O  ';  'r   )	rT   r   r   rc   r   r   r   r   r   )rc   r   ro   logdebugr   r   r   listrB   rC   r   rR   r   appendr]   r%   rp   rT   )re   environmentsrc   r   r   r   namesprefixes	platformsr   r   r   rU   rV   r   r   valrT   s                     r>   rp   Environment.merge  sz    %1>\cXX\>*6E,3**JCJJ,E8D5zA~		I5Wa[F8}q 		F .:J\c\\\S\\\	Js9~!# |H!99BE 
 "MM ' 
 !MM ' 
  MM ' 
 &2V\c@S@S@UfqQT@UQ\	VC --335) &7&::-077<  !  4((+,a( 6   #(($0KLSJJjcjjLK
 //1-

 
	
G ?E KD W Ls3   JJJJ	J!J/JJ%JF)from_history	no_buildsignore_channelsr+   c               j  ^ [        USS9nUR                  5       n	/ n
0 nU(       a  U R                  U5      n
/ nOUR                  5       nUR	                  5       nU H  nU(       a  UR
                  OUR                  nU(       dG  UR                  (       a6  UR                  R                  (       a  UR                  R                   SU 3nU
R                  [        U5      5        M     U(       a0  U Vs/ s H  nUR                   SUR                   3PM      nnUUS'   [        UR                  5       5      n[        U=(       d    S5      nU(       d  / U4S jU 5       QUQ7n[        [        R!                  U5      5      n["        R%                  5       n['        UUS9nU " UUUUU	UU
US	9$ s  snf )
ak  
Create an Environment model from an existing conda prefix.

This method analyzes an installed conda environment and creates
an Environment model that can be used for exporting or other operations.

:param prefix: Path to the conda environment prefix
:param name: Name for the environment
:param platform: Target platform (e.g., 'linux-64', 'osx-64')
:param from_history: Use explicit specs from history instead of installed packages
:param no_builds: Exclude build strings from package specs
:param ignore_channels: Don't include channel information in package specs
:return: Environment model representing the prefix
T)interoperabilityz::z==pipr;   c              3  l   >#    U  H)  nUR                   R                  =m[        :w  d  M%  Tv   M+     g 7fr:   )rL   canonical_namer   )r<   conda_packager   s     r>   r?   *Environment.from_prefix.<locals>.<genexpr>  s8       *5*7*?*?*N*NN&' #N)4s   $4	4)r+   )r   r   rc   rT   r   r   r   r   )r   get_environment_env_varsr   get_conda_packagesget_python_packagesspec_no_buildspecrL   rc   r   r   versionr   iter_recordsrA   rB   rC   r%   ri   r   )re   r   rc   r   r   r   r   r+   prefix_datar   r   r   conda_precspython_precs
conda_precspec_strpython_precpython_depsr   environment_channelsrT   r   s                        @r>   from_prefixEnvironment.from_prefixs  s   4 !$?88:	   !$!1!1&!9K &88:K&::<L *
7@:33joo ("**"**//","4"4"9"9!:"XJGH")))H*=> *  (4'3 #''(;+>+>*?@'3   ,7!%( !!9!9!;<  %X^4 	$ *5	$ &	$   %T]]3G%HI #//1 *>?/1/	
 		
Gs   6%F0c           	        UR                    Vs/ s H  o3R                  S5      PM     nn/ n/ nUR                   H:  n UR                  [	        U5       Vs/ s H  o[
        :w  d  M  UPM     sn5        M<     U(       ah  U Vs1 s H  n[        U5      R                  iM     n	n[        R                   H/  n
[        U
5      R                  U	;  d  M  UR                  U
5        M1     U HH  n[        U5      =nR                  S5      (       a  UR                  U5        M7  UR                  U5        MJ     / nU(       a/  [        U5      [        U5      :X  a  [        U5      nO[!        S5      e[#        UR                  [        R$                  [        R&                  UU[(        R+                  5       S9$ s  snf s  snf ! [         a    [        S5      ef = fs  snf )aj  
Create an Environment model from command-line arguments.

This method will parse command-line arguments and create an
Environment object. This includes: reading files provided as
cli arguments, and pulling EnvironmentConfig from the context.

:param args: argparse Namespace containing command-line arguments
:return: An Environment object representing the cli
z"'ziError reading file, file should be a text file containing packages
See `conda create --help` for details.urlz6Cannot mix specifications with conda package filenames)rc   r   r   r   r   rT   )packagesstripfileextendr   r   UnicodeErrorr   r   rc   r   create_default_packagesr   rM   ro   r   r   r~   target_prefixsubdirr%   ri   )re   argsadd_default_packagespackagespecsr   fetch_explicit_packagesfpathr   r   default_package
match_specr   s                r>   from_cliEnvironment.from_cli  s     6:]]C]'u%]C"$ YYE&4U&;W&;d?VT&;W   6;<edYt_))eE<#*#B#B_-22%?LL1 $C D'o-
22599'..t4"))*5	  "*+s5z9$E+%! &L  ((^^1/$113
 	
_ D X  =  =s.   F4F>F9
(F9
.F>G9F>>Gc                j    [        U 5      nUR                  5       n[        UR                  5       5      $ r:   )r   get_requested_specs_mapr   values)r   historyspec_maps      r>   r   Environment.from_history#  s+    &/224HOO%&&rI   c                   XR                   :X  a  U $ SSKJn  [        R                  R                  5       nU R                  U R                  5      nU" U R                  R                  0 5       H9  nU nU" S[        R                  US4UUSS9nUR                  5       nSSS5        M;     [        U R                  U R                  U[        R                  5       UWU R                   S9$ ! , (       d  f       M  = f)	zT
Given the current environment, extrapolate the environment for the given platform.
r   )	Repodatasz/env/does/not/existnoarchcreate)r   r+   subdirsspecs_to_addrepodata_fncommandN)r   rc   r   rT   r   r   r   )r   cli.installr   r   plugin_managerget_cached_solver_backendr   r   rT   r1   r+   solve_final_stater~   rc   r%   ri   r   )	rD   r   r   solver_backendr   repodata_managerr   r4   r   s	            r>   extrapolateEnvironment.extrapolate*  s     }}$K+ //IIK!..t{{; )$++*B*BB G!['0$--%x0!3 +$ %+$<$<$>! "! !H ;;$1131/"44
 	
 "!s   3,C**
C9	r;   )r   r   rc   r   r   r   r   boolr   r   r   r   r+   zlist[str] | Noners   r~   )F)r   r   r   r   rs   r~   )r   r!   rs   r   )r   r   rs   r~   )rt   ru   rv   rw   rx   ry   r   r%   rT   rB   r   r   r   rc   r   r   r   r   r   rz   rp   r   r   staticmethodr   r   r{   r;   rI   r>   r~   r~      s    MG %6G HFH /4D.I+IW-24-H*H
 D*FJ3*/*EE4 %d ;I~;A -2$,G)G4 Y
 Y
v  # %%)e
e
 e
 	e
 e
 e
 e
 #e
 
e
 e
N  &+E
E
 #E
 
	E
 E
N ' '
rI   r~   N)8rx   
__future__r   dataclassesr   r   r   r   	functoolsr   	itertoolsr	   loggingr
   typingr   base.constantsr   r   r   base.contextr   
cli.commonr   common.iteratorsr   rX   core.prefix_datar   
exceptionsr   r   r   r   miscr   r   r   argparser   collections.abcr   r   r   r   r   r    common.pathr!   recordsr"   r#   rt   r   r%   r~   r;   rI   r>   <module>r     s    0 " 9 9      H H " ( 9 ) 4  4 !"(  '&A a
 a
 a
H 4v
 v
 v
rI   