
    *d3                        d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
mZ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mZ ddlmZ ddlmZ ddlmZmZ ddl m!Z! ddl"m#Z# 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/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5  ej6        de7           Z8 G d d          Z9 G d d          Z: G d d           Z;dS )!a)  
Solver-agnostic logic to compose the requests passed to the solver
and accumulate its results.

The state exposed to the solver is handled by two objects whose primary
function is to serve read-only information to the solver and its other helpers.

- ``SolverInputState``: fully solver agnostic. It handles:
    - The local state on disk, namely the prefix state. This includes the
      already installed packages in the prefix (if any), the explicit requests
      made in that prefix in the past (history), its pinned specs, packages
      configured as aggressive updates and others.
    - The runtime context, determined by the configuration file(s),
      `CONDA_*` environment variables, command line flags and the requested
      specs (if any).
- ``IndexHelper``: can be subclassed to add solver-specific logic
  (e.g. custom index building). It should, provide, at least, a method to
  query the index for the _explicit pool_ of packages for a given spec (e.g.
  its potential dependency tree). Note that the IndexHelper might need
  pieces of ``SolverInputState`` to build the index (e.g. installed packages,
  configured channels and subdirs...)

.. todo::

    Embed IndexHelper in SolverInputState?

Since ``conda`` follows an iterative approach to solve a request,
in addition the _input_ state, the Solver itself can store additional state
in a separate helper: the ``SolverOutputState`` object. This is meant to help
accumulate the following pieces of data:

- ``specs``: a mapping of package names to its corresponding ``MatchSpec``
  objects. These objects are passed to the actual Solver, hoping it will return
  a solution.
- ``records``: a mapping of package names to ``PackageRecord`` objects. It will
  end up containing the list of package records that will compose the final state
  of the prefix (the _solution_). Its default value is set to the currently installed
  packages in the prefix. The solver will alter this list as needed to accommodate
  the final solution.

If the algorithm was not iterative, the sole purpose of the solver would be to turn
the ``specs`` into ``records``. However, ``conda``'s logic will try to constrain the
solution to mimic the initial state as much as possible to reduce the amount of
changes in the prefix. Sometimes, the initial request is too constrained, which results
in a number of conflicts. These conflicts are then stored in the ``conflicts`` mapping,
which will determine which ``specs`` are relaxed in the next attempt. Additionally,
``conda`` stores other solve artifacts:

- ``for_history``: The explicitly requested specs in the command-line should end up
  in the history. Some modifier flags can affect how this mapping is populated (e.g.
  ``--update-deps``.)
- ``neutered``: Pieces of history that were found to be conflicting in the future and
  were annotated as such to avoid falling in the same conflict again.

The mappings stored in ``SolverOutputState`` are backed by ``TrackedMap`` objects,
which allow to keep the reasons _why_ those specs or records were added to the mappings,
as well as richer logging for each action.
    N)chain)PathLike)MappingProxyType)IterableMappingOptionalTypeUnion)
IndexedSet)
CondaError)NULL)dals)DepsModifierUpdateModifier)context)dashlist)get_major_minor_versionpaths_equal)_supplement_index_with_system)
PrefixData)get_pinned_specs)PackagesNotFoundErrorSpecsConfigurationConflictError)History)Channel	MatchSpec)PrefixGraph)PackageRecord   )EnumAsBools
TrackedMapzconda.c                   :    e Zd ZdZdee         dee         fdZdS )IndexHelpera+  
    The _index_ refers to the combination of all configured channels and their
    platform-corresponding subdirectories. It provides the sources for available
    packages that can become part of a prefix state, eventually.

    Subclass this helper to add custom repodata fetching if needed.
    specsreturnc                     t           N)NotImplementedError)selfr%   s     ;lib/python3.11/site-packages/conda_libmamba_solver/state.pyexplicit_poolzIndexHelper.explicit_poolf   s    !!    N)__name__
__module____qualname____doc__r   r   strr,    r-   r+   r$   r$   ]   sI         "8I#6 "8C= " " " " " "r-   r$   c                   .   e Zd ZdZej        ej        ej        ej	        ej
        ej        ej        ej        dZdZdej        ej        ddddddf	deeeef         deeeeef                           d	ee         d
ee         dee         dee         dee         dee         dee         dee         fdZd ZefdZedefd            Zedeee f         fd            Z!edeeef         fd            Z"edeeef         fd            Z#edeeef         fd            Z$edeeef         fd            Z%edeeef         fd            Z&edeeef         fd            Z'edefd            Z(edefd            Z)edefd            Z*edefd             Z+ede,fd!            Z-ede,fd"            Z.edefd#            Z/edefd$            Z0edefd%            Z1edefd&            Z2dee3         fd'Z4dee3         fd(Z5dee3         fd)Z6dS )*SolverInputStatea  
    Helper object to provide the input data needed to compute the state that will be
    exposed to the solver.

    Parameters
    ----------
    prefix
        Path to the prefix we are operating on. This will be used to expose
        ``PrefixData``, ``History``, pinned specs, among others.
    requested
        The MatchSpec objects required by the user (either in the command line or
        through the Python API).
    update_modifier
        A value of ``UpdateModifier``, which has an effect on which specs are added
        to the final list. The default value here must match the default value in the
        ``context`` object.
    deps_modifier
        A value of ``DepsModifier``, which has an effect on which specs are added
        to the final list. The default value here must match the default value in the
        ``context`` object.
    ignore_pinned
        Whether pinned specs can be ignored or not. The default value here must match
        the default value in the ``context`` object.
    force_remove
        Remove the specs without solving the environment (which would also remove their)
        dependencies. The default value here must match the default value in the
        ``context`` object.
    force_reinstall
        Uninstall and install the computed records even if they were already satisfied
        in the given prefix. The default value here must match the default value in the
        ``context`` object.
    prune
        Remove dangling dependencies that ended up orphan. The default value here must
        match the default value in the ``context`` object.
    command
        The subcommand used to invoke this operation (e.g. ``create``, ``install``, ``remove``...).
        It can have an effect on the computed list of records.
    _pip_interop_enabled
        Internal only. Whether ``PrefixData`` will also expose packages not installed by
        ``conda`` (e.g. ``pip`` and others can put Python packages in the prefix).
    )NOT_SETNO_DEPS	ONLY_DEPSSPECS_SATISFIED_SKIP_SOLVEFREEZE_INSTALLEDUPDATE_DEPSUPDATE_SPECS
UPDATE_ALL)anacondacondazconda-buildz
python.appconsole_shortcutpowershell_shortcutr3   NFprefix	requestedupdate_modifierdeps_modifierignore_pinnedforce_removeforce_reinstallprunecommand_pip_interop_enabledc                 "   || _         t          ||
          | _        |
| _        t	          |                                          | _        d t          |          D             | _        d t          j
        D             | _        i }t          |           d |D             | _        i | _        |D ] }t          |          }|| j        |j        <   !|                     d|          | _        |                     d|          | _        |                     d|          | _        |                     d|          | _        |                     d	|          | _        || _        |	| _        d
 | j        D             | _        |                                  d S )N)pip_interop_enabledc                     i | ]
}|j         |S r3   name.0specs     r+   
<dictcomp>z-SolverInputState.__init__.<locals>.<dictcomp>   s    MMMD	4MMMr-   c                     i | ]
}|j         |S r3   rO   rQ   s     r+   rT   z-SolverInputState.__init__.<locals>.<dictcomp>   s    #c#c#cDIt#c#c#cr-   c                     i | ]
}|j         |S r3   rO   rR   records     r+   rT   z-SolverInputState.__init__.<locals>.<dictcomp>   s    CCCfCCCr-   rD   rE   rF   rG   rH   c                 .    i | ]}|t          |          S r3   r   )rR   ps     r+   rT   z-SolverInputState.__init__.<locals>.<dictcomp>   s     RRR1q)A,,RRRr-   )rB   r   _prefix_datarK   r   get_requested_specs_map_historyr   _pinnedr   aggressive_update_packages_aggressive_updatesr   _virtual
_requestedr   rP   _default_to_context_if_null_update_modifier_deps_modifier_ignore_pinned_force_remove_force_reinstall_prune_command_DO_NOT_REMOVE_NAMES_do_not_remove_check_state)r*   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   virtualrS   s                r+   __init__zSolverInputState.__init__   s    &vCWXXX$8!??AAMM4DV4L4LMMM#c#c@b#c#c#c %g...CC7CCC 	. 	.DT??D)-DODI&& $ @ @!
 !
 #>>P]^^">>P]^^!==nl[[ $ @ @!
 !
  SR8QRRRr-   c                     | j                                         D ]N\  }}| j                            |          }|r-|                    |          st          |g|g| j                  OdS )zO
        Run some consistency checks to ensure configuration is solid.
        N)pinneditems	installedgetmatchr   rB   )r*   rP   pin_specrs   s       r+   rm   zSolverInputState._check_state   s~    
 #k//11 	\ 	\ND(**400I \	!:!: \5ykH:t{[[[	\ 	\r-   c                 j    |t           u rt          ||          n| j                            ||          S )zTObtain default value from the context if value is set to NULL; otherwise leave as is)r   getattr_ENUM_STR_MAPrt   )r*   rP   valuer   s       r+   rc   z,SolverInputState._default_to_context_if_null   s4    ).$ww%%%D<N<R<RSXZ_<`<``r-   r&   c                     | j         S )z
        A direct reference to the ``PrefixData`` object for the given ``prefix``.
        You will usually use this object through the ``installed`` property.
        )r[   r*   s    r+   prefix_datazSolverInputState.prefix_data   s       r-   c                 4    t          | j        j                  S )z
        This exposes the installed packages in the prefix. Note that a ``PackageRecord``
        can generate an equivalent ``MatchSpec`` object with ``.to_match_spec()``.
        )r   r}   _prefix_recordsr|   s    r+   rs   zSolverInputState.installed   s       0 @AAAr-   c                 *    t          | j                  S )z
        These are the specs that the user explicitly asked for in previous operations
        on the prefix. See :class:`History` for more details.
        )r   r]   r|   s    r+   historyzSolverInputState.history   s      ...r-   c                 V    | j         rt          i           S t          | j                  S )a  
        These specs represent hard constrains on what package versions can be installed
        on the environment. The packages here returned don't need to be already installed.

        If ``ignore_pinned`` is True, this returns an empty dictionary.
        )rF   r   r^   r|   s    r+   rq   zSolverInputState.pinned   s-      	(#B'''---r-   c                 *    t          | j                  S )z
        System properties exposed as virtual packages (e.g. ``__glibc=2.17``). These packages
        cannot be (un)installed, they only represent constrains for other packages. By convention,
        their names start with a double underscore.
        )r   ra   r|   s    r+   rn   zSolverInputState.virtual
  s      ...r-   c                 *    t          | j                  S )z
        Packages that the solver will always try to update. As such, they will never have an
        associated version or build constrain. Note that the packages here returned do not need to
        be installed.
        )r   r`   r|   s    r+   aggressive_updatesz#SolverInputState.aggressive_updates  s       8999r-   c                 *    t          | j                  S )z
        Packages that are protected by the solver so they are not accidentally removed. This list
        is not configurable, but hardcoded for legacy reasons.
        )r   rl   r|   s    r+   do_not_removezSolverInputState.do_not_remove  s       3444r-   c                 *    t          | j                  S )zT
        Packages that the user has explicitly asked for in this operation.
        )r   rb   r|   s    r+   rC   zSolverInputState.requested$  s    
  000r-   c                     | j         dk    S )z>
        True if the used subcommand was ``install``.
        installrj   r|   s    r+   is_installingzSolverInputState.is_installing-  s    
 }	))r-   c                     | j         dk    S )z=
        True if the used subcommand was ``update``.
        updater   r|   s    r+   is_updatingzSolverInputState.is_updating4      
 }((r-   c                     | j         dk    S )z=
        True if the used subcommand was ``create``.
        creater   r|   s    r+   is_creatingzSolverInputState.is_creating;  r   r-   c                     | j         dk    S )z=
        True if the used subcommand was ``remove``.
        remover   r|   s    r+   is_removingzSolverInputState.is_removingB  r   r-   c                 *    t          | j                  S )a  
        Use attribute access to test whether the modifier is set to that value

        >>> update_modifier = EnumAsBools(context.update_modifier)
        >>> update_modifier.UPDATE_SPECS
            True
        >>> update_modifier.UPDATE_DEPS
            False
        )r!   rd   r|   s    r+   rD   z SolverInputState.update_modifierK  s     40111r-   c                 *    t          | j                  S )a  
        Use attribute access to test whether the modifier is set to that value

        >>> deps_modifier = EnumAsBools(context.deps_modifier)
        >>> deps_modifier.NOT_SET
            True
        >>> deps_modifier.DEPS_ONLY
            False
        )r!   re   r|   s    r+   rE   zSolverInputState.deps_modifierX  s     4.///r-   c                     | j         S r(   )rf   r|   s    r+   rF   zSolverInputState.ignore_pinnedg  s    ""r-   c                     | j         S r(   )rg   r|   s    r+   rG   zSolverInputState.force_removek  s    !!r-   c                     | j         S r(   )rh   r|   s    r+   rH   z SolverInputState.force_reinstallo  s    $$r-   c                     | j         S r(   )ri   r|   s    r+   rI   zSolverInputState.prunes  s
    {r-   c              #     K   | j                                         D ]k}|                    d          }|rR|j        rG|j                            d          r-t          |j                            d          d                   }|V  ldS )a  
        Collect all channels added with the `channel::package=*` syntax. For now,
        we only collect those specifically requested by the user in the current command
        (same as conda), but we should investigate whether history keeps channels around
        too.
        channelzfile://z::r   N)rC   valuesget_exact_valueoriginal_spec_str
startswithr   split)r*   rS   r   s      r+   channels_from_specsz$SolverInputState.channels_from_specsy  s       N))++ 	 	D**955G ) Md.D.O.OPY.Z.Z M%d&<&B&B4&H&H&KLLG	 	r-   c              #   
  K   t                      }| j                                        D ]X}|j        j        s|j        j        r|j        j        dv r*|j        j        }||vr|                    |           |j        V  Yd S )N)@z	<develop>pypi)	setrs   r   r   authtokenrP   
subdir_urladd)r*   	seen_urlsrX   r   s       r+   channels_from_installedz(SolverInputState.channels_from_installed  s      EE	n++-- 	% 	%F~" fn&:  ~"&@@@ 2J**j)))n$$$	% 	%r-   c              #   R   K   t           j        rt          j        d          V  d S d S )Nz#https://repo.anaconda.com/pkgs/free)r   restore_free_channelr   from_urlr|   s    r+   maybe_free_channelz#SolverInputState.maybe_free_channel  s<      ' 	J"#HIIIIIII	J 	Jr-   )7r.   r/   r0   r1   r   r6   r7   r8   r   r9   r:   r;   r<   r=   ry   rk   r
   r2   bytesr   r   r   r   boolro   rm   r   rc   propertyr   r}   r   r   rs   r   rq   rn   r   r   rC   r   r   r   r   r!   rD   rE   rF   rG   rH   rI   r   r   r   r   r3   r-   r+   r5   r5   j   s       ( (V  ''!+&4&O*;%1&3$/	 	M @B4B4O0<0D(,',*/ %!%/3, ,c5(*+, HU3	>%:;<, ".1	,
  -,  ~, tn, "$, ~, #, 'tn, , , ,\\ \ \ @G a a a a !Z ! ! ! X! B73#56 B B B XB /i0 / / / X/ 	.Y/ 	. 	. 	. X	. /i0 / / / X/ :GCN$; : : : X: 5wsI~6 5 5 5 X5 173	>2 1 1 1 X1 *t * * * X* )T ) ) ) X) )T ) ) ) X) )T ) ) ) X) 
2 
2 
2 
2 X
2 
0{ 
0 
0 
0 X
0 #t # # # X# "d " " " X" % % % % X% t    X
Xg%6    %'): % % % %"JHW$5 J J J J J Jr-   r5   c                      e Zd ZdZdddddddedeeeef                  deeee	f                  deeeef                  deeeef                  d	eeeef                  fd
Z
d Zed             Zed             Zed             Zdedeeef         fdZdefdZd Zd Zd Zded         fdZed             ZdS )SolverOutputStatea  
    This is the main mutable object we will massage before passing the result of the computation
    (the ``specs`` mapping) to the solver. It will also store the result of the solve (in
    ``records``).

    Parameters
    ----------
    solver_input_state
        This instance provides the initial state for the output.
    specs
        Mapping of package names to ``MatchSpec`` objects that will override the initialization
        driven by ``solver_input_state`` (check ``._initialize_specs_from_input_state()`` for more
        details).
    records
        Mapping of package names to ``PackageRecord`` objects. If not provided, it will be
        initialized from the ``installed`` records in ``solver_input_state``.
    for_history
        Mapping of package names to ``MatchSpec`` objects. These specs will be written to
        the prefix history once the solve is complete. Its default initial value is taken from the
        explicitly requested packages in the ``solver_input_state`` instance.
    neutered
        Mapping of package names to ``MatchSpec`` objects. These specs are also written to
        the prefix history, as part of the neutered specs. If not provided, their default value is
        a blank mapping.
    conflicts
        If a solve attempt is not successful, conflicting specs are kept here for further
        relaxation of the version and build constrains. If not provided, their default value is a
        blank mapping.

    Notes
    -----
    Almost all the attributes in this object map package names (``str``) to ``MatchSpec``
    (_specs_ in short) objects. The only mapping with different values is ``records``, which
    stores ``PackageRecord`` objects. A quick note on these objects:

    * ``MatchSpec`` objects are a query language for packages, based on the ``PackageRecord``
      schema. ``PackageRecord`` objects is how packages that are already installed are
      represented. This is what you get from ``PrefixData.iter_records()``. Since they are
      related, ``MatchSpec`` objects can be created from a ``PackageRecord`` with
      ``.to_match_spec()``.
    * ``MatchSpec`` objects also feature fields like ``target`` and ``optional``. These are,
      essentially, used by the low-level classic solver (:class:`conda.resolve.Resolve`) to
      mark specs as items it can optionally play with to satisfy the solver constrains. A
      ``target`` marked spec is _soft-pinned_ in the sense that the solver will try to satisfy
      that but it will stop trying if it gets in the way, so you might end up a different
      version or build. ``optional`` seems to be in the same lines, but maybe the entire spec
      can be dropped from the request? The key idea here is that these two fields might not be
      directly usable by the solver, but it might need some custom adaptation. For example, for
      ``libmamba`` we might need a separate pool that can be configured as a flexible task. See
      more details in the first comment of ``conda.core.solve.classic.Solver._add_specs``
    N)r%   recordsfor_historyneutered	conflictssolver_input_stater%   r   r   r   r   c                r   || _         t          d          | _        |r| j                            |d           n(|j        r!| j                            |j        d           t          d          | _        |r| j                            |d           n|                                  t          d          | _        |r| j                            |d           n(|j        r!| j                            |j        d           t          d|pi d	
          | _	        t          d|pi d	
          | _
        d S )Nr   z,Initialized from explicitly passed argumentsreasonz-Initialized from installed packages in prefixr%   r   z6Initialized from requested specs in solver input stater   zFrom arguments)datar   r   )r   r"   r   r   rs   r%   "_initialize_specs_from_input_stater   rC   r   r   )r*   r   r%   r   r   r   r   s          r+   ro   zSolverOutputState.__init__  s    5G4>y4I4I 	L0^____) 	L",F     
 /9.A.A
 	6Je,Z[[[[335554>}4M4M 	##$R $      ) 	##",O $   
 2<hn"6F2
 2
 2

 3=yB8H3
 3
 3
r-   c                    | j         j        r| j                            | j         j        d           | j         j                                        D ]\  }}|| j         j        v r+| j                            |t          |          d           >|| j         j	        v r,| j                            |t          |          dd           x|j
        dk    r*| j                            |t          |          d           n0| j                            d	 | j         j        D             d
           | j         j        D ]-}| j                            |t          |          dd           .dS )z
        Provide the initial value for the ``.specs`` mapping. This depends on whether
        there's a history available (existing prefix) or not (new prefix).
        zAs in historyr   z#Installed and in aggressive updatesz(Installed and protected in do_not_removeF)r   	overwriter   z2Installed from PyPI; protect from indirect pruningc                 .    i | ]}|t          |          S r3   r   )rR   rP   s     r+   rT   zHSolverOutputState._initialize_specs_from_input_state.<locals>.<dictcomp>,  s     UUU4yUUUr-   z"Installed and no history availablezVirtual systemN)r   r   r%   r   rs   rr   r   r   r   r   subdirrn   )r*   rP   rX   s      r+   r   z4SolverOutputState._initialize_specs_from_input_state  s    "* "	Jd5=oVVV $ 7 A G G I I  f42EEEJNNioo6[ #     T4BBB JNN!$I"'	 #     ]f,, JNN!$S #   +8 JUU43J3TUUU;     +3 	\ 	\D JNN449IUZN[[[[	\ 	\r-   c                 r    t          t          | j                                                  j                  S )z
        Massage currently stored records so they can be returned as the type expected by the
        solver API. This is what you should return in ``Solver.solve_final_state()``.
        )r   r   r   r   graphr|   s    r+   current_solutionz"SolverOutputState.current_solution6  s+     +dl&9&9&;&;<<BCCCr-   c                 H    d | j                                         D             S )z/
        Specs that are _not_ virtual.
        c                 D    i | ]\  }}|                     d           ||S __r   rR   rP   rS   s      r+   rT   z0SolverOutputState.real_specs.<locals>.<dictcomp>C  s0    ]]]ztTtW[G\G\]d]]]r-   r%   rr   r|   s    r+   
real_specszSolverOutputState.real_specs>  s'    
 ^]TZ-=-=-?-?]]]]r-   c                 H    d | j                                         D             S )z)
        Specs that are virtual.
        c                 D    i | ]\  }}|                     d           ||S r   r   r   s      r+   rT   z3SolverOutputState.virtual_specs.<locals>.<dictcomp>J  s0    YYYztT4??SWCXCXYdYYYr-   r   r|   s    r+   virtual_specszSolverOutputState.virtual_specsE  s'    
 ZYTZ-=-=-?-?YYYYr-   indexr&   c                     | j         j        r|                                  n|                     |           |                                  | j        S )z
        Main method to populate the ``specs`` mapping. ``index`` is needed only
        in some cases, and only to call its method ``.explicit_pool()``.
        )r   r   _prepare_for_remove_prepare_for_add_prepare_for_solver%   )r*   r   s     r+   prepare_specszSolverOutputState.prepare_specsL  sU    
 ". 	)$$&&&&!!%(((!!!zr-   c           	         | j         }| j                                        D ]\  }fd| j                                        D             }|s.t          |          dk    r|                     |           |d         }|j        r0| j                            ||	                                d           ||j
        v r+| j                            |t          |          d           || j        vr1| j                            ||	                                d           ||j        v rK| j                            |t          |j        |         |                                          d	           X| j                            |t          ||                                          d
           t                      }|j        r9t          |                    |j                                                            }|j                                        D ]\  }t          d          }||j        v }	||j        v r |	s| j                            ||d           I|	r|j        |                                       r5d}
| j                            |||
           |                    |           d}
| j                            ||j        |         |
           ||v r| j                            ||d           t*                              d           
|j        j        r|j                                        D ]}\  }}|| j        v r@| j                            |t          ||	                                d          d           N| j                            ||	                                d           ~n|j        j        rX| j        j                                        }| j                            d           |j        r|j        D ]Y}||j        v r$| j                            |||         d           /| j                            |t          |          d           Z|j                                        D ]:\  }}|j        dk    r*| j                            |t          |          d           ;n|j        D ]Y}||j        v r$| j                            |||         d           /| j                            |t          |          d           Zn[|j        j        rO| j        D ]G}||j        vr<||j        vr3||j        vr*| j                            |t          |          d           Hd| j        v rd|j        vr| j        d         }d| j        vr<|j        j        r0| j                            d|	                                d           n| j                            dt          d                                        d           rd!}
n*d"}
tA          |j!                  d#z   }t          |$          | j                            d|
           tD          j#        sE|j
                                        D ]+\  }|| j        v r| j                            |d%           ,|j                                        D ]&\  }||vr| j                            |d&           'd'| j        v rd'|j        v rtI          |j%        tD          j&                  r|j        d'         }| j        d'         d(|j!         }                    d           s0t          |$          d)}
| j                            d'|
           tD          j'        rBd'|j        vr;t          d'|d*+          d,}
| j                            d'|
           d*S d*S d*S d*S d*S d*S )-a  
        This is the core logic for specs processing. In contrast with the ``conda remove``
        logic, this part is more intricate since it has to deal with details such as the
        role of the history specs, aggressive updates, pinned packages and the deps / update
        modifiers.

        Parameters
        ----------
        index
            Needed to query for the dependency tree of potentially conflicting
            specs.
        c                 >    g | ]}                     |          |S r3   )ru   )rR   rX   rS   s     r+   
<listcomp>z6SolverOutputState._prepare_for_add.<locals>.<listcomp>t  s+    ___DJJW]L^L^_f___r-   r    r   z Spec matches unmanageable recordr   z)Spec matches record in aggressive updatesz1Spec matches record in explicit pool for its name)targetzSpec matches record in historyzSpec matches recordF)optionalz#Pinned, installed and not requestedzXPinned, installed and requested; constraining request as pin because they are compatiblezqPinned, installed and requested; pin and request are conflicting, so adding user request due to higher precedencez>Pin matches one of the potential dependencies of user requestszEpinned spec %s conflicts with explicit specs. Overriding pinned spec.T)r   r   z/Relaxing installed because it caused a conflictzFreezing as installedz+Redefining from scratch due to --update-allz8Update all, with history, pinned: reusing existing entryzRUpdate all, with history, not pinned: adding spec from history with no constraintsr   zKUpdate all, with history: treat pip installed stuff as explicitly installedz6Update all, no history, pinned: reusing existing entryzRUpdate all, no history, not pinned: adding spec from installed with no constraintszRelaxed because conflictingpythonzHFreezing python due to business rule, freeze-installed, and no conflictsversionz2Leaving Python pinning as it was calculated so farz)Pinning Python to match installed version.*)r   zAggressive updates relaxationzExplicitly requested by userr?   z>=z;Pinning conda with version greater than currently installedN)r   r   zHPinning conda with version greater than currently installed, auto update)(r   r%   rr   r   r   len _raise_incompatible_spec_recordsis_unmanageabler   to_match_specr   r   r   r   dist_strrq   r,   rC   rs   ru   r   logwarnrD   r:   r=   _datacopyclearr   r<   rt   r   r   r   offliner   rB   conda_prefixauto_update_conda)r*   r   sisrP   record_matchesrX   pin_overridesr,   pinrC   r   	old_specsr   required_versionrS   s                 @r+   r   z"SolverOutputState._prepare_for_addX  s:	    % ***,, *	 *	JD$____4<3F3F3H3H___N! >""a''55dNKKK $A&F% 
&..009[      ///
)D//2]      T^++
((**N     
 $$ 
ck$/8I8IJJJ;      
)D1B1BCCCLa      : 	M 3 3CM4H4H4J4J K KLLM***,, &	 &	JD$D5111C-Is}$$Y$
tS1VWWWW !=&,,T22 M=  JNN4VN<<<!%%d++++[  JNN4t)<VNLLLL&& 
[      []a    / U	` # 3 3 5 5 
a 
af4>)) JNN!$v/C/C/E/EPTUUUP #     JNN4)=)=)?)?H_N````
a  + H	` 
(--//IJ$QRRR{ (  K  Dsz))
 %dO#] '     
 %dOO$? '     %(M$7$7$9$9  LD&}..
 %dOO$< '     M  Dsz))
 %dO#[ '     
 %dOO$< '      - 	`&  ` `
**CK//CM11JNN44A^N___ t|##(E(E\(+Ft~--#2E2V-
((**'      z~~h	(0C0CDD88I&& <QFFHF5fnEELG$T7;;;D 
xf===  	W!4::<< W W
d4:%%JNN46UNVVV ---// 	R 	RJD$=((
tT2PQQQ tz!!3=((CJ(<== ) ]7+F:g&D4FN4488I&& = /?@@@V
wV<<<( =WCM-I-I 2B4PPPc
wV<<<<< "!((((= =-I-Ir-   c                 R    | j                             | j        j        d           dS )z.Just add the user requested specs to ``specs``zAdding user-requested specsr   N)r%   r   r   rC   r|   s    r+   r   z%SolverOutputState._prepare_for_remove  s,     	
$1;Dabbbbbr-   c                       fd j                                         D             rGfdt           j         j        j                  D             }t          | j        j                  dS )a  
        Last part of the logic, common to addition and removal of packages. Originally,
        the legacy logic will also minimize the conflicts here by doing a pre-solve
        analysis, but so far we have opted for a different approach in libmamba: let the
        solver try, fail with conflicts, and annotate those as such so they are unconstrained.

        Now, this method only ensures that the pins do not cause conflicts.
        c                 P    g | ]"\  }}|j         j        v t          |          #S r3   )r   rq   r2   )rR   rP   rS   r*   s      r+   r   z8SolverOutputState._prepare_for_solve.<locals>.<listcomp>  s>     "
 "
 "
dt.555 II555r-   c                 6    g | ]}|vt          |          S r3   )r2   )rR   rS   conflicting_and_pinneds     r+   r   z8SolverOutputState._prepare_for_solve.<locals>.<listcomp>  s5       555 D		555r-   )requested_specspinned_specsrB   N)r   rr   r   r%   r   rC   r   rB   )r*   rC   r   s   ` @r+   r   z$SolverOutputState._prepare_for_solve  s    "
 "
 "
 "
"n2244"
 "
 "

 " 
	   !$*d.E.OPP  I
 2 )3.5   
	 
	r-   c                    | j         j        rzj        rsj                                        D ]R\  }}j                                        D ]3}|                    |          r| j        	                    |            n4S| j
        S j        j        r8j        s1j                                        D ]\  }}|j        vr n| j
        S j        r6fdj                                        D             }|rt          |          dS dS )z}
        Operations that do not need a solver at all and might result in returning early
        are collected here.
        c                 ,    g | ]\  }}|j         v|S r3   )rs   )rR   rP   rS   r   s      r+   r   z0SolverOutputState.early_exit.<locals>.<listcomp>  s0       #tCM@Y@Y@Y@Y@Yr-   N)r   r   rG   rC   rr   rs   r   ru   r   popr   rD   r9   r   )r*   rP   rS   rX   not_installedr   s        @r+   
early_exitzSolverOutputState.early_exit  sg   
 %? 	)s/ 	)!m1133  
d!m2244  Fzz&)) ((... ((9 	-#/ 	-!m1133 - -
ds},,E - ,, ? 	;   '*}':':'<'<  M  ;+M:::	; 	;; ;r-   solverSolverc           	         | j         }| j                            |j        d           | j                                        D ]N\  }}|j                            |          }|r-|j        |j        k     r| j	        
                    ||d           O|j        j        rt          |j                  }i }|j                                        D ];\  }}| j                                        D ]}|                    |          r|||<   <|j        r	|D ]}||= n|                                D ]
\  }}|||<   | j                            d           | j                            |d           nX|j        j        rq|j        j        sdt/          | j                                        |j                                                  }	|	                                }
g }|j        r=|
D ]9}|j        |j        vr|j        |j        v r|                    |j                   :nj|
D ]g}|j        D ]C}t9          |          }|j        | j        vr$d}| j        
                    |j        ||           D|                    |j                   h|D ]]}|j                            |          }|r| j        
                    ||d           <| j                            |j        d           ^n|j        j        rt=          d	          }t/          | j                                                  }	|j                                        D ]a\  }}|	                    |          }|	                     |          D ]1}|
                    |j        t9          |j                  d
           2b|j!                                        D ]\  }}|                    |dd           d|v rj|j        d         }d"                    |j#        $                    d          dd                   dz   }|
                    dt9          d|                     |                    |j        d           |j        r$d}tK          |&                                          }n#tK          |                                          }d}tO          j(        dd          5  |)                    |j*        |j+        |j,        ||d          -                    t\          j/        |j0        |j1        |j2        |j3                  }d |D             }ddd           n# 1 swxY w Y   | j                            d           | j                            |d           | j                            d           | j                            |d           d|_4        |j3        rt/          tK          | j                                                  | j                                                  }	|	3                                 | j                            d           | j                            d |	j5        D             d           dS dS )a2  
        These tasks are performed _after_ the solver has done its work. It essentially
        post-processes the ``records`` mapping.

        Parameters
        ----------
        solver_cls
            The class used to instantiate the Solver. If not provided, defaults to the one
            specified in the context configuration.

        Notes
        -----
        This method could be solver-agnostic  but unfortunately ``--update-deps`` requires a
        second solve; that's why this method needs a solver class to be passed as an argument.
        z(User requested specs recorded to historyr   z.Spec needs less strict constrains than historyz#Redefining records due to --no-depsz"Redefined records due to --no-depsz1Recording deps brought by --only-deps as explicitz1Restoring originally installed due to --only-depsz*Excluding from solution due to --only-depsupdate_deps_specsz New specs asked by --update-depsNz0Exclude pinned packages from --update-deps specsr   .   r   )rP   r   z5Add original requested specs on top for --update-depsr3   quietFrecursive_call_for_update_deps)rB   channelssubdirsspecs_to_addspecs_to_removerJ   )rD   rE   rF   rG   rI   c                     i | ]
}|j         |S r3   rO   rW   s     r+   rT   z0SolverOutputState.post_solve.<locals>.<dictcomp>y  s    EEE66;EEEr-   zRedefining due to --update-depszRedefined due to --update-depsPruningc                     i | ]
}|j         |S r3   rO   rW   s     r+   rT   z0SolverOutputState.post_solve.<locals>.<dictcomp>  s     O O Of O O Or-   Pruned)6r   r   r   rC   r%   rr   r   rt   
strictnessr   r   rE   r7   dictrs   r   r   ru   r   r   r8   rD   r;   r   +remove_youngest_descendant_nodes_with_specsrP   appenddependsr   r   r"   get_node_by_nameall_ancestorsrq   joinr   r   listkeysr   	_override	__class__rB   r	  r
  solve_final_stater   r<   re   rF   rG   rI   ri   r   )r*   r  r   rP   rS   history_specoriginal_stateonly_change_theserX   r   would_remove	to_remove
dependencyr   rs   	new_specsancestorr   r  r  r   s                        r+   
post_solvezSolverOutputState.post_solve  s   " %
 	6`aaa ***,, 	 	JD$;??400L ,2I I I!!$'W "    $ L	 "#-00N "!m1133 9 9
d"l1133 9 9Fzz&)) 928)$/9  2- - -D&t,,- %6$;$;$=$= 2 2LD&+1N4((L&KLLLL7[\\\\( t	1D1P t	   3 3 5 5s}7K7K7M7MNNE !LLNNL I 2* 2 2F{#-77FK3=<X<X $$V[1111	2 + 2 2F&,n Q Q
(449DJ66%XF ,00D0PPP$$V[1111! 	 	M--d33	 L$$i0c %     L$$,X %    	  , F	 ##677I 3 3 5 566E!m1133  
d//55 % 3 3F ; ;  HMM !(-00A "     "j..00  
d$'Y      9$$x0((6>#7#7#<#<RaR#@AADHh	x(Q(Q(QRRR&]      %!"&y~~'7'7"8"8#I$4$4$6$677"$"7E22 F F !**!=#_"N!-$3< +   $#$2$?"%"4"%"3!$!1) $    FEWEEE%F F F F F F F F F F F F F F F( L&GHHHL0PQQQ""*K"LLL##I6V#WWW CJ 9 	bT\%8%8%:%: ; ;TZ=N=N=P=PQQEKKMMMLi000L O O5; O O OX`aaaaa		b 	bs   A-UUUc                 v    t          t          d| j         d|  dt          |d           d                    )z>Raise an error if something is very wrong with the environmentaw  
                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: z
                spec: z#
                matches_for_spec:    )indentz
                )r   r   rP   r   )rS   r   s     r+   r   z2SolverOutputState._raise_incompatible_spec_records  si     
  9    $,GA#>#>#>  
 

 
 	
r-   )r.   r/   r0   r1   r5   r   r   r2   r   r   ro   r   r   r   r   r   r$   r   r   r   r   r   r	   r&  staticmethodr   r3   r-   r+   r   r     s       2 2p 489=9=6:7;-
 -
 -
 --
 Y/0	-

 '#}"456-
 gc9n56-
 73	>23-
 GCN34-
 -
 -
 -
^0\ 0\ 0\d D D XD ^ ^ X^ Z Z XZ
; 
73	>3J 
 
 
 
a=k a= a= a= a=R	c c c
  L; ; ;B}bh }b }b }b }b~ 
 
 \
 
 
r-   r   )<r1   logging	itertoolsr   osr   typesr   typingr   r   r   r	   r
   boltons.setutilsr   r?   r   conda.auxlibr   conda.auxlib.ishr   conda.base.constantsr   r   conda.base.contextr   conda.common.ior   conda.common.pathr   r   conda.core.indexr   conda.core.prefix_datar   conda.core.solver   conda.exceptionsr   r   conda.historyr   conda.models.channelr   conda.models.match_specr   conda.models.prefix_graphr   conda.models.recordsr   modelsr!   r"   	getLoggerr.   r   r$   r5   r   r3   r-   r+   <module>rB     s  9 9z              " " " " " " ; ; ; ; ; ; ; ; ; ; ; ; ; ; ' ' ' ' ' '             ! ! ! ! ! ! = = = = = = = = & & & & & & $ $ $ $ $ $ B B B B B B B B : : : : : : - - - - - - - - - - - - S S S S S S S S ! ! ! ! ! ! ( ( ( ( ( ( - - - - - - 1 1 1 1 1 1 . . . . . . + + + + + + + +g+++,,
" 
" 
" 
" 
" 
" 
" 
"qJ qJ qJ qJ qJ qJ qJ qJh	}
 }
 }
 }
 }
 }
 }
 }
 }
 }
r-   