B
    lz]FC                 @   s   d dl 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mZ ddlmZ ddlmZ dd	lmZ eZeZG d
d deZG dd deZG dd deZG dd deZdS )    )absolute_importdivisionprint_functionunicode_literals   )NULL)PackageCacheData)
PrefixData)DepsModifierSolver)UpdateModifier)
SubdirData)Channelc               @   sZ   e Zd ZdZdddZeeeeefddZeeeeedfdd	Zeeeeedfd
dZdS )r   aB  
    **Beta** While in beta, expect both major and minor changes across minor releases.

    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             C   s   t |||||| _dS )a  
        **Beta**

        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.

        N)_Solver	_internal)selfprefixchannelssubdirsZspecs_to_addZspecs_to_remover   r   (lib/python3.7/site-packages/conda/api.py__init__"   s    zSolver.__init__c             C   s   | j |||||S )a  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Gives the final, solved state of the environment.

        Args:
            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.

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

        )r   solve_final_state)r   update_modifierdeps_modifierpruneignore_pinnedforce_remover   r   r   r   6   s    "zSolver.solve_final_stateFc             C   s   | j ||||||S )a1  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        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.

        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.

        )r   solve_for_diff)r   r   r   r   r   r   force_reinstallr   r   r   r   [   s    zSolver.solve_for_diffc             C   s   | j ||||||S )a  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        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`.

        Returns:
            UnlinkLinkTransaction:

        )r   solve_for_transaction)r   r   r   r   r   r   r   r   r   r   r    }   s    zSolver.solve_for_transactionN)r   r   r   )	__name__
__module____qualname____doc__r   r   r   r   r    r   r   r   r   r      s   
$!r   c               @   s>   e Zd ZdZdd Zdd ZedddZd	d
 Zdd Z	dS )r   z
    **Beta** While in beta, expect both major and minor changes across minor releases.

    High-level management and usage of repodata.json for subdirs.
    c             C   s    t |}|jstt|| _dS )a  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Args:
            channel (str or Channel):
                The target subdir for the instance. Must either be a url that includes a subdir
                or a :obj:`Channel` that includes a subdir. e.g.:
                    * 'https://repo.anaconda.com/pkgs/main/linux-64'
                    * Channel('https://repo.anaconda.com/pkgs/main/linux-64')
                    * Channel('conda-forge/osx-64')
        N)r   ZsubdirAssertionError_SubdirDatar   )r   Zchannelr   r   r   r      s    
zSubdirData.__init__c             C   s   t | j|S )a  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Run a query against this specific instance of repodata.

        Args:
            package_ref_or_match_spec (PackageRef or MatchSpec or str):
                Either an exact :obj:`PackageRef` to match against, or a :obj:`MatchSpec`
                query object.  A :obj:`str` will be turned into a :obj:`MatchSpec` automatically.

        Returns:
            Tuple[PackageRecord]

        )tupler   query)r   package_ref_or_match_specr   r   r   r(      s    zSubdirData.queryNc             C   s   t t| ||S )a$  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Run a query against all repodata instances in channel/subdir matrix.

        Args:
            package_ref_or_match_spec (PackageRef or MatchSpec or str):
                Either an exact :obj:`PackageRef` to match against, or a :obj:`MatchSpec`
                query object.  A :obj:`str` will be turned into a :obj:`MatchSpec` automatically.
            channels (Iterable[Channel or str] or None):
                An iterable of urls for channels or :obj:`Channel` objects. If None, will fall
                back to context.channels.
            subdirs (Iterable[str] or None):
                If None, will fall back to context.subdirs.

        Returns:
            Tuple[PackageRecord]

        )r'   r&   	query_all)r)   r   r   r   r   r   r*      s    zSubdirData.query_allc             C   s
   | j  S )a0  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Returns:
            Iterable[PackageRecord]: A generator over all records contained in the repodata.json
                instance.  Warning: this is a generator that is exhausted on first use.

        )r   iter_records)r   r   r   r   r+      s    	zSubdirData.iter_recordsc             C   s   | j  | _ | S )a  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Update the instance with new information. Backing information (i.e. repodata.json)
        is lazily downloaded/loaded on first use by the other methods of this class. You
        should only use this method if you are *sure* you have outdated data.

        Returns:
            SubdirData

        )r   reload)r   r   r   r   r,      s    zSubdirData.reload)NN)
r!   r"   r#   r$   r   r(   staticmethodr*   r+   r,   r   r   r   r   r      s   r   c               @   sd   e Zd ZdZdd ZefddZdd Zedd	d
Z	dd Z
edd ZedddZdd ZdS )r   z
    **Beta** While in beta, expect both major and minor changes across minor releases.

    High-level management and usage of package caches.
    c             C   s   t || _dS )z
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Args:
            pkgs_dir (str):
        N)_PackageCacheDatar   )r   pkgs_dirr   r   r   r      s    zPackageCacheData.__init__c             C   s   | j ||S )a  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Args:
            package_ref (PackageRef):
                A :obj:`PackageRef` instance representing the key for the
                :obj:`PackageCacheRecord` being sought.
            default: The default value to return if the record does not exist. If not
                specified and no record exists, :exc:`KeyError` is raised.

        Returns:
            PackageCacheRecord

        )r   get)r   package_refdefaultr   r   r   r0     s    zPackageCacheData.getc             C   s   t | j|S )a  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Run a query against this specific package cache instance.

        Args:
            package_ref_or_match_spec (PackageRef or MatchSpec or str):
                Either an exact :obj:`PackageRef` to match against, or a :obj:`MatchSpec`
                query object.  A :obj:`str` will be turned into a :obj:`MatchSpec` automatically.

        Returns:
            Tuple[PackageCacheRecord]

        )r'   r   r(   )r   r)   r   r   r   r(     s    zPackageCacheData.queryNc             C   s   t t| |S )aN  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Run a query against all package caches.

        Args:
            package_ref_or_match_spec (PackageRef or MatchSpec or str):
                Either an exact :obj:`PackageRef` to match against, or a :obj:`MatchSpec`
                query object.  A :obj:`str` will be turned into a :obj:`MatchSpec` automatically.
            pkgs_dirs (Iterable[str] or None):
                If None, will fall back to context.pkgs_dirs.

        Returns:
            Tuple[PackageCacheRecord]

        )r'   r.   r*   )r)   	pkgs_dirsr   r   r   r*   %  s    zPackageCacheData.query_allc             C   s
   | j  S )a5  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Returns:
            Iterable[PackageCacheRecord]: A generator over all records contained in the package
                cache instance.  Warning: this is a generator that is exhausted on first use.

        )r   r+   )r   r   r   r   r+   9  s    	zPackageCacheData.iter_recordsc             C   s   | j jS )z
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Indicates if the package cache location is writable or read-only.

        Returns:
            bool

        )r   is_writable)r   r   r   r   r4   D  s    zPackageCacheData.is_writablec             C   s   t t| jS )a  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Get an instance object for the first writable package cache.

        Args:
            pkgs_dirs (Iterable[str]):
                If None, will fall back to context.pkgs_dirs.

        Returns:
            PackageCacheData:
                An instance for the first writable package cache.

        )r   r.   first_writabler/   )r3   r   r   r   r5   Q  s    zPackageCacheData.first_writablec             C   s   | j  | _ | S )a  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Update the instance with new information. Backing information (i.e. contents of
        the pkgs_dir) is lazily loaded on first use by the other methods of this class. You
        should only use this method if you are *sure* you have outdated data.

        Returns:
            PackageCacheData

        )r   r,   )r   r   r   r   r,   c  s    zPackageCacheData.reload)N)N)r!   r"   r#   r$   r   r   r0   r(   r-   r*   r+   propertyr4   r5   r,   r   r   r   r   r      s   	r   c               @   sH   e Zd ZdZdd ZefddZdd Zdd	 Ze	d
d Z
dd ZdS )r	   z
    **Beta** While in beta, expect both major and minor changes across minor releases.

    High-level management and usage of conda environment prefixes.
    c             C   s   t || _dS )z
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Args:
            prefix_path (str):
        N)_PrefixDatar   )r   Zprefix_pathr   r   r   r   z  s    zPrefixData.__init__c             C   s   | j |j|S )a  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Args:
            package_ref (PackageRef):
                A :obj:`PackageRef` instance representing the key for the
                :obj:`PrefixRecord` being sought.
            default: The default value to return if the record does not exist. If not
                specified and no record exists, :exc:`KeyError` is raised.

        Returns:
            PrefixRecord

        )r   r0   name)r   r1   r2   r   r   r   r0     s    zPrefixData.getc             C   s   t | j|S )a  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Run a query against this specific prefix instance.

        Args:
            package_ref_or_match_spec (PackageRef or MatchSpec or str):
                Either an exact :obj:`PackageRef` to match against, or a :obj:`MatchSpec`
                query object.  A :obj:`str` will be turned into a :obj:`MatchSpec` automatically.

        Returns:
            Tuple[PrefixRecord]

        )r'   r   r(   )r   r)   r   r   r   r(     s    zPrefixData.queryc             C   s
   | j  S )a  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Returns:
            Iterable[PrefixRecord]: A generator over all records contained in the prefix.
                Warning: this is a generator that is exhausted on first use.

        )r   r+   )r   r   r   r   r+     s    	zPrefixData.iter_recordsc             C   s   | j jS )a\  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Indicates if the prefix is writable or read-only.

        Returns:
            bool or None:
                True if the prefix is writable.  False if read-only.  None if the prefix
                does not exist as a conda environment.

        )r   r4   )r   r   r   r   r4     s    zPrefixData.is_writablec             C   s   | j  | _ | S )a  
        **Beta** While in beta, expect both major and minor changes across minor releases.

        Update the instance with new information. Backing information (i.e. contents of
        the conda-meta directory) is lazily loaded on first use by the other methods of this
        class. You should only use this method if you are *sure* you have outdated data.

        Returns:
            PrefixData

        )r   r,   )r   r   r   r   r,     s    zPrefixData.reloadN)r!   r"   r#   r$   r   r   r0   r(   r+   r6   r4   r,   r   r   r   r   r	   s  s   	r	   N)Z
__future__r   r   r   r   Zcommon.constantsr   Zcore.package_cache_datar   r.   Zcore.prefix_datar	   r7   Z
core.solver
   Z_DepsModifierr   r   r   Z_UpdateModifierZcore.subdir_datar   r&   Zmodels.channelr   objectr   r   r   r   <module>   s    Z 