a
    4Da_+                     @   sR  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m	Z	m
Z
mZmZmZ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mZ d dlmZmZmZ d dlmZ d d	l m!Z! d d
l"m#Z# erd dlm$Z$ ne%Z$eeef Z&e'e(Z)G dd de$Z*G dd de$Z+G dd dZ,G dd de$Z-G dd de-Z.G dd de-Z/dS )    N)	IOTYPE_CHECKING
Collection	ContainerIterableIteratorListOptionalUnion)Requirement)InvalidSpecifierSpecifierSet)NormalizedName)LegacyVersionVersion)DIRECT_URL_METADATA_NAME	DirectUrlDirectUrlValidationError)stdlib_pkgs)egg_link_path_from_sys_path)url_to_path)Protocolc                   @   sB   e Zd ZeedddZeedddZeedddZdS )	BaseEntryPointreturnc                 C   s
   t  d S NNotImplementedErrorself r    k/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/pip/_internal/metadata/base.pyname+   s    zBaseEntryPoint.namec                 C   s
   t  d S r   r   r   r    r    r!   value/   s    zBaseEntryPoint.valuec                 C   s
   t  d S r   r   r   r    r    r!   group3   s    zBaseEntryPoint.groupN)__name__
__module____qualname__propertystrr"   r#   r$   r    r    r    r!   r   *   s   r   c                   @   s  e Zd ZedddZedddZeee dddZeee ddd	Z	eee dd
dZ
eedddZeedddZeee dddZeedddZeedddZeedddZeedddZeedddZeedddZee ddd Zeejjdd!d"Zeee dd#d$Zeedd%d&Z ee!dd'd(Z"d0e#e ee$ d*d+d,Z%ee dd-d.Z&d/S )1BaseDistributionr   c                 C   s   | j  d| j d| j dS )N z ())raw_nameversionlocationr   r    r    r!   __repr__9   s    zBaseDistribution.__repr__c                 C   s   | j  d| j S )Nr+   )r-   r.   r   r    r    r!   __str__<   s    zBaseDistribution.__str__c                 C   s
   t  dS )a  Where the distribution is loaded from.

        A string value is not necessarily a filesystem path, since distributions
        can be loaded from other sources, e.g. arbitrary zip archives. ``None``
        means the distribution is created in-memory.

        Do not canonicalize this value with e.g. ``pathlib.Path.resolve()``. If
        this is a symbolic link, we want to preserve the relative path between
        it and files in the distribution.
        Nr   r   r    r    r!   r/   ?   s    zBaseDistribution.locationc                 C   s6   | j }|r| r2t|jS nt| j}|r2| jS dS )zThe project location for editable distributions.

        This is the directory where pyproject.toml or setup.py is located.
        None if the distribution is not installed in editable mode.
        N)
direct_urlZis_local_editabler   urlr   r-   r/   )r   r2   egg_link_pathr    r    r!   editable_project_locationM   s    
z*BaseDistribution.editable_project_locationc                 C   s
   t  dS )a'  Location of the .[egg|dist]-info directory.

        Similarly to ``location``, a string value is not necessarily a
        filesystem path. ``None`` means the distribution is created in-memory.

        For a modern .dist-info installation on disk, this should be something
        like ``{location}/{raw_name}-{version}.dist-info``.

        Do not canonicalize this value with e.g. ``pathlib.Path.resolve()``. If
        this is a symbolic link, we want to preserve the relative path between
        it and other files in the distribution.
        Nr   r   r    r    r!   info_directoryc   s    zBaseDistribution.info_directoryc                 C   s
   t  d S r   r   r   r    r    r!   canonical_names   s    zBaseDistribution.canonical_namec                 C   s
   t  d S r   r   r   r    r    r!   r.   w   s    zBaseDistribution.versionc              
   C   sv   z|  t}W n ty"   Y dS 0 zt|W S  ttjtfyp } z t	
dt| j| W Y d}~dS d}~0 0 dS )zObtain a DirectUrl from this distribution.

        Returns None if the distribution has no `direct_url.json` metadata,
        or if `direct_url.json` is invalid.
        NzError parsing %s for %s: %s)	read_textr   FileNotFoundErrorr   	from_jsonUnicodeDecodeErrorjsonJSONDecodeErrorr   loggerwarningr7   )r   contenter    r    r!   r2   {   s$    zBaseDistribution.direct_urlc                 C   s
   t  d S r   r   r   r    r    r!   	installer   s    zBaseDistribution.installerc                 C   s
   t | jS r   )boolr5   r   r    r    r!   editable   s    zBaseDistribution.editablec                 C   s
   t  d S r   r   r   r    r    r!   local   s    zBaseDistribution.localc                 C   s
   t  d S r   r   r   r    r    r!   in_usersite   s    zBaseDistribution.in_usersitec                 C   s
   t  d S r   r   r   r    r    r!   in_site_packages   s    z!BaseDistribution.in_site_packagesr"   r   c                 C   s
   t  dS )zRead a file in the .dist-info (or .egg-info) directory.

        Should raise ``FileNotFoundError`` if ``name`` does not exist in the
        metadata directory.
        Nr   r   r"   r    r    r!   r8      s    zBaseDistribution.read_textc                 C   s
   t  d S r   r   r   r    r    r!   iter_entry_points   s    z"BaseDistribution.iter_entry_pointsc                 C   s
   t  dS )z?Metadata of distribution parsed from e.g. METADATA or PKG-INFO.Nr   r   r    r    r!   metadata   s    zBaseDistribution.metadatac                 C   s   | j dS )zDValue of "Metadata-Version:" in distribution metadata, if available.zMetadata-Version)rK   getr   r    r    r!   metadata_version   s    z!BaseDistribution.metadata_versionc                 C   s   | j d| jS )z*Value of "Name:" in distribution metadata.Name)rK   rL   r7   r   r    r    r!   r-      s    zBaseDistribution.raw_namec              
   C   sn   | j d}|du rt S ztt|}W n> tyh } z&d}t|| j| t W  Y d}~S d}~0 0 |S )zValue of "Requires-Python:" in distribution metadata.

        If the key does not exist or contains an invalid value, an empty
        SpecifierSet should be returned.
        zRequires-PythonNz-Package %r has an invalid Requires-Python: %s)rK   rL   r   r)   r   r>   r?   r-   )r   r#   specrA   messager    r    r!   requires_python   s    z BaseDistribution.requires_pythonr    )extrasr   c                 C   s
   t  dS )zDependencies of this distribution.

        For modern .dist-info distributions, this is the collection of
        "Requires-Dist:" entries in distribution metadata.
        Nr   )r   rR   r    r    r!   iter_dependencies   s    z"BaseDistribution.iter_dependenciesc                 C   s
   t  dS )zExtras provided by this distribution.

        For modern .dist-info distributions, this is the collection of
        "Provides-Extra:" entries in distribution metadata.
        Nr   r   r    r    r!   iter_provided_extras   s    z%BaseDistribution.iter_provided_extrasN)r    )'r%   r&   r'   r)   r0   r1   r(   r	   r/   r5   r6   r   r7   DistributionVersionr.   r   r2   rB   rC   rD   rE   rF   rG   r8   r   r   rJ   emailrP   MessagerK   rM   r-   r   rQ   r   r   rS   rT   r    r    r    r!   r*   8   sH   r*   c                   @   s   e Zd ZdZed dddZeeee  d dddZ	eed d	d
dZ
ed dddZed dddZdedddfeee eeeee dddZdS )BaseEnvironmentz6An environment containing distributions to introspect.r   c                 C   s
   t  d S r   r   )clsr    r    r!   default   s    zBaseEnvironment.default)pathsr   c                 C   s
   t  d S r   r   )rY   r[   r    r    r!   
from_paths   s    zBaseEnvironment.from_pathsr*   rH   c                 C   s
   t  dS )z=Given a requirement name, return the installed distributions.Nr   rI   r    r    r!   get_distribution   s    z BaseEnvironment.get_distributionc                 C   s
   t  dS )a  Iterate through installed distributions.

        This function should be implemented by subclass, but never called
        directly. Use the public ``iter_distribution()`` instead, which
        implements additional logic to make sure the distributions are valid.
        Nr   r   r    r    r!   _iter_distributions   s    z#BaseEnvironment._iter_distributionsc                 c   sD   |   D ]6}tjd|jtjd}|s8td|j|j q|V  qdS )z(Iterate through installed distributions.z)^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$)flagsz%Ignoring invalid distribution %s (%s)N)r^   rematchr7   
IGNORECASEr>   r?   r/   )r   distZproject_name_validr    r    r!   iter_distributions  s    z"BaseEnvironment.iter_distributionsTF)
local_onlyskipinclude_editableseditables_only	user_onlyr   c                    sb   |   }|rdd |D }|s,dd |D }|r>dd |D }|rPdd |D } fdd|D S )a  Return a list of installed distributions.

        :param local_only: If True (default), only return installations
        local to the current virtualenv, if in a virtualenv.
        :param skip: An iterable of canonicalized project names to ignore;
            defaults to ``stdlib_pkgs``.
        :param include_editables: If False, don't report editables.
        :param editables_only: If True, only report editables.
        :param user_only: If True, only report installations in the user
        site directory.
        c                 s   s   | ]}|j r|V  qd S r   )rE   .0dr    r    r!   	<genexpr>+      z?BaseEnvironment.iter_installed_distributions.<locals>.<genexpr>c                 s   s   | ]}|j s|V  qd S r   rD   rj   r    r    r!   rm   -  rn   c                 s   s   | ]}|j r|V  qd S r   ro   rj   r    r    r!   rm   /  rn   c                 s   s   | ]}|j r|V  qd S r   )rF   rj   r    r    r!   rm   1  rn   c                 3   s   | ]}|j  vr|V  qd S r   )r7   rj   rf   r    r!   rm   2  rn   )rd   )r   re   rf   rg   rh   ri   itr    rp   r!   iter_installed_distributions  s    z,BaseEnvironment.iter_installed_distributionsN)r%   r&   r'   __doc__classmethodrZ   r	   r   r)   r\   r]   r   r^   rd   r   rC   r   r*   rr   r    r    r    r!   rX      s*   	rX   c                   @   s&   e Zd ZU eed< ejdddZdS )Wheelr/   r   c                 C   s
   t  d S r   r   r   r    r    r!   
as_zipfile8  s    zWheel.as_zipfileN)r%   r&   r'   r)   __annotations__zipfileZipFilerv   r    r    r    r!   ru   5  s   
ru   c                   @   s,   e Zd ZeddddZejdddZdS )FilesystemWheelN)r/   r   c                 C   s
   || _ d S r   )r/   )r   r/   r    r    r!   __init__=  s    zFilesystemWheel.__init__r   c                 C   s   t j| jddS NT)
allowZip64)rx   ry   r/   r   r    r    r!   rv   @  s    zFilesystemWheel.as_zipfile)r%   r&   r'   r)   r{   rx   ry   rv   r    r    r    r!   rz   <  s   rz   c                   @   s2   e Zd Zeee ddddZejdddZ	dS )MemoryWheelN)r/   streamr   c                 C   s   || _ || _d S r   )r/   r   )r   r/   r   r    r    r!   r{   E  s    zMemoryWheel.__init__r   c                 C   s   t j| jddS r|   )rx   ry   r   r   r    r    r!   rv   I  s    zMemoryWheel.as_zipfile)
r%   r&   r'   r)   r   bytesr{   rx   ry   rv   r    r    r    r!   r~   D  s   r~   )0email.messagerV   r<   loggingr`   rx   typingr   r   r   r   r   r   r   r	   r
   Z"pip._vendor.packaging.requirementsr   Z pip._vendor.packaging.specifiersr   r   Zpip._vendor.packaging.utilsr   pip._vendor.packaging.versionr   r   pip._internal.models.direct_urlr   r   r   pip._internal.utils.compatr   Zpip._internal.utils.egg_linkr   pip._internal.utils.urlsr   r   objectrU   	getLoggerr%   r>   r   r*   rX   ru   rz   r~   r    r    r    r!   <module>   s2   ,
 2L