Current File : //lib/python3.9/site-packages/pip/_internal/req/__pycache__/constructors.cpython-39.pyc
a

[��f�;�@s�dZddlZddlZddlZddlmZmZmZmZm	Z	m
Z
ddlmZddl
mZmZddlmZddlmZmZddlmZdd	lmZmZdd
lmZddlmZddlmZdd
l m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+m,Z,gd�Z-e�.e/�Z0ej1�2�Z3e4e	e4ee4fd�dd�Z5ee4ee4d�dd�Z6e4e	ee4e4ee4fd�dd�Z7e4e4d�dd�Z8Gd d!�d!�Z9e4e9d�d"d#�Z:d=e4ee
e!e4fee;e;eee4efe;e;e;e!d%�	d&d'�Z<e4e;d(�d)d*�Z=e4e4ee4d+�d,d-�Z>e4ee4e9d.�d/d0�Z?d>e4ee
e4e!fee;e;eee4efe;ee4e;e!d1�	d2d3�Z@d?e4ee!e;ee;e;e!d4�d5d6�ZAd@ee;ee;e;e!d7�d8d9�ZBee!e!d:�d;d<�ZCdS)Aa~Backing implementation for InstallRequirement's various constructors

The idea here is that these formed a major chunk of InstallRequirement's size
so, moving them and support code dedicated to them outside of that class
helps creates for better understandability for the rest of the code.

These are meant to be used elsewhere within pip to create instances of
InstallRequirement.
�N)�Any�Dict�Optional�Set�Tuple�Union)�Marker)�InvalidRequirement�Requirement)�	Specifier)�RequirementParseError�parse_requirements)�InstallationError)�PyPI�TestPyPI)�Link)�Wheel)�ParsedRequirement)�InstallRequirement)�is_archive_file)�is_installable_dir)�get_requirement)�path_to_url)�is_url�vcs)�install_req_from_editable�install_req_from_line�parse_editable)�path�returncCs6t�d|�}d}|r*|�d�}|�d�}n|}||fS)Nz^(.+)(\[[^\]]+\])$��)�re�match�group)r�m�extrasZpath_no_extras�r'�B/usr/lib/python3.9/site-packages/pip/_internal/req/constructors.py�
_strip_extras+s
r))r&rcCs|s
t�Std|���jS)N�placeholder)�setr�lowerr&)r&r'r'r(�convert_extras7sr-)�editable_reqrcCs�|}t|�\}}tj�|�r$t|�}|���d�rdt|�j}|rX||t	d|���j
fS||t�fStD]*}|���|�d��rh|�d|��}q�qht|�}|j
s�d�tj�}t|�d|�d���|j}|s�td�|���||t�fS)	aParses an editable requirement into:
        - a requirement name
        - an URL
        - extras
        - editable options
    Accepted requirements:
        svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir
        .[some_extra]
    zfile:r*�:�+z, zq is not a valid editable requirement. It should either be a path to a local project or a VCS URL (beginning with z).zZCould not detect requirement name for '{}', please specify one with #egg=your_package_name)r)�osr�isdirrr,�
startswithr�egg_fragmentrr&r+rZis_vcs�joinZall_schemesr�format)r.�urlZ
url_no_extrasr&Zpackage_nameZversion_control�linkZbackendsr'r'r(r=s@
�����r)�reqrcCs�d}tj�|�r�d}zJt|��.}tt|����|d�|�7}Wd�n1sR0YWq�ty�t	j
d|dd�Yq�0n|d|�d	�7}|S)
z�Returns helpful msg in case requirements file does not exist,
    or cannot be parsed.

    :params req: Requirements file path
    �z The path does exist. z�The argument you provided ({}) appears to be a requirements file. If that is the case, use the '-r' flag to install the packages specified within it.Nz&Cannot parse '%s' as requirements fileT)�exc_infoz File 'z' does not exist.)r1r�exists�open�nextr
�readr6r�logger�debug)r9�msg�fpr'r'r(�deduce_helpful_msgts
��(rDc@s0eZdZeeeeeeeed�dd�Z	dS)�RequirementParts��requirementr8�markersr&cCs||_||_||_||_dS�NrF)�selfrGr8rHr&r'r'r(�__init__�szRequirementParts.__init__N)
�__name__�
__module__�__qualname__rr
rrr�strrKr'r'r'r(rE�s
�rEcCsbt|�\}}}|durHzt|�}WqLtyDtd|�d���YqL0nd}t|�}t||d|�S)N�Invalid requirement: '�')rr
r	rrrE)r.�namer7Zextras_overrider9r8r'r'r(�parse_req_from_editable�srSF)	r.�
comes_from�
use_pep517�isolated�options�
constraint�
user_supplied�permit_editable_wheelsrc	Cs`t|�}t|j||d||j||||r0|�dg�ng|rB|�dg�ng|rT|�di�ni|jd�
S)NT�install_options�global_options�hashes)rTrY�editablerZr8rXrUrVr[r\�hash_optionsr&)rSrrGr8�getr&)	r.rTrUrVrWrXrYrZ�partsr'r'r(r�s �r)rRrcCs>tjj|vrdStjjdur,tjj|vr,dS|�d�r:dSdS)akChecks whether the string "looks like" a path on the filesystem.

    This does not check whether the target actually exists, only judge from the
    appearance.

    Returns true if any of the following conditions is true:
    * a path separator is found (either os.path.sep or os.path.altsep);
    * a dot is found (which represents the current directory).
    TN�.F)r1r�sep�altsepr3)rRr'r'r(�_looks_like_path�s

re)rrRrcCs�t|�r4tj�|�r4t|�r$t|�Std|�d���t|�s@dStj�|�rTt|�S|�	dd�}t
|�dkr|t|d�s|dSt�d|�t|�S)	aK
    First, it checks whether a provided path is an installable directory. If it
    is, returns the path.

    If false, check if the path is an archive file (such as a .whl).
    The function checks if the path is a file. If false, if the path has
    an @, it will treat it as a PEP 440 URL requirement and return the path.
    z
Directory zC is not installable. Neither 'setup.py' nor 'pyproject.toml' found.N�@r r!rzARequirement %r looks like a filename, but the file does not exist)
rer1rr2rrrr�isfile�split�lenr@Zwarning)rrRZurlreq_partsr'r'r(�_get_url_from_path�s$	
��rj)rR�line_sourcercsnt|�rd}nd}||vrF|�|d�\}}|��}|s<d}qJt|�}nd}|��}d}tj�tj�|��}d}d}t|�r�t|�}n&t	|�\}	}t
|	|�}
|
dur�t|
�}|�r|jdkr�t�
d|j�r�tttj�tj�|j����}|j�rt|j�}|j�d|j��}n|j}n|}t|�}ttd��fdd	��ttd
��fdd�}
|du�r\|
|�}nd}t||||�S)
Nz; �;r �filez\.\./z==)�textrcs�s|S|�d��d�S)Nz (from �)r')rn)rkr'r(�with_source4sz(parse_req_from_line.<locals>.with_source)�
req_as_stringrcs�zt��}Wn�ty�tjj�vr8d}|t��7}n(d�vr\t�fdd�tD��s\d}nd}�d����}|r�|d|��7}t|��Yn40|j	D]*}t
|�}|�d	�r�d
|�d�}t|��q�|S)NzIt looks like a path.�=c3s|]}|�vVqdSrIr')�.0�op�rqr'r(�	<genexpr>@szAparse_req_from_line.<locals>._parse_req_string.<locals>.<genexpr>z,= is not a valid operator. Did you mean == ?r:zInvalid requirement: z
Hint: �]zExtras after version 'z'.)rr	r1rrcrD�any�	operatorsrZ	specifierrO�endswith)rqr9Zadd_msgrB�specZspec_str)rprur(�_parse_req_string9s*�


z.parse_req_from_line.<locals>._parse_req_string)rrh�striprr1r�normpath�abspathrr)rj�schemer"�searchr7rZis_wheelr�filenamerR�versionr4r-rOr
rE)rRrkZ
marker_sepZmarkers_as_stringrHrqrr8Zextras_as_string�pr7Zwheelr&r|r9r')rkrpr(�parse_req_from_linesH





r�)	rRrTrUrVrWrXrkrYrc	Csbt||�}t|j||j|j|||r.|�dg�ng|r@|�dg�ng|rR|�di�ni||j|d�S)aCreates an InstallRequirement from a name, which might be a
    requirement, directory containing 'setup.py', filename, or URL.

    :param line_source: An optional string describing where the line is from,
        for logging purposes in case of an error.
    r[r\r])
r8rHrUrVr[r\r_rXr&rY)r�rrGr8rHr`r&)	rRrTrUrVrWrXrkrYrar'r'r(r^s
�r)�
req_stringrTrVrUrYrcCs|zt|�}Wn"ty.td|�d���Yn0tjtjg}|jrj|rj|jrj|jj|vrjtd�	|j
|���t|||||d�S)NrPrQzkPackages installed from PyPI cannot depend on packages which are not also hosted on PyPI.
{} depends on {} )rVrUrY)rr	rrZfile_storage_domainrr7r8�netlocr6rRr)r�rTrVrUrYr9Zdomains_not_allowedr'r'r(�install_req_from_req_string�s6����
����r�)�
parsed_reqrVrUrYrc
CsH|jr"t|j|j||j||d�}n"t|j|j|||j|j|j|d�}|S)N)rTrUrXrVrY)rTrUrVrWrXrkrY)Zis_editablerrGrTrXrrWrk)r�rVrUrYr9r'r'r(�#install_req_from_parsed_requirement�s(�
�
r�)r8�ireqrcCs.t|j|j|j||j|j|j|j|j|j	d�
S)N)
r9rTr^r8rHrUrVr[r\r_)
rr9rTr^rHrUrVr[r\r_)r8r�r'r'r(�install_req_from_link_and_ireq�s�r�)NNFNFFF)NNFNFNF)NFNF)FNF)D�__doc__Zloggingr1r"�typingrrrrrrZpip._vendor.packaging.markersrZ"pip._vendor.packaging.requirementsr	r
Z pip._vendor.packaging.specifiersrZpip._vendor.pkg_resourcesrr
Zpip._internal.exceptionsrZpip._internal.models.indexrrZpip._internal.models.linkrZpip._internal.models.wheelrZpip._internal.req.req_filerZpip._internal.req.req_installrZpip._internal.utils.filetypesrZpip._internal.utils.miscrZpip._internal.utils.packagingrZpip._internal.utils.urlsrZpip._internal.vcsrr�__all__Z	getLoggerrLr@Z
_operators�keysryrOr)r-rrDrErS�boolrrerjr�rr�r�r�r'r'r'r(�<module>s�
 

"7��"\��$��(���