
    Vh{[                       d Z ddlmZ ddlZddlZej                  r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mZ dd
lmZ ddlmZmZ 	 ddlmZ ddlmZ  ed      Z ed      Z  ejB                   ee            Z" G d de      Z# G d de#      Z$ G d de#      Z% G d de%      Z& G d de%      Z'd Z( e(       Z)y# e$ r  G d d      ZdZY }w xY w)z Requirement provider interfaces.    )annotationsN)ConcreteArtifactsManager)MultiGalaxyAPIProxy)	GalaxyAPI)get_signature_from_source)	CandidateRequirement)is_pre_releasemeets_requirements)string_types)SemanticVersionLooseVersion)AbstractProvider)__version__c                      e Zd Zy)r   N)__name__
__module____qualname__     ^/home/dcms/DCMS/lib/python3.12/site-packages/ansible/galaxy/dependency_resolution/providers.pyr   r   "   s    r   r   z0.0.0z0.5.3z1.1.0c                  N    e Zd ZdZ	 	 	 	 	 	 ddZd Zd Zd Zd Zd Z	d	 Z
d
 Zy) CollectionDependencyProviderBasez<Delegate providing a requirement interface for the resolver.Nc                    || _         t        j                  t        j                  |      | _        t        |xs d      | _        || _        || _	        || _
        || _        y)aU  Initialize helper attributes.

        :param api: An instance of the multiple Galaxy APIs wrapper.

        :param concrete_artifacts_manager: An instance of the caching \
                                           concrete artifacts manager.

        :param with_deps: A flag specifying whether the resolver \
                          should attempt to pull-in the deps of the \
                          requested requirements. On by default.

        :param with_pre_releases: A flag specifying whether the \
                                  resolver should skip pre-releases. \
                                  Off by default.

        :param upgrade: A flag specifying whether the resolver should \
                        skip matching versions that are not upgrades. \
                        Off by default.

        :param include_signatures: A flag to determine whether to retrieve \
                                   signatures from the Galaxy APIs and \
                                   include signatures in matching Candidates. \
                                   On by default.
        )art_mgrr   N)
_api_proxy	functoolspartialr	   from_requirement_dict_make_req_from_dictset_preferred_candidates
_with_deps_with_pre_releases_upgrade_include_signatures)selfapisconcrete_artifacts_managerpreferred_candidates	with_depswith_pre_releasesupgradeinclude_signaturess           r   __init__z)CollectionDependencyProviderBase.__init__1   s^    D #,#4#4--.$
  &))=)C%D"#"3#5 r   c                    |j                   S )ap  Given requirement or candidate, return an identifier for it.

        This is used to identify a requirement or candidate, e.g.
        whether two requirements should have their specifier parts
        (version ranges or pins) merged, whether two candidates would
        conflict with each other (because they have same name but
        different versions).
        )canonical_package_id)r'   requirement_or_candidates     r   identifyz)CollectionDependencyProviderBase.identify^   s     (<<<r   c                    t         )a  Return sort key function return value for given requirement.

        This result should be based on preference that is defined as
        "I think this requirement should be resolved first".
        The lower the return value is, the more preferred this
        group of arguments is.

        resolvelib >=0.5.3, <0.7.0

        :param resolution: Currently pinned candidate, or ``None``.

        :param candidates: A list of possible candidates.

        :param information: A list of requirement information.

        Each ``information`` instance is a named tuple with two entries:

          * ``requirement`` specifies a requirement contributing to
            the current candidate list

          * ``parent`` specifies the candidate that provides
            (depended on) the requirement, or `None`
            to indicate a root requirement.

        resolvelib >=0.7.0, < 0.8.0

        :param identifier: The value returned by ``identify()``.

        :param resolutions: Mapping of identifier, candidate pairs.

        :param candidates: Possible candidates for the identifier.
            Mapping of identifier, list of candidate pairs.

        :param information: Requirement information of each package.
            Mapping of identifier, list of named tuple pairs.
            The named tuples have the entries ``requirement`` and ``parent``.

        resolvelib >=0.8.0, <= 1.0.1

        :param identifier: The value returned by ``identify()``.

        :param resolutions: Mapping of identifier, candidate pairs.

        :param candidates: Possible candidates for the identifer.
            Mapping of identifier, list of candidate pairs.

        :param information: Requirement information of each package.
            Mapping of identifier, list of named tuple pairs.
            The named tuples have the entries ``requirement`` and ``parent``.

        :param backtrack_causes: Sequence of requirement information that were
            the requirements that caused the resolver to most recently backtrack.

        The preference could depend on a various of issues, including
        (not necessarily in this order):

          * Is this package pinned in the current resolution result?

          * How relaxed is the requirement? Stricter ones should
            probably be worked on first? (I don't know, actually.)

          * How many possibilities are there to satisfy this
            requirement? Those with few left should likely be worked on
            first, I guess?

          * Are there any known conflicts for this requirement?
            We should probably work on those with the most
            known conflicts.

        A sortable value should be returned (this will be used as the
        `key` parameter of the built-in sorting function). The smaller
        the value is, the more preferred this requirement is (i.e. the
        sorting function is called with ``reverse=False``).
        NotImplementedErrorr'   argskwargss      r   get_preferencez/CollectionDependencyProviderBase.get_preferencej   s    X "!r   c                X     t         fd|D              rt        d      S t        |      S )Nc              3  :   K   | ]  }|j                   v   y wN)r"   ).0	candidater'   s     r   	<genexpr>zCCollectionDependencyProviderBase._get_preference.<locals>.<genexpr>   s$      
 T777
s   z-inf)anyfloatlen)r'   
candidatess   ` r   _get_preferencez0CollectionDependencyProviderBase._get_preference   s.     
!+
 
 = :r   c                    t         )a;  Find all possible candidates satisfying given requirements.

        This tries to get candidates based on the requirements' types.

        For concrete requirements (SCM, dir, namespace dir, local or
        remote archives), the one-and-only match is returned

        For a "named" requirement, Galaxy-compatible APIs are consulted
        to find concrete candidates for this requirement. If there's a
        pre-installed candidate, it's prepended in front of others.

        resolvelib >=0.5.3, <0.6.0

        :param requirements: A collection of requirements which all of \
                             the returned candidates must match. \
                             All requirements are guaranteed to have \
                             the same identifier. \
                             The collection is never empty.

        resolvelib >=0.6.0

        :param identifier: The value returned by ``identify()``.

        :param requirements: The requirements all returned candidates must satisfy.
            Mapping of identifier, iterator of requirement pairs.

        :param incompatibilities: Incompatible versions that must be excluded
            from the returned list.

        :returns: An iterable that orders candidates by preference, \
                  e.g. the most preferred candidate comes first.
        r5   r7   s      r   find_matchesz-CollectionDependencyProviderBase.find_matches   s    D "!r   c                    |d   }|j                   }d}|dz  }t               } j                  sM|j                  dk(  r> j                  D ch c](  j                   |k(  rt         fd|D              r* }}	 |rg n j                  j                  |      }|j                  rz|D ]I  \  }	}
d| d|	 d	t        |	       d
| }t        |	t              st        |      |	dk7  s>	 t        |	       K |D 	cg c]  \  }	}t        ||	||j                  d         c}}	S g }g }g }t        d |D              }|rC|D ch c]7  }|j                   r)|j"                  j%                  d      j'                         9 c}n	t               }|D ]  \  }	}t        ||	|dd       }|D ]  } j)                  ||      }|s 0t+        |j"                        xr% |xr!  j,                  xs |j                  xs |	|v  }|r p j.                  sf|j1                  |j2                  xs g          j.                  r!|D ]  }|j5                  t7        |              |j5                  t        ||	|dt9        |                    |j;                  d d       |s^ j                  D ch c]H  j                   |k(  r7t         fd|D              r" j                  rt        fd|D              rJ }}t=        |      |z   S c c}w # t        $ r$}|j                  rt        d| d|       | d }~ww xY w# t        $ r}t        |      |d }~ww xY wc c}}	w c c}w c c}w )Nr   zlA SemVer-compliant version or '*' is required. See https://semver.org to learn how to compose it correctly. z%This is an issue with the collection.galaxyc              3  B   K   | ]  }j                  |        y wr=   is_satisfied_byr>   requirementr?   r'   s     r   r@   zACollectionDependencyProviderBase._find_matches.<locals>.<genexpr>   s     a[D((i@a   z*Invalid version found for the collection 'z'. z': z (z). *c              3  :   K   | ]  \  }}t        |         y wr=   )r
   )r>   candidate_version_src_servers      r   r@   zACollectionDependencyProviderBase._find_matches.<locals>.<genexpr>*  s&      1
.!; 0111
s   =c                D    t        | j                        | j                  fS r=   )r   versrc)r?   s    r   <lambda>z@CollectionDependencyProviderBase._find_matches.<locals>.<lambda>z  s    	.	# r   T)keyreversec              3  B   K   | ]  }j                  |        y wr=   rK   rM   s     r   r@   zACollectionDependencyProviderBase._find_matches.<locals>.<genexpr>  s     e,,[)DerO   c              3  t   K   | ]/  }t        |j                        t        j                        k   1 y wr=   )r   rV   )r>   latestr?   s     r   r@   zACollectionDependencyProviderBase._find_matches.<locals>.<genexpr>  s)     w^dOFJJ7?9==;YYws   58)fqcnr!   r%   typer"   allr   get_collection_versions	TypeErroris_concrete_artifact
ValueError
isinstancer   r   r   rA   	is_pinnedrV   lstripstriprL   r
   r$   r&   extendsignature_sourcesappendr   	frozensetsortlist)r'   requirements	first_reqr^   version_reqpreinstalled_candidatesr?   coll_versionsexcversionreq_srcversion_errex_none_src_serverlatest_matches
signaturesextra_signature_sources"discarding_pre_releases_acceptablerN   &all_pinned_requirement_version_numbers
src_servertmp_candidatecandidate_satisfies_requirement&should_disregard_pre_release_candidateextra_sources   `     `                  r   _find_matchesz.CollectionDependencyProviderBase._find_matches   s    !O	~~ E>> #&%}}8!;+/+E+E''>>T)aT`aa '# '
		"9Bt?f?fgp?qM ))
 %2 >  J9+UXY`Xaacdhipdqcrru  wB  vC  D "'<8$[11^>'0#>. 2?-G- $)99>>4P 
 
"$-0 1
2?1
 .
*$ 0  ,
2
 $$ OO""3'--/
2
 69U 	/ $1 9	GZ%dGZ4PM+ 6262F2F3/ 7& #=#4#45 : // M(==M"&LL' 72 : //'..{/L/L/RPRS]6b ++(? S"))*CL*QRS%%dGZ9ZCXYo9	v 	 	 	 	
 '+/+E+E''>>T) eXdee MMwhvww '# ' +,~==q'  	-- @3{m\ 	@ & >(52=>"
2
^'sI   -L?L +L8=#M<M&AM 	L5L00L58	MMMc                    |j                   s|j                   s|j                  dk(  ryt        |j                  |j                        S )a  Whether the given requirement is satisfiable by a candidate.

        :param requirement: A requirement that produced the `candidate`.

        :param candidate: A pinned candidate supposedly matchine the \
                          `requirement` specifier. It is guaranteed to \
                          have been generated from the `requirement`.

        :returns: Indication whether the `candidate` is a viable \
                  solution to the `requirement`.
        rP   T)ru   ro   )
is_virtualrV   r   )r'   rN   r?   s      r   rL   z0CollectionDependencyProviderBase.is_satisfied_by  s@      &&$$3&!MM$
 	
r   c           	         | j                   j                  |      }| j                  s|j                  sg S |j	                         D cg c]  \  }}| j                  ||d       c}}S c c}}w )zGet direct dependencies of a candidate.

        :returns: A collection of requirements that `candidate` \
                  specifies as its dependencies.
        )nameru   )r   get_collection_dependenciesr#   r   itemsr    )r'   r?   req_mapdep_namedep_reqs        r   get_dependenciesz1CollectionDependencyProviderBase.get_dependencies  sj     //==iH y';';I &-]]_
!' $$h7%KL
 	
 
s   	A+)NNTFFT)r   r   r   __doc__r/   r3   r:   rE   rG   r   rL   r   r   r   r   r   r   .   sG    F
 (,!%##+6Z
=L"\	""Hh>T
6
r   r   c                      e Zd Zd Zd Zy)CollectionDependencyProvider050c                $    | j                  |      S r=   )r   )r'   ro   s     r   rG   z,CollectionDependencyProvider050.find_matches  s    !!,//r   c                $    | j                  |      S r=   rE   r'   
resolutionrD   informations       r   r:   z.CollectionDependencyProvider050.get_preference      ##J//r   Nr   r   r   rG   r:   r   r   r   r   r     s    00r   r   c                      e Zd Zd Zd Zy)CollectionDependencyProvider060c                    | j                  t        ||               D cg c]  t        fd||   D              s c}S c c}w )Nc              3  P   K   | ]  }j                   |j                   k(    y wr=   )rV   )r>   incompatmatchs     r   r@   z?CollectionDependencyProvider060.find_matches.<locals>.<genexpr>  s     _XuyyHLL0_s   #&)r   rn   rA   )r'   
identifierro   incompatibilitiesr   s       `r   rG   z,CollectionDependencyProvider060.find_matches  sO      $11$|J7O2PQ
_ARS]A^__ 
 	
 
s    Ac                $    | j                  |      S r=   r   r   s       r   r:   z.CollectionDependencyProvider060.get_preference  r   r   Nr   r   r   r   r   r     s    
0r   r   c                      e Zd Zd Zy)CollectionDependencyProvider070c                <    | j                  t        ||               S r=   rE   rn   )r'   r   resolutionsrD   r   s        r   r:   z.CollectionDependencyProvider070.get_preference      ##DJ)?$@AAr   Nr   r   r   r:   r   r   r   r   r         Br   r   c                      e Zd Zd Zy)CollectionDependencyProvider080c                <    | j                  t        ||               S r=   r   )r'   r   r   rD   r   backtrack_causess         r   r:   z.CollectionDependencyProvider080.get_preference  r   r   Nr   r   r   r   r   r     r   r   r   c                     t         t        d      k\  rt        S t         t        d      k\  rt        S t         t        d      k\  rt        S t
        S )Nz0.8.0z0.7.0z0.6.0)RESOLVELIB_VERSIONr   r   r   r   r   r   r   r   _get_providerr     sA    _W55.._W55.._W55..**r   )*r   
__future__r   r   typingtTYPE_CHECKING3ansible.galaxy.collection.concrete_artifact_managerr   *ansible.galaxy.collection.galaxy_api_proxyr   ansible.galaxy.apir   ansible.galaxy.collection.gpgr   0ansible.galaxy.dependency_resolution.dataclassesr   r	   /ansible.galaxy.dependency_resolution.versioningr
   r   ansible.module_utils.sixr   ansible.utils.versionr   r   
resolvelibr   r   resolvelib_versionImportErrorRESOLVELIB_LOWERBOUNDRESOLVELIB_UPPERBOUNDfrom_loose_versionr   r   r   r   r   r   r   CollectionDependencyProviderr   r   r   <module>r      s    ' "  ?? O, C 2 ?!+< (0 '0 7_77EW8XY ]
'7 ]
B0&F 0
0&F 
0B&E BB&E B+  - w  !  !	!s   C
 
CC