
    wBf                    J   d Z ddlmZ ddlZddl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 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mZm Z  ddl!m"Z" ddl#m$Z$m%Z% ddl&m'Z'm(Z(m)Z) ddl*m+Z, ddl-m.Z.m/Z/ ddl0m1Z1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZA ddlBmCZCmDZD dd lEmFZFmGZG dd!lHmIZI dd"lJmKZK 	 dd#lLmLZL erdd$lmOZO dd%lPmQZQ  e	eR      ZS G d& d'      ZT G d( d)      ZUd* ZVd+e$f	 d-d,ZWy# eM$ r	 dd#lNmLZL Y Cw xY w).z"The classic solver implementation.    )annotationsN)chain)DEBUG	getLogger)join)dedent)TYPE_CHECKING)
IndexedSet)exists   )
CondaError)__version__)memoizedproperty)dals)REPODATA_FNUNKNOWN_CHANNELDepsModifierUpdateModifier)context)NULLTRACE)Spinnerdashlisttime_recorder)groupby_to_dict)get_major_minor_versionpaths_equal)PackagesNotFoundErrorSpecsConfigurationConflictErrorUnsatisfiableError)HistoryChannel)
NoarchType	MatchSpec)PrefixGraph)VersionOrder)Resolve   )_supplement_index_with_systemget_reduced_index)PrefixSetupUnlinkLinkTransaction)
PrefixData)
SubdirData)
frozendict)Iterable)PackageRecordc                     e Zd ZdZdddeef	 	 	 	 	 	 	 	 	 	 	 ddZeeeeeedfdZeeeeeedf	 ddZeeeeedfdZ	d Z
d	 Zd
 Z ee       d        Zd Z ee       d        Zd Zd Zd Z ee       d        Zd Zd Zd Zy)Solverz
    A high-level API to conda's solving logic. Three public methods are provided to access a
    solution in various forms.

      * :meth:`solve_final_state`
      * :meth:`solve_for_diff`
      * :meth:`solve_for_transaction`
     c                `   || _         |xs t        j                  | _        t	        d | j                  D              | _        t        d |xs t        j                  D              | _        t        t        j                  d |D                    | _
        t        d | j                  D              | _        t        t        j                  d |D                    | _        d| _        || _        t        d | j                  D              sJ || _        d| _        d| _        d	| _        i | _        y)
a  
        Args:
            prefix (str):
                The conda prefix / environment location for which the :class:`Solver`
                is being instantiated.
            channels (Sequence[:class:`Channel`]):
                A prioritized list of channels to use for the solution.
            subdirs (Sequence[str]):
                A prioritized list of subdirs to use for the solution.
            specs_to_add (set[:class:`MatchSpec`]):
                The set of package specs to add to the prefix.
            specs_to_remove (set[:class:`MatchSpec`]):
                The set of package specs to remove from the prefix.

        c              3  2   K   | ]  }t        |        y wNr"   ).0cs     0lib/python3.12/site-packages/conda/core/solve.py	<genexpr>z"Solver.__init__.<locals>.<genexpr>_   s     "F!71:"F   c              3      K   | ]  }|  y wr9   r6   r:   ss     r<   r=   z"Solver.__init__.<locals>.<genexpr>`   s     C1QC   c              3      K   | ]  }|  y wr9   r6   r@   s     r<   r=   z"Solver.__init__.<locals>.<genexpr>a   s     5NAa5NrB   c              3  4   K   | ]  }|j                     y wr9   namer:   _s     r<   r=   z"Solver.__init__.<locals>.<genexpr>b   s     +NqAFF+N   c              3      K   | ]  }|  y wr9   r6   r@   s     r<   r=   z"Solver.__init__.<locals>.<genexpr>c   s     8Tq8TrB   r6   c              3  @   K   | ]  }|t         j                  v   y wr9   )r   known_subdirsr@   s     r<   r=   z"Solver.__init__.<locals>.<genexpr>g   s     D!1---Ds   NF)prefixr   channels	_channelsr
   tuplesubdirs	frozensetr&   mergespecs_to_addspecs_to_add_namesspecs_to_removeneutered_specs_commandall_repodata_fn_index_r	_prepared_pool_cache)selfrM   rN   rQ   rT   rV   repodata_fncommands           r<   __init__zSolver.__init__D   s    2 !5W%5%5""Ft~~"FFC(B7??CC%ioo5N5N&NO"++ND<M<M+N"N(8TO8T)TU Dt||DDDD'    Fc           
        | j                   t        j                  k(  rt        j                  r
t	               t        j
                  j                  | j                  | j                         | j                  |||||||      \  }}	t        j
                  j                  | j                  ||	       | j                  |	       t        t        | j                   ||	| j                  | j                  | j                              S )a  Gives an UnlinkLinkTransaction instance that can be used to execute the solution
        on an environment.

        Args:
            deps_modifier (DepsModifier):
                See :meth:`solve_final_state`.
            prune (bool):
                See :meth:`solve_final_state`.
            ignore_pinned (bool):
                See :meth:`solve_final_state`.
            force_remove (bool):
                See :meth:`solve_final_state`.
            force_reinstall (bool):
                See :meth:`solve_for_diff`.
            should_retry_solve (bool):
                See :meth:`solve_final_state`.

        Returns:
            UnlinkLinkTransaction:

        )rM   r   root_prefixenable_private_envsNotImplementedErrorplugin_managerinvoke_pre_solvesrT   rV   solve_for_diffinvoke_post_solvesrZ   _notify_conda_outdatedr.   r-   rW   )
r_   update_modifierdeps_modifierpruneignore_pinnedforce_removeforce_reinstallshould_retry_solveunlink_precs
link_precss
             r<   solve_for_transactionzSolver.solve_for_transactionn   s    > ;;'---'2M2M &'' 	00  	

 $(#6#6$
 j 	11	
 	##J/$$$!!##	
 		
rc   c                    | j                  ||||||      }t        | j                  || j                  |      \  }	}
t	        d |	      j                  d      }|rt        dt        d |D              z        |	|
fS )a.  Gives the package references to remove from an environment, followed by
        the package references to add to an environment.

        Args:
            deps_modifier (DepsModifier):
                See :meth:`solve_final_state`.
            prune (bool):
                See :meth:`solve_final_state`.
            ignore_pinned (bool):
                See :meth:`solve_final_state`.
            force_remove (bool):
                See :meth:`solve_final_state`.
            force_reinstall (bool):
                For requested specs_to_add that are already satisfied in the environment,
                    instructs the solver to remove the package and spec from the environment,
                    and then add it back--possibly with the exact package instance modified,
                    depending on the spec exactness.
            should_retry_solve (bool):
                See :meth:`solve_final_state`.

        Returns:
            tuple[PackageRef], tuple[PackageRef]:
                A two-tuple of PackageRef sequences.  The first is the group of packages to
                remove from the environment, in sorted dependency order from leaves to roots.
                The second is the group of packages to add to the environment, in sorted
                dependency order from roots to leaves.

        c                    | j                   S r9   )is_unmanageable)precs    r<   <lambda>z'Solver.solve_for_diff.<locals>.<lambda>   s    D,@,@ rc   Tz&Cannot unlink unmanageable packages:%sc              3  <   K   | ]  }|j                           y wr9   )	record_idr:   rz   s     r<   r=   z(Solver.solve_for_diff.<locals>.<genexpr>   s     E4>>+E   )solve_final_statediff_for_unlink_link_precsrM   rT   groupbygetRuntimeErrorr   )r_   rm   rn   ro   rp   rq   rr   rs   final_precsrt   ru   unmanageables               r<   rj   zSolver.solve_for_diff   s    L ,,
 $>KKd&7&7$
 j
 @,OSS
 8EEEF 
 Z''rc   c           	         |r|t         j                  k(  rt        }|t        u rt        j                  }n"t        t        |      j                               }|t        u rt        j                  }n"t        t        |      j                               }|t        u rt        j                  n|}|t        u rt        j                  n|}t        j                  d j                   j                   j                  |       t!         d      }|s#t#         j                  ||||||      }| _        n! j$                  }||_        ||_        ||_         j                  rT|rR j                  r
t)               t+         fd|j,                  D              }	t/        t1        |	      j2                        S |t         j4                  k(  rn j                  sb|s` j                  D ])  }
t7        |j8                  j;                  |
      d      r) n) t/        t1        |j,                        j2                        S |j<                  sit?        d j@                  z  t        jB                   xr t        jD                   xr | t        jF                        5   jI                  |      }ddd       |r|t         j                  k(  rd}n% j@                  tJ        k7  rd j@                  z  }nd}t?        d	t        jB                   xr t        jD                   t        jF                  |
      5   jM                  |      } jO                  |      }tQ        jP                  |j,                        } jS                  |j,                  |jT                        } jW                  |      } jY                  |      } jS                  |j,                  |jT                        }|j                  t         jZ                  k(  r\ j]                  |||j^                  ja                               }tc        |      dkD  r#|D ]  }
 je                  |
|j,                           |jf                  rti        |      ti        |j,                        z
  ti        |jf                        z
  }|j,                  D cg c]  }|jj                   }}|j,                  jm                  |D cg c]*  }|jj                  |jT                  vr|jj                  |vr|, c}        jo                  |      }ddd       tq        jr                          t/        t1        |j,                        j2                        |_        t        j                  d j                  dju                  d |j,                  D                     |j,                  S # 1 sw Y   xY wc c}w c c}w # 1 sw Y   xY w)a  Gives the final, solved state of the environment.

        Args:
            update_modifier (UpdateModifier):
                An optional flag directing how updates are handled regarding packages already
                existing in the environment.

            deps_modifier (DepsModifier):
                An optional flag indicating special solver handling for dependencies. The
                default solver behavior is to be as conservative as possible with dependency
                updates (in the case the dependency already exists in the environment), while
                still ensuring all dependencies are satisfied.  Options include
                * NO_DEPS
                * ONLY_DEPS
                * UPDATE_DEPS
                * UPDATE_DEPS_ONLY_DEPS
                * FREEZE_INSTALLED
            prune (bool):
                If ``True``, the solution will not contain packages that were
                previously brought into the environment as dependencies but are no longer
                required as dependencies and are not user-requested.
            ignore_pinned (bool):
                If ``True``, the solution will ignore pinned package configuration
                for the prefix.
            force_remove (bool):
                Forces removal of a package without removing packages that depend on it.
            should_retry_solve (bool):
                Indicates whether this solve will be retried. This allows us to control
                whether to call find_conflicts (slow) in ssc.r.solve

        Returns:
            tuple[PackageRef]:
                In sorted dependency order from roots to leaves, the package references for
                the solved state of the environment.

        zFsolving prefix %s
  specs_to_remove: %s
  specs_to_add: %s
  prune: %ssscc              3  `   K   | ]$  t        fd j                  D              s & yw)c              3  @   K   | ]  }|j                          y wr9   match)r:   specrz   s     r<   r=   z5Solver.solve_final_state.<locals>.<genexpr>.<genexpr>W  s     M4::d+M   N)anyrV   )r:   rz   r_   s    @r<   r=   z+Solver.solve_final_state.<locals>.<genexpr>T  s-      M8L8LMM s   *.Nz Collecting package metadata (%s)zOunsuccessful initial attempt using frozen solve. Retrying with flexible solve.
zQunsuccessful attempt using repodata from %s, retrying with next repodata source.
zfailed
zSolving environment)fail_messager   z/solved prefix %s
  solved_linked_dists:
    %s
z
    c              3  <   K   | ]  }|j                           y wr9   )dist_strr~   s     r<   r=   z+Solver.solve_final_state.<locals>.<genexpr>  s     Id$--/Ir   );r   FREEZE_INSTALLEDr   r   rm   strlowerrn   r   rp   rq   logdebugrM   rV   rT   hasattrSolverStateContainerr   rs   rg   rP   solution_precsr
   r'   graphSPECS_SATISFIED_SKIP_SOLVEnextprefix_dataqueryrr   rZ   verbosequietjson_collect_all_metadatar   _remove_specs
_add_specscopyget_request_package_in_solution	specs_map_find_inconsistent_packages_run_satUPDATE_SPECSget_constrained_packagesindexkeyslendetermine_constricting_specsadd_back_mapsetrF   extend_post_sat_handlingr   
log_totalsr   )r_   rm   rn   ro   rp   rq   rs   retryingr   solutionr   r   r   pre_packagespost_packagesconstrainedorphan_precsrH   solution_prec_namess   `                  r<   r   zSolver.solve_final_state   s   Z _(G(GG"Od"%55O,S-A-G-G-IJOD #11M(]);)A)A)CDM%2d%:G!! 	 0<t/Cw++		 KK  		
 4'&"C DH((C"1C -C%7C" L  )++ .. H
 k(399:: ~HHH(()) ICOO11$7>I "+c.@.@"A"G"GHHuu2T5F5FFOO#JGMM(9J(l 6
 0056 /^5T5T"T*  +-0262C2CD 
 &L!5$5LL%	
 -	/ $$S)C//#&C!YYs'9'9:N??""CMML 2237C--$C @@""CMMM ""n&A&AA";; -1A {#a' + T99$@R@RST '#,,-.#**+, 
 8;7I7I&J!qvv&J#&J"")) ".666FF*==  ))#.C[-	/^ 	  "'C4F4F(G(M(MN		@KKMMIc6H6HII	
 !!!Y6 6n 'KK-	/ -	/s7   V'"E:V>V4/V>
/V9
9V>'V14
V>>Wc                   |D cg c]1  }|j                   j                   k(  st        |j                        3 c}d   }g }|D ]0  }t        fd|j                  D              s#|j                  D ]  }t        |      }|j                   j                   k(  s(|j                  5|j                  j                  sd|j                  j                  v sdd|j                  j                  v rf|j                  |j                  j                  D 	cg c]6  }	d|	j                  v r&|j                   t        |j                    d|	       f8 c}	       |j                  |j                   |f        3 |D 
cg c]!  }
|
d   j                  j                  |k  s |
# }}
t        |      dk(  ry t        dj                    d       |D ]  }t        |d    d	|d            t        d
       |S c c}w c c}	w c c}
w )Nr   c              3  @   K   | ]  }j                   |v s|  y wr9   rE   )r:   jr   s     r<   r=   z6Solver.determine_constricting_specs.<locals>.<genexpr>  s     =dii1n1=s   <, r*   z

Updating z is constricted by 
z -> requires z
If you are sure you want an update of your package either try `conda update --all` or install a specific version of the package you want using `conda install <pkg>=<version>`
)rF   r(   versionr   dependsr&   exact_valuer   r   tupappend
matcher_vor   print)r_   r   r   sphighest_versionconstrictingrz   depm_depvihard_constrictingconsts    `           r<   r   z#Solver.determine_constricting_specs  s   /=
)+DIIAUL$

 " 	DD=dll==<< DC%cNE

dii/!MM5"]]66#ASAS:S%--"4"44(// .3]]->->!"()'*aff} &*YY	UZZL!:M0N$O!" )//E0BC!D	D* $
qt||'>'>/'QA
 
  !Q&dii[(=>?& 	8EU1XJmE!H:67	8G	

 ! M
!"
s   G8G8;G=>!H Hc                   i }| j                   D ]  }|j                  }|D cg c]>  }|j                  |k(  r-|j                  !|j                  t        |j                        f@ c}||<   ||   j	                  |j                         D cg c]7  \  }}||k(  r-|j                  !|j                  t        |j                        f9 c}}        |S c c}w c c}}w r9   )rT   rF   r   r   r   items)	r_   r   r   requested_packagespkgupdate_pkg_requestr   kr   s	            r<   r   z&Solver.get_request_package_in_solution  s    $$ 	C!$ (666//AII4I QYY(612
 1299 !* 11..1993H VVS^,	  "!6s   AC<Cc                &   t               }d } ||      s ||      r|S | j                  D ]a  j                  j                  d      rt	        d |j                     D              }|t	        fd|D              k(  rV||k(  s\|hz  }c |S )Nc                T    | j                         D ]  \  }}t        |      dk(  s y y)Nr   TF)r   r   )r   r   r   s      r<   empty_package_listz;Solver.get_constrained_packages.<locals>.empty_package_list  s.    		  1q6Q;  rc   __c              3  &   K   | ]	  }|d      yw)r*   Nr6   r:   r   s     r<   r=   z2Solver.get_constrained_packages.<locals>.<genexpr>  s     !G1!A$!Gs   c              3  j   K   | ]*  }|j                   j                   k(  s|j                   , y wr9   rF   r   )r:   r   r   s     r<   r=   z2Solver.get_constrained_packages.<locals>.<genexpr>  s)      &3881C		&s   33)r   rT   rF   
startswithmax)r_   r   r   
index_keysupdate_constrainedr   current_versionr   s          @r<   r   zSolver.get_constrained_packages  s     U	 l+/A-/P%%$$ 
	DCxx""4(!!GSXX0F!GGO# &#-& #   L0);se)C&
	D "!rc   )module_namec                   |j                   rh | j                  | j                  }n|j                  j	                  |j
                         dD ]F  }||j                  vs|j                  j                  |d       s/t        |      |j                  |<   H i }t        |       |j                         D cg c]  }|j                   }}|D ])  }||j                  vst        |      |j                  |<   + |j                  j                         D ]}  }|j
                  r5t        |j                        t        j                  v s|j                  dk(  sD|j                  j	                  |j                  t        |j                        i        h | j                  | j                  |j
                  j!                         }| j#                  |      \  }	}
|j%                  |	|
       |S c c}w )N)anacondacondazconda-buildz
python.appconsole_shortcutpowershell_shortcutpypi)ro   rV   rT   r   updatespecs_from_history_mapr   r   r&   r+   r   rF   iter_recordsr   aggressive_update_packagessubdirvalues_prepareset_repository_metadata)r_   r   prepared_specspkg_namevirtual_pkg_indexpvirtual_pkgsvirtual_pkgs_namerz   r   r   s              r<   r   zSolver._collect_all_metadata  s   99Ht33Hd6G6GHN MM  !;!;<
 B 3==0S__5H5Hd6 /8.ACMM(+B !#)*;<,=,B,B,DEqAFFELE%1 T!$CMM97@AR7SCMM"34T 446 L 22 +w/Q/QQ{{f,MM(($))Ytyy5I)JK!L$%%"" ++224N ==0q##E1-
? Fs   8G1c           	     \   | j                   rd | j                   D        }t        t        j                  d |D                    }t	        |j
                  |j                  j                               }g g }| j                   D ]S  }t        j                  t        d|       |j                  |      }|rj                  |       C|j                  |       U t        fd|D              }|r$t        t        t        d |D                          D ]  }	t        |	j                   xs d      |z  }
|
r|	j"                  |j$                  v r|j                  j'                  |	j"                  t)        |	j"                              }t+        |j,                  j/                         D ci c]  \  }}|dk7  r|| c}}      |_        ||j                  |j"                  <   |j                  j1                  |	j"                  d         t        |j2                        |_        |S c c}}w )Nc              3  *   K   | ]  }d |v s|  ywtrack_featuresNr6   r:   r   s     r<   r=   z'Solver._remove_specs.<locals>.<genexpr>R  s       9IT9Q s   	c              3  >   K   | ]  }|j                  d         ywr   )get_raw_valuer   s     r<   r=   z'Solver._remove_specs.<locals>.<genexpr>V  s!      $=AD&&'78$s   z*using PrefixGraph to remove records for %sc              3  L   K   | ]  t        fd D              s  yw)c              3  @   K   | ]  }j                  |        y wr9   r   r:   recr   s     r<   r=   z1Solver._remove_specs.<locals>.<genexpr>.<genexpr>m  s     Js4::c?Jr   N)r   )r:   r   all_removed_recordss    @r<   r=   z'Solver._remove_specs.<locals>.<genexpr>j  s(      .J6IJJ .s    $c              3  2   K   | ]  }t        |        y wr9   r   r@   s     r<   r=   z'Solver._remove_specs.<locals>.<genexpr>q  s      KAQ Kr>   r6   features)rV   r   r   from_iterabler'   r   r   r   r   r   remove_specr   r   rP   r   sortedr
  rF   r   r   r&   r1   _match_componentsr   popr   )r_   r   _track_fts_specsfeature_namesr   no_removed_records_specsr   removed_recordsunmatched_specs_to_remover  rec_has_a_featurekeyvaluer  s                @r<   r   zSolver._remove_specsK  s    !%!5!5   ## $EU$ M
   2 2CMM4H4H4JKE"$')$,, 	: KTR"'"3"3D"9"'..?,33D9	: ). .4. )%
 )+& K1J KKL  + 6 %((:$;m$K!$S5O5O)O==,,SXXy7JKD-7 /3.D.D.J.J.L *U"j0  J.D* 04CMM$)),MM%%chh56" "'u{{!3C
s   +H(c                   j                   j                  j                  d      \  }rLt        fdj                  D              _        j                   j                  j                  d      \  }t        j                  t              r#t        j                  drt              nd       rt        t        d      t        j                         t        t              t        j                         D ]  }j                  j                  |j                  d       }||fj                   |j                  <   t#        |j                  |j%                               j                  |j                  <   |j                  dk(  s|s|j                  d<    t        fd	j                  D              _        S )
Nr6   c              3  V   K   | ]   }j                   j                  ||       " y wr9   )r   r   )r:   r   r   s     r<   r=   z5Solver._find_inconsistent_packages.<locals>.<genexpr>  s      &Wqsyy}}Q':&Ws   &)zinconsistent precs: %sNonez
            The environment is inconsistent, please check the package plan carefully
            The following packages are causing the inconsistency:filetargetpythonc              3  ,   K   | ]  }|vs|  y wr9   r6   )r:   rz   inconsistent_precss     r<   r=   z5Solver._find_inconsistent_packages.<locals>.<genexpr>  s      'tCU7U's   	)r   bad_installedr   rP   r   isEnabledForr   r   r   r   r   sysstderrr   r  rF   r   r&   r   )r_   r   rH   rz   r   r!  s    `   @r<   r   z"Solver._find_inconsistent_packages  sx   
 !$ 3 3C4F4F K "'&WCDVDV&W!WC$'EE$7$78J8JB$O!A!E"II(0B+, E
 ZZ (-.SZZ@* 3}}((D9/3Tl  + ,5TYYt}}+Wdii( 99(T.2CMM(+3 "' '!$!3!3' "C 
rc   c                   |j                  |j                        }d}|r|d   }|j                  j                  j                  |j                  g       D ]V  }|j                  |j                  kD  rd} n9|j                  |j                  k(  s:|j
                  |j
                  kD  sTd} n |r,t        |j                  j                  |j
                        S |S )NFr   T)r   build_number)r   rF   r   groupsr   r'  r&   )r_   r   r   installed_poolinstalled_prec
has_updaterz   s          r<   _package_has_updateszSolver._package_has_updates  s    '++DII6
+A.N((B7 	<<."8"88!%JLLN$:$::))N,G,GG!%J	  diiDDUDUV	
 	
rc   c                    |j                   sy|j                  t        j                  k7  ry|j                  }||vxr ||vxs |||   v }|S )NF)r   rm   r   r   rF   )r_   r   target_precconflict_specsexplicit_poolr)  r   no_conflicts           r<   _should_freezezSolver._should_freeze  se     ))."A"AA ##n4 
M)S[M(<S-S 	 rc   c           
         t        d j                  j                               j                  j	                   j
                        }j                  rd}n5j                  j                         D cg c]  }|j                          }}j                  j                  | j
                        xs
 t               }|D ch c]  }|j                   }}j                  j                         D ]d  \  }t        fdj                  D              }|s(t        |      dk7  r,t        t!        d      |t#        d |D        d      fz        |d	   }	|	j$                  r|	j                         j                  |<   t'        |      t(        j*                  v rt'        |      j                  |<   ŉ j-                  |	||      r|	j                         j                  |<   |j.                  v r7t'        j.                  |   |	j1                         
      j                  |<   =t'        ||	j1                         
      j                  |<   g t3               j4                  D ]  }
|
j                  |v s|
j                   j6                  vr1j8                  s%t'        |
d      j                  |
j                  <   [||
j                     j                  j	                  |
g      j;                  |
j                  t3                     z  r@t'        |
d      j                  |
j                  <   j=                  |
j                         t>        jA                  d|
        jB                  tD        jF                  k(  rj                  j                         D cg c]  }|j                  j                  vs| }}|D ]u  }|j                  |vr(|j                         j                  |j                  <   9t'        |j                  |j                         d      j                  |j                  <   w t>        jI                  dj                         jB                  tD        jJ                  k(  rj.                  rtM        fdj.                  D              _        j                  j                         D ]L  }|jN                  dk(  sj                  jQ                  |j                  t'        |j                        i       N nj                  j                         D ci c]Z  }|j                  |j                  d j4                  D        vrt'        |j                        nj                  |j                     \ c}_        njB                  tD        jR                  k(  rfdt         fd j
                  D              }j                  j                  t        d j                  jU                         D              |      }|xs dD ]  }|j                  j                  v st'        |d      j4                  vsj8                  sB|j                  j.                  vs[t'        |j                        j                  |j                  <    tW        d j                  D              }tW        d  j
                  D              }|r`|s]j                  j;                  d      }jB                  tD        jF                  k(  }d|vr!|r|j                         j                  d<   n j                  j;                  dt'        d            }|j;                  d      s%tY        |jZ                        dz   }t'        ||      }|ft         j
                        z   }j                  j                  | j
                        rW j\                  dk7  s! j^                  t`        k(  r*jb                  r|sj                  je                  |       ntg        i       |j                  d<   t(        jh                  sGt(        j*                  D ]4  j                  j                  v sj                  j                  <   6 j                  jQ                  fd j
                  D               dj                  v rtk         jl                  t(        jn                        rj                  j;                  d      }|rd |jZ                  z  }tW        d!  j
                  D              }j                  d   }j                  j;                  di       j;                  d      }|st'        ||      }t(        jp                  r|st'        d|d "      }|j                  d<   S c c}w c c}w c c}w c c}w )#Nc                    | j                   S r9   rE   xs    r<   r{   z#Solver._add_specs.<locals>.<lambda>  s
    166 rc   r6   c              3  F   K   | ]  }j                  |      s|  y wr9   r   )r:   rz   r   s     r<   r=   z$Solver._add_specs.<locals>.<genexpr>  s!      %tzz$7G%   !!r*   a  
                    Conda encountered an error with your environment.  Please report an issue
                    at https://github.com/conda/conda/issues.  In your report, please include
                    the output of 'conda info' and 'conda list' for the active environment, along
                    with the command you invoked that resulted in this error.
                      pkg_name: %s
                      spec: %s
                      matches_for_spec: %s
                    c              3  2   K   | ]  }t        |        y wr9   r	  r@   s     r<   r=   z$Solver._add_specs.<locals>.<genexpr>  s     %Gc!f%Gr>      )indentr   r  FoptionalzFpinned spec %s conflicts with explicit specs.  Overriding pinned spec.T)r  r=  zspecs_map with targets: %sc              3     K   | ]p  }t        |      j                  d  j                  D        vr|t        |      fn6t        |      j                  j                  t        |      j                     f r yw)c              3  4   K   | ]  }|j                     y wr9   rE   rG   s     r<   r=   z.Solver._add_specs.<locals>.<genexpr>.<genexpr>W  s     3UqAFF3UrI   N)r&   rF   pinned_specsr   )r:   r   r   s     r<   r=   z$Solver._add_specs.<locals>.<genexpr>U  so      %  !++3UCDTDT3UU 9T?+#D/..io>R>R0STU%s   A6A9r   c              3  4   K   | ]  }|j                     y wr9   rE   rG   s     r<   r=   z$Solver._add_specs.<locals>.<genexpr>c  s     ,NQVV,NrI   c                      j                   vxr- t         fdj                  D              xr j                   xs  j                   j                  v S )Nc              3  P   K   | ]  }j                   |j                   k(    y wr9   rE   )r:   rH   r6  s     r<   r=   z6Solver._add_specs.<locals>.<lambda>.<locals>.<genexpr>p  s     GAFFaff,Gs   #&)rF   r   r@  rp   r   )r6  pin_overridesr   s   `r<   r{   z#Solver._add_specs.<locals>.<lambda>m  sW    FF-/ .Gc6F6FGG.---8
 66S777 rc   c              3  T   K   | ]  } |      sj                  |       ! y wr9   )r,  )r:   rH   r)  r_   skipr   s     r<   r=   z$Solver._add_specs.<locals>.<genexpr>v  s/      !Aw ))#q.A!s   %(c              3  2   K   | ]  }t        |        y wr9   r%   rG   s     r<   r=   z$Solver._add_specs.<locals>.<genexpr>}  s     CqilCr>   c              3  :   K   | ]  }|j                   d k(    ywr  NrE   rG   s     r<   r=   z$Solver._add_specs.<locals>.<genexpr>  s     J!166X-J   c              3  :   K   | ]  }|j                   d k(    ywrI  rE   r@   s     r<   r=   z$Solver._add_specs.<locals>.<genexpr>  s     %TQaff&8%TrJ  r  r   .*r   installc              3  X   K   | ]!  }|j                   vs|j                   |f # y wr9   rE   )r:   rA   rD  s     r<   r=   z$Solver._add_specs.<locals>.<genexpr>  s)      
affM6QQVVQK
s   **r   z>=%sc              3  :   K   | ]  }|j                   d k(    yw)r   NrE   r@   s     r<   r=   z$Solver._add_specs.<locals>.<genexpr>  s      1*+AFFg%1rJ  )r   r  )9r   r   r   r   _get_package_poolrT   ro   to_match_specget_conflicting_specsrP   rF   r   r   r   r   r   r   r   ry   r&   r   r   r2  r   r   r   r@  rU   rp   r   addr   warnrm   r   r   r   
UPDATE_ALLdictr   r   r   r   r   r   r   rX   rZ   r   rs   find_conflictsr    offliner   rM   conda_prefixauto_update_conda) r_   r   r0  installed_specsrecordr/  r   r   matches_for_specr.  rA   rH   precsrz   rT   	conflictsconflictpy_in_prefixpy_requested_explicitlypython_prefix_recfreeze_installedpython_specpinned_versionspec_setconda_prefix_recversion_reqconda_requested_explicitly
conda_specconda_in_specs_to_add_versionr)  rD  rF  s    ``    `                      @@@r<   r   zSolver._add_specs  s\    !!13??3O3O3QR //0A0AB99 O 69__5Q5Q5S+1$$&O 
 EE''9J9JKVuw 	 1??$))??!mm113 )	NHd$ %!$!3!3%    '(A-$
 % $%G6F%GPQR $ /q1...9.G.G.ICMM(+x(G,N,NN.7.ACMM(+((nm^ /:.G.G.ICMM(+!;!;;.7228<*335/CMM(+
 /8 )=)=)?/CMM(+O)	V !! 	Avv&66!8!88ARAR,5a%,HCMM!&&)"166*SUU-D-DaS-I-M-MFFCE.  -6a%,HCMM!&&)!%%aff-HH2	, ."A"AA??779QVV3===XE   99N2/3/A/A/CCMM$)),/8		$*<*<*>0CMM$)),	 			.> .";";; )) $ % !$ : :	% !  OO88: PD{{f,,,dii4999M-NOP !$ < < >!  II99,NS=M=M,NN "$)), ]]49956!   N$?$??D ! !**! L 33CCMM,@,@,BCC\I &O L MMS]]2 "(T:#BRBRR,, S-G-GG3<X]]3KCMM(--0L Js7I7IJJ"%%T$BSBS%T"T 7 # 3 3H ="22n6U6UU~-2B*;*I*I*Kh' "mm//)H:MN"y1/0A0I0IJTQ # #,K"PK'>E$2C2C,DD55..x9J9JK}}	1))[8!$!7!7?O ,,X6044*5h' :: 499-/3CMM$)),4 	 
!%!2!2
 	
 cmm#DKKAUAU(V"227;$'7'?'??-0 1/3/@/@1 .* !]]73
030A0A'20N0R0R1- 5!*:{!KJ,,5O!*7KPT!UJ)3g&
q @JB!s   <gg3g#g#Ag(c           
        t        g j                  j                         j                        }j                  j                         D cg c]   }j                  j                  |      r|" }}|rt        |      t        j                  j                  t        |      | j                        xs g       }|rd}t        j                  t              r&t        j                  dt        d |D                     t        j                  j                               t!        fd|      }t!        fd|      }|j#                  d      r|j#                  dd      }	|j#                  dd      }
t        |	      t        | j                        z  t        |
      z
  }t%        t'        d |D              t'        d	 |
D ch c]  }| c}D              | j(                        |D ]  }|j*                  s|j,                  rd}|j/                  |       |j#                  d
      r"t1        |j2                  |j4                        }nt1        |j2                        }|j7                  |       |j                  |j2                  <    |r9t        j                  j                  t        |      | j                              }nn|rt        j                  t              r/t        j                  dt        t'        d |D                           |rt8        j:                  rLj                  j=                  t        |      | j                  j>                  j@                        _!        ntE        i       t        fdj                  jG                         D              | _$        jJ                  rjJ                  jG                         D ]f  \  }\  }}|rjB                  D cg c]  }|j2                  |k7  s| c}_!        jB                  jM                  |       |j7                  |       h |_'        S c c}w c c}w c c}w )NFzconflicting specs: %sc              3  <   K   | ]  }|j                   xs |  y wr9   r  r@   s     r<   r=   z"Solver._run_sat.<locals>.<genexpr>  s     FqQXX]]Fr   c                    | v S r9   r6   )rA   specs_map_sets    r<   r{   z!Solver._run_sat.<locals>.<lambda>  s    a=.@ rc   c                6    t        | d      j                  v S )NTr<  )r&   r@  )rA   r   s    r<   r{   z!Solver._run_sat.<locals>.<lambda>  s    )A59I9II rc   Tr6   c              3  <   K   | ]  }|j                           y wr9   __str__r@   s     r<   r=   z"Solver._run_sat.<locals>.<genexpr>
  s     M1199;Mr   c              3  <   K   | ]  }|j                           y wr9   rt  r@   s     r<   r=   z"Solver._run_sat.<locals>.<genexpr>  s     N1199;Nr   r   rM  zfinal specs to add: %sc              3  2   K   | ]  }t        |        y wr9   r	  r@   s     r<   r=   z"Solver._run_sat.<locals>.<genexpr>&  s     H1AHr>   )rT   history_specsrs   c              3     K   | ]=  \  }}|j                   v r*|j                  j                   |   j                  k  r| ? y wr9   )r   
strictness)r:   r   r   r   s      r<   r=   z"Solver._run_sat.<locals>.<genexpr>6  sH      $
1C...s99!<GGG $
s   AA)(r
   r   r   track_features_specsr   find_matchesr   r   rS  rP   rT   r   r#  r   r   r   r   r   r   r  rM   r  r=  remover&   rF   r   rT  r   unsatisfiable_hintssolver   rs   r   r    r   rW   r   r   final_environment_specs)r_   r   r  rA   absent_specsconflicting_specsspecs_modifiedgrouped_specsconflicting_pinned_specsin_specs_mappinned_conflictsin_specs_map_or_specs_to_addr   neutered_specrF   rz   rH   rq  s    `               @r<   r   zSolver._run_sat  s   ",%%'))#
 $'==#7#7#9WaASASTUAVWW'55  EE''-.0A0A  	
  "N&		+F4EFF   4 4 67M#$@BSTM
 (/I!($
 (++D1,00r:#;#?#?b#I %D,=,=(>>()0*, 6M0LMMN<L0Mq0MNNKK 
 * 	=;;t}}%)N+2248xx	*(1$))T\\(R(1$))(<+//>/<CMM$)),	= $'EE//568I8I%! g  l E"II(H0GHHI !G$?$?!$-.!..!88#&#9#9	 "- "C %R((# $
++-$
 
 &)&6&6&<&<&> 6"ltT  $'#5#5*4*C& &&--d3+//56 '>#
m Xh 1Nv*s    Q2Q		Q5Q
Qc           	     |	   j                   }j                  t        j                  k(  rt	        j
                  j                               }| j                  D ch c]  }|D ]  }|j                  |      r|  }}}||z  }| j                  D ch c]&  }j                  D ]  }|j                  |      r| ( }}}|D ch c]  }|j                   c}t	        fd|D              }||z  }|_
        nOj                  t        j                  k(  rPj                  t        j                  k7  r2t!        j                  | j                        }|j#                         }	t%        | j                        | _	        |	D ]R  }|j&                  D ]A  }
t)        |
      }
|
j                  j*                  vs'| j                  j-                  |
       C T t/        | j                        | _	        | j                  D ch c]  }|j                   c}t1        fd|	D              }t1        t!        g |j2                  t5        d |            j2                        _
        nj                  t        j                  k(  rt!        j                        }t%               }| j                  D ]D  }|j7                  |j                        }|j9                  d |j;                  |      D               F |D ci c]  }|t)        |       }}j<                  D ]  }|j?                  |j                  d          d|v r[j
                  jA                  d      }djC                  |jD                  jG                  d      d d       dz   }t)        d|      |d<   |j9                  | j                  D ci c]  }|j                  | c}       t1        |jI                               }|| _	        | jK                  t        jL                  j                  jN                  jP                  jR                  	      _
        d
_'        jN                  r@t!        j                  |      }|jO                          t1        |j2                        _
        S c c}}w c c}}w c c}w c c}w c c}w c c}w )Nc              3  >   K   | ]  }|j                   vr|  y wr9   rE   )r:   rz   remove_before_adding_backs     r<   r=   z,Solver._post_sat_handling.<locals>.<genexpr>i  s&      +99$== +s   c              3     K   | ]8  }|j                   vr(j                  j                  |j                   d        : y wr9   )rF   r   r   )r:   nodespecs_to_remove_namesr   s     r<   r=   z,Solver._post_sat_handling.<locals>.<genexpr>  s;      99$99 ##DIIt4s   >Ac              3  4   K   | ]  }|j                     y wr9   rE   )r:   
ancest_recs     r<   r=   z,Solver._post_sat_handling.<locals>.<genexpr>  s      $(2JOO$rI   r  .r   rL  r   )rm   rn   ro   rp   rq   F)*r  rn   r   NO_DEPSr
   r   r   rV   r   rT   r   rF   	ONLY_DEPSrm   r   UPDATE_DEPSr'   +remove_youngest_descendant_nodes_with_specsr   r   r&   r   rT  rR   rP   r   filterget_node_by_namer   all_ancestorsr@  r  r   r   r   splitr   r   r   ro   rp   rq   )r_   r   r  _no_deps_solutionr   rz   only_remove_theseonly_add_theser   removed_nodesr   add_backupdate_namesr  rF   r   
python_recpy_vernew_specs_to_addr  r  s    `                 @@r<   r   zSolver._post_sat_handlingO  sa   "%"="= 4 44 !+3??+G+G+I J !00!-! ::d# !! ! !22 !--.. ::d# N  @N(Nt(N% * +-+ !
 /!2C
 !7!77##~'A'AA   2 2D4E4EFE!MMOM #D$5$5 6D% 3<< 3C#C.Cxxs}}4))--c233 !*$*;*; <D <@;O;O$P4TYY$P! ) H
 "'CekkCF4,BCDJJ"C   N$>$>>   2 23E5L)) --dii8## $6;6I6I$6O$ 
 <HH4y.HIH (( /dii./9$ __00:
*"4"4":":3"?"CDtK&/Xv&N	(#$:K:KL$diioLM$Y%5%5%78 !1D!%!7!7 . ; ;!//ii!// -- "8 "C CI99 2 24KLEKKM!&u{{!3C
[! )OJ %Q: I Ms$   !R+R$	R*R/R4=R9c                   t         j                  rt         j                  ry t        t         j                        j                  dd       }|r|j                  j                  }|t        k(  rd}t        | dt               t        | j                  t         j                        rt        fd|D              ry t        t        j                   | j"                  | j$                  | j&                        d       }|rE|d   j(                  }t+        t-        d	t         d
| d| d| d	      t.        j0                         y y y )Nr   defaultsz::conda>c              3  @   K   | ]  }j                  |        y wr9   r   )r:   rz   conda_newer_specs     r<   r=   z0Solver._notify_conda_outdated.<locals>.<genexpr>  s     K'--d3Kr   )r`   c                ,    t        | j                        S r9   )r(   r   r5  s    r<   r{   z/Solver._notify_conda_outdated.<locals>.<lambda>  s    l1995 rc   r  zg

                ==> WARNING: A newer version of conda exists. <==
                  current version: z#
                  latest version: z`

                Please update conda by running

                    $ conda update -n base -c z conda

                Or to minimize the number of packages updated during conda update use

                     conda install conda=z

                r  )r   notify_outdated_condar   r/   rZ  r   channelcanonical_namer   r&   CONDA_VERSIONr   rM   r   r  r0   	query_allrN   rQ   rZ   r   r   r   r$  r%  )r_   ru   current_conda_prefix_recchannel_nameconda_newer_precslatest_versionr  s         @r<   rl   zSolver._notify_conda_outdated  s>   ,,#-g.B.B#C#G#GQU#V #3;;JJL.)  )L>-)QR4;;(<(<=K
KK &$$$MMLL $ 1 1	 6
! !!22!6!>!> $ %2? 3##1"2 3/ 0<n =* +9)9 :" %	 !/ $rc   c                   | j                   r'|| j                  k(  r| j                  | j                  fS t	        | d      rO| j                  rC|| _        t        | j                         t        | j                  | j                        | _        nt               }| j                  D ]0  }|j                  d      }|s|j                  t        |             2 | j                  j                  |       t        | j                  | j                  | j                   || j"                        }t        |       || _        || _        t        || j                        | _        d| _         | j                  | j                  fS )Nr[   )rN   r  T)r]   _prepared_specsr[   r\   r   r+   r)   rN   r   rT   get_exact_valuerT  r#   r   r,   rM   rQ   rZ   )r_   r   additional_channelsr   r  reduced_indexs         r<   r   zSolver._prepare  s/    >>n0D0DD;;''4"t{{#1D )$++6dkkDMMBDG #&%)) >..y9'++GG,<=	> MM  !45-!!M *-8#1D 'DKmdmmDDG{{DGG##rc   N)rM   r   rN   zIterable[Channel]rQ   zIterable[str]rT   Iterable[MatchSpec]rV   r  r`   r   returnz;tuple[tuple[PackageRecord, ...], tuple[PackageRecord, ...]])__name__
__module____qualname____doc__r   r   rb   rv   rj   r   r   r   r   r   r   r   r   r,  r2  r   r   r   rl   r   r6   rc   r<   r5   r5   :   sB    "$,./1&(( $( 	(
 *( -( (X  H
X  <( 
E<(@  @"D'!R"("2 x(: ):x;z x(+ )+Z
.$l\ x( )Bxt2h)$rc   r5   c                  d    e Zd Zd Zed        Zed        Zed        Zed        Zd Z	d Z
d Zy	)
r   c                    || _         || _        || _        || _        || _        || _        || _        d | _        d | _        i | _	        d | _
        | j                          i | _        d | _        y r9   )rm   rn   ro   rp   rq   rs   rM   r   r   r   r   _init_solution_precsr   r  )r_   rM   rm   rn   ro   rp   rq   rs   s           r<   rb   zSolverStateContainer.__init__-  sy    $  /*
*("4  
 "!!#'+$rc   c                ,    t        | j                        S r9   )r/   rM   r_   s    r<   r   z SolverStateContainer.prefix_dataX  s    $++&&rc   c                H    t        | j                        j                         S r9   )r!   rM   get_requested_specs_mapr  s    r<   r   z+SolverStateContainer.specs_from_history_map\  s    t{{#;;==rc   c                B    t        d t        j                  D              S )Nc              3  8   K   | ]  }t        |d z           yw)@Nr%   )r:   r6  s     r<   r=   z<SolverStateContainer.track_features_specs.<locals>.<genexpr>b  s     HAYq3w'Hs   )rP   r   r   r  s    r<   r{  z)SolverStateContainer.track_features_specs`  s    H1G1GHHHrc   c                H    | j                   rdS t        | j                        S )Nr6   )rp   get_pinned_specsrM   r  s    r<   r@  z!SolverStateContainer.pinned_specsd  s    ''rJ-=dkk-JJrc   c                "    ||c| _         | _        y r9   )r   r   )r_   r   r   s      r<   r   z,SolverStateContainer.set_repository_metadatah  s    "A
DFrc   c                    | j                   rt               | _        y t        | j                  j	                               | _        y r9   )ro   rP   r   r   r   r  s    r<   r  z)SolverStateContainer._init_solution_precsk  s/    ::"''D"'(8(8(E(E(G"HDrc   c                N    i | _         | j                          i | _        d | _        y r9   )r   r  r   r  r  s    r<   working_state_resetz(SolverStateContainer.working_state_resetr  s%    !!#'+$rc   N)r  r  r  rb   r   r   r   r{  r@  r   r  r  r6   rc   r<   r   r   )  sl    ),V ' ' > > I I K K&I,rc   r   c                (   t        | dd      }t        |      rHt        |      5 }d |j                         j	                         j                         D        }ddd       nd}t        d g t        j                  D              S # 1 sw Y   .xY w)z<Find pinned specs from file and return a tuple of MatchSpec.z
conda-metapinnedc              3  b   K   | ]'  }|r#|j                         j                  d       s| ) yw)#N)stripr   r   s     r<   r=   z#get_pinned_specs.<locals>.<genexpr>~  s.      QWWY11#6 s   -/Nr6   c              3  6   K   | ]  }t        |d         yw)Tr<  Nr%   r   s     r<   r=   z#get_pinned_specs.<locals>.<genexpr>  s"       	$&&s   )	r   r   openreadr  
splitlinesrP   r   pinned_packages)rM   pinfilef	from_files       r<   r  r  y  s    6<2Gg'] 	a)446I	 	 	 :g--:	:  	 	s   4BBr6   c           	     ,  	
 t        t              s&t        d      sJ d       t        d      sJ d       t        t        t	        |       j                               j                        |t        u rt        j                  n|}z
  z
  		
fd}|r(|D ]#  t        fdD        d       

sJ  |
       % t        d      t        fdD        d       }t        fd	D        d       }t        }|r?|r= ||j                         ||j                        k7  rd
 D        }|D ]
  
 |
        t        t        t        fd                  t        t        	fd            	t!              t!        	      fS )N__getitem__z&final_precs must support list indexing__sub__z'final_precs must support set differencec                T    j                  |        v rj                  |        y y r9   )rT  )r  ru   rz   previous_recordsrt   s    r<   _add_to_unlink_and_linkz;diff_for_unlink_link_precs.<locals>._add_to_unlink_and_link  s+    s##S! $rc   c              3  F   K   | ]  }j                  |      s|  y wr9   r   r  s     r<   r=   z-diff_for_unlink_link_precs.<locals>.<genexpr>  s     Gtzz#Gr8  r  c              3  F   K   | ]  }j                  |      s|  y wr9   r   r:   r  rf  s     r<   r=   z-diff_for_unlink_link_precs.<locals>.<genexpr>  s     CK,=,=c,BCr8  c              3  F   K   | ]  }j                  |      s|  y wr9   r   r  s     r<   r=   z-diff_for_unlink_link_precs.<locals>.<genexpr>  s     Mk6G6G6LMr8  c              3  \   K   | ]$  }|j                   t        j                  k(  s!| & y wr9   )noarchr$   r  )r:   r   s     r<   r=   z-diff_for_unlink_link_precs.<locals>.<genexpr>  s!     WQZEVEV9VqWs   ",,c                &    j                  |       S r9   r   )r6  r  s    r<   r{   z,diff_for_unlink_link_precs.<locals>.<lambda>  s    4D4J4J14M rc   r  c                &    j                  |       S r9   r  )r6  r   s    r<   r{   z,diff_for_unlink_link_precs.<locals>.<lambda>  s    [=N=Nq=Q rc   )
isinstancer
   r   r'   r/   r   r   r   r   rr   r   r&   r   r   reversedr  rP   )rM   r   rT   rr   r  prev_pythoncurr_pythongmmnoarch_python_precsru   rz   r  rf  r   rt   s    `       @@@@@@r<   r   r     s    k:.
 	43	4 
 
 	54	5 
 "+j.@.M.M.O"P"V"VW#2d#:  $k1L//J"   	*DGGNDK4#D)	* H%KC(CTK M{MtTK
!C##$K,?,?(@@W+W' 	*D#D)	* *MNOL F:3QRSJj 111rc   r  )Xr  
__future__r   r   r$  	itertoolsr   loggingr   r   os.pathr   textwrapr   typingr	   boltons.setutilsr
   genericpathr    r   r   r  auxlib.decoratorsr   
auxlib.ishr   base.constantsr   r   r   r   base.contextr   common.constantsr   r   	common.ior   r   r   common.iteratorsr   r   common.pathr   r   
exceptionsr   r   r    historyr!   models.channelr#   models.enumsr$   models.match_specr&   models.prefix_graphr'   models.versionr(   resolver)   r   r+   r,   linkr-   r.   r   r/   subdir_datar0   r1   ImportErrorauxlib.collectionr2   models.recordsr3   r  r   r5   r   r  r   r6   rc   r<   <module>r     s    ) "  
  $     '   + 0  W W " * 8 8 9 > 
  $ % ) - )  C 4 # #/% .l$ l$^'M, M,`, 	82
 A82{*  /./s   D D"!D"