
    th                    
   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
mZ d dlmZ d dlmZmZmZmZ d dlmZmZ d dlmZ dd	lmZmZmZmZ dd
lmZ  ej>                  e       Z!ddZ" G d d      Z# G d de      Z$y)    )annotationsN)IteratorSequence)Optional)InvalidWheelFilenameNormalizedNamecanonicalize_nameparse_wheel_filename)BaseDistributionBaseEnvironment)WHEEL_EXTENSION   )BadMetadataBasePathget_dist_canonical_nameget_info_location)Distributionc                   | j                  t              syt        j                  j	                  |       sy	 t        t        j                  j                  |              t        j                  |       S # t        $ r Y yw xY w)NF)
endswithr   ospathisfiler
   basenamer   zipfile
is_zipfile)locations    KD:\jyotish\venv\Lib\site-packages\pip/_internal/metadata/importlib/_envs.py_looks_like_wheelr      si    _-77>>(#RWW--h78 h''   s   (A5 5	B Bc                  l    e Zd ZdZeej                  j                  ee	   f   Z
ddZddZd	dZd	dZy)
_DistributionFindera$  Finder to locate distributions.

    The main purpose of this class is to memoize found distributions' names, so
    only one distribution is returned for each package name. At lot of pip code
    assumes this (because it is setuptools's behavior), and not doing the same
    can potentially cause a distribution in lower precedence path to override a
    higher precedence one if the caller is not careful.

    Eventually we probably want to make it possible to see lower precedence
    installations as well. It's useful feature, after all.
    c                "    t               | _        y N)set_found_names)selfs    r   __init__z_DistributionFinder.__init__7   s    14    c              #  l  K   t        |      ryt        j                  j                  |g      D ]I  }t	        |      }	 t        |      }|| j                  v r)| j                  j                  |       ||f K y# t        $ r+}t        j                  d||j                         Y d}~|d}~ww xY ww)z!Find distributions in a location.N)r   zSkipping %s due to %s)r   	importlibmetadatadistributionsr   r   r   loggerwarningreasonr$   add)r%   r   distinfo_locationnamees         r   
_find_implz_DistributionFinder._find_impl:   s     
 X& &&448*4ED-d3M.t4 t(((!!$'%% F  6qxxPs.   <B4A=
3B4=	B1!B,'B4,B11B4c              #  ~   K   | j                  |      D ]%  \  }}|d}n|j                  }t        |||       ' yw)ziFind distributions in a location.

        The path can be either a directory, or a ZIP archive.
        N)r4   parentr   )r%   r   r0   r1   installed_locations        r   findz_DistributionFinder.findO   sH     
 $(??8#<D-$6:"%2%9%9"t]4FGG $=s   ;=c              #    K   t        j                  |      }|j                         sy|j                         D ]  }|j                  dk7  r|j                         5 }d |D        }t        d |D        d      }ddd       sKt        |j                  |            }| j                  |      D ]  \  }}	t        ||	|         y# 1 sw Y   QxY ww)a  Read location in egg-link files and return distributions in there.

        The path should be a directory; otherwise this returns nothing. This
        follows how setuptools does this for compatibility. The first non-empty
        line in the egg-link is read as a path (resolved against the egg-link's
        containing directory if relative). Distributions found at that linked
        location are returned.
        Nz	.egg-linkc              3  <   K   | ]  }|j                           y wr"   )strip.0lines     r   	<genexpr>z<_DistributionFinder.find_legacy_editables.<locals>.<genexpr>k   s     4!$!s   c              3  &   K   | ]	  }|s|  y wr"    r<   s     r   r?   z<_DistributionFinder.find_legacy_editables.<locals>.<genexpr>l   s     "BEDT4Es    )pathlibPathis_diriterdirsuffixopennextstrjoinpathr4   r   )
r%   r   r   childflines
target_reltarget_locationr0   r1   s
             r   find_legacy_editablesz)_DistributionFinder.find_legacy_editables[   s      ||H%{{}\\^E||{*4!4!"BE"BBG
  !$--
";<O'+'G#m"4== (H $ s   ACC	9AC	C	CN)returnNone)r   rJ   rR   zIterator[FoundResult])r   rJ   rR   Iterator[BaseDistribution])__name__
__module____qualname____doc__tupler)   r*   r   r   r   FoundResultr&   r4   r8   rQ   rA   r'   r   r    r    (   s>    
 	**77(9KKLK7&*
H>r'   r    c                  H    e Zd ZddZedd       Zed	d       Zd
dZddZy)Environmentc                    || _         y r"   )_paths)r%   pathss     r   r&   zEnvironment.__init__u   s	    r'   c                .     | t         j                        S r"   sysr   )clss    r   defaultzEnvironment.defaultx   s    388}r'   c                B    | | t         j                        S  | |      S r"   ra   )rc   r_   s     r   
from_pathszEnvironment.from_paths|   s    =sxx= 5zr'   c              #     K   t               }| j                  D ]4  }|j                  |      E d {    |j                  |      E d {    6 y 7  7 	wr"   )r    r^   r8   rQ   )r%   finderr   s      r   _iter_distributionszEnvironment._iter_distributions   sI     $&H{{8,,,33H=== $,=s!   .AAA	A
AAc                d    t        |      fd| j                         D        }t        |d       S )Nc              3  @   K   | ]  }|j                   k(  r|  y wr"   )canonical_name)r=   distributionrl   s     r   r?   z/Environment.get_distribution.<locals>.<genexpr>   s'      
 =**n<  =s   )r	   iter_all_distributionsrI   )r%   r2   matchesrl   s      @r   get_distributionzEnvironment.get_distribution   s4    *40
 $ ; ; =

 GT""r'   N)r_   zSequence[str]rR   rS   )rR   r   )r_   zlist[str] | NonerR   r   )rR   rT   )r2   rJ   rR   zBaseDistribution | None)	rU   rV   rW   r&   classmethodrd   rf   ri   rp   rA   r'   r   r\   r\   t   s9        
>#r'   r\   )r   rJ   rR   bool)%
__future__r   importlib.metadatar)   loggingr   rC   rb   r   collections.abcr   r   typingr   pip._vendor.packaging.utilsr   r   r	   r
   pip._internal.metadata.baser   r   pip._internal.utils.filetypesr   _compatr   r   r   r   _distsr   	getLoggerrU   r,   r   r    r\   rA   r'   r   <module>r~      sl    "   	  
  .   J 9 V V  			8	$	(I> I>X#/ #r'   