o
    Vh0                     @  s   d dl mZ d dl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	 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 erdd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ eeZG dd dZ dS )    )annotationsN)TYPE_CHECKING)Any)Config)PackageFilterPolicy)ConsoleMessage)PoetryRuntimeError)HTTPRepository)get_highest_priority_hash_type)Wheel)Version)Package)Link)RepositoryPool)Envc                   @  sP   e Zd ZdZ	d%d&ddZd'ddZd(ddZd)ddZd*d d!Zd+d#d$Z	dS ),ChooserzH
    A Chooser chooses an appropriate release archive for packages.
    Npoolr   envr   configConfig | NonereturnNonec                 C  sF   || _ || _|pt | _t| jdg | _t| jdg | _d S )Nzinstaller.no-binaryzinstaller.only-binary)	_pool_envr   create_configr   get_no_binary_policy_only_binary_policy)selfr   r   r    r    o/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/poetry/installation/chooser.py__init__#   s   
zChooser.__init__packager   r   c           	        s  g }t  }d}d}d} D ]_}|d7 }|jrEj js.td|j j |d7 }qt	|j
jsEtd|j ||j q|jdv rRtd|j q|jrjj jsjtd|j j |d7 }q|| q|s{ ||||t| fdd	d
}|S )zM
        Return the url of the selected archive for a given package.
        r      zGSkipping wheel for %s as requested in no binary policy for package (%s)zESkipping wheel %s as this is not supported by the current environment>   .egg.exe.msi.rpm.srpmz$Skipping unsupported distribution %szWSkipping source distribution for %s as requested in only binary policy for package (%s)c                   s     | S N)	_sort_key)linkr#   r   r    r!   <lambda>i   s    z$Chooser.choose_for.<locals>.<lambda>)key)set
_get_linksis_wheelr   allowsnameloggerdebugfilenamer   is_supported_by_environmentr   addextis_sdistr   append_no_links_found_errormax)	r   r#   linksunsupported_wheels
links_seenwheels_skippedsdists_skippedr,   chosenr    r-   r!   
choose_for0   sR   

zChooser.choose_forrA   intrB   rC   r@   set[str]r   c           	   
   C  s  g }d| d}|dkr|d| d7 }|dkr |d| d7 }|r,|dt | d7 }|t|  |rS|tdd	d
td|d	d
ddtdd	d
g7 }d}|jrd|jrd|d|j d7 }|td|j	 d|j	 d| d
dd td| |dS )Nz(This is likely not a Poetry issue.

  - z. candidate(s) were identified for the package
r     - zE wheel(s) were skipped due to your <c1>installer.no-binary</> policy
zU source distribution(s) were skipped due to your <c1>installer.only-binary</> policy
z^ wheel(s) were skipped as your project's environment does not support the identified abi tags
z}The following wheel(s) were skipped as the current project environment does not support them due to abi compatibility issues.Tr6   
warningzIf you would like to see the supported tags in your project environment, you can execute the following command:

    <c1>poetry debug tags</>  ()zMake sure the lockfile is up-to-date. You can try one of the following;

    1. <b>Regenerate lockfile: </><fg=yellow>poetry lock --no-cache --regenerate</>
    2. <b>Update package     : </><fg=yellow>poetry update --no-cache z=</>

If neither works, please first check to verify that the z; has published wheels available from your configured sourcezx that are compatible with your environment- ie. operating system, architecture (x86_64, arm64 etc.), python interpreter.	Solutionsinfoz+Unable to find installation candidates for )reasonmessages)lenr<   r   stripjoinindentwrapsource_typesource_referencer4   make_sectionr   )	r   r#   rA   rB   rC   r@   rR   rP   source_hintr    r    r!   r=   m   s`   zChooser._no_links_found_error
list[Link]c                 C  s  |j r|jd us
J | j|j}n| jds| jjd }n| jd}||}dd |jD }|s6|S g }g }dd |D }|D ]N}|jsN|	| qCd }	|
|j  }
rmt|
|j }rm| d|j|  }	n
t|trw||}	|	|vr|	|j|	f td|j|	 qC|	| qC|r|sd|j d	|j d
}ddd |D }ddd |D }tdtd| d| ddg}t|||S )Npypir   c                 S     h | ]}|d  qS hashr    .0fr    r    r!   	<setcomp>       z%Chooser._get_links.<locals>.<setcomp>c                 S  s   h | ]	}| d d qS ):r   )splitrb   hr    r    r!   rd      s    rf   z8Skipping %s as %s checksum does not match expected valuez Downloaded distributions for <b>rM   z9)</> did not match any known checksums in your lock file.rJ   c                 s  s&    | ]\}}d | d| dV  qdS )rH   (rN   Nr    )rb   r,   ri   r    r    r!   	<genexpr>   s   $ z%Chooser._get_links.<locals>.<genexpr>c                 s  s    | ]}d | V  qdS )rH   Nr    rh   r    r    r!   rk      s    a  <options=bold>Causes:</>
  - invalid or corrupt cache either during locking or installation
  - network interruptions or errors causing corrupted downloads

<b>Solutions:</>
  1. Try running your command again using the <c1>--no-cache</> global option enabled.
  2. Try regenerating your lock file using (<c1>poetry lock --no-cache --regenerate</>).

If any of those solutions worked, you will have to clear your caches using (<c1>poetry cache clear --all CACHE_NAME</>).z&Poetry retrieved the following links:
z4

The lockfile contained only the following hashes:
TrI   )rX   rY   r   
repositoryhas_repositoryrepositoriesfind_links_for_packagefileshashesr<   intersectionkeysr
   r7   
isinstancer	   calculate_sha256r5   r6   pretty_namepretty_versionrU   r   r   )r   r#   rl   r?   locked_hashesselected_linksskippedlocked_hash_namesr,   	link_hash
candidates	hash_namerQ   link_hashesknown_hashesrR   r    r    r!   r1      sf   



	
zChooser._get_linksr,   3tuple[int, int, int, Version, tuple[Any, ...], int]c                 C  s   d}d}|j rIt|j}|| jst|j d|| jjp"d }|jdurHt	
d|j}|s:td|j | }t|d |d f}n	t| jj}	|	 }t| ||}
t|j }|
|||j||fS )a#  
        Function to pass as the `key` argument to a call to sorted() to sort
        InstallationCandidates by preference.
        Returns a tuple such that tuples sorting as greater using Python's
        default comparison operator are more preferred.
        The preference is as follows:
        First and foremost, candidates with allowed (matching) hashes are
        always preferred over candidates without matching hashes. This is
        because e.g. if the only candidate with an allowed hash is yanked,
        we still want to use that candidate.
        Second, excepting hash considerations, candidates that have been
        yanked (in the sense of PEP 592) are always less preferred than
        candidates that haven't been yanked. Then:
        If not finding wheels, they are sorted by version only.
        If finding wheels, then the sort order is by version, then:
          1. existing installs
          2. wheels ordered via Wheel.support_index_min(self._supported_tags)
          3. source archives
        If prefer_binary was set, then all wheels are sorted above sources.
        Note: it was considered to embed this logic into the Link
              comparison operators, but then different sdist links
              with the same version, would have to be considered equal
        r    r   z@ is not a supported wheel for this platform. It can't be sorted.Nz^(\d+)(.*)$zUnable to parse build tag: r$   )r2   r   r7   r8   r   RuntimeErrorget_minimum_supported_indexsupported_tags	build_tagrematch
ValueErrorgroupsrF   rS   !_is_link_hash_allowed_for_packageyankedversion)r   r#   r,   r   binary_preferencewheelprir   build_tag_groupssupport_numhas_allowed_hash
yank_valuer    r    r!   r+      s6   


zChooser._sort_keyboolc                 C  s:   |j sdS dd |j  D }dd |jD }t||@ S )NTc                 S  s   h | ]\}}| d | qS )rf   r    )rb   r4   ri   r    r    r!   rd   7  s    z<Chooser._is_link_hash_allowed_for_package.<locals>.<setcomp>c                 S  r^   r_   r    ra   r    r    r!   rd   8  re   )rq   itemsrp   r   )r   r,   r#   r   rx   r    r    r!   r   3  s
   z)Chooser._is_link_hash_allowed_for_packager*   )r   r   r   r   r   r   r   r   )r#   r   r   r   )r#   r   rA   rF   rB   rF   rC   rF   r@   rG   r   r   )r#   r   r   r\   )r#   r   r,   r   r   r   )r,   r   r#   r   r   r   )
__name__
__module____qualname____doc__r"   rE   r=   r1   r+   r   r    r    r    r!   r      s    

=
D
E=r   )!
__future__r   loggingr   typingr   r   poetry.config.configr   r   poetry.console.exceptionsr   r   #poetry.repositories.http_repositoryr	   poetry.utils.helpersr
   poetry.utils.wheelr   poetry.core.constraints.versionr   poetry.core.packages.packager   poetry.core.packages.utils.linkr   #poetry.repositories.repository_poolr   poetry.utils.envr   	getLoggerr   r5   r   r    r    r    r!   <module>   s(    
