U ��.e48�@s�dZddlZddlZddlZddlmZddlmZmZddl m Z ddl m Z m Z ddlmZddlmZmZdd lmZdd lmZdd lmZdd lmZdd lmZmZddlmZddl m!Z!ddl"m#Z#m$Z$ddl%m&Z&e�rddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-ddl.m/Z/dddgZ0e�1e2�Z3e j4�5�Z6dd�Z7dd�Z8dd�Z9dd�Z:dd�Z;Gd d!�d!e<�Z=d"d#�Z>d/d%d�Z?d&d'�Z@d(d)�ZAd*d+�ZBd0d,d�ZCd1d-d.�ZDdS)2a~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)�Marker)�InvalidRequirement� Requirement)� Specifier)�RequirementParseError�parse_requirements)�InstallationError)�PyPI�TestPyPI)�Link)�make_pyproject_path)�InstallRequirement)�ARCHIVE_EXTENSIONS)�is_installable_dir�splitext)�MYPY_CHECK_RUNNING)� path_to_url)�is_url�vcs)�Wheel)�Any�Dict�Optional�Set�Tuple�Union)� WheelCache�install_req_from_editable�install_req_from_line�parse_editablecCs t|�d��}|tkrdSdS)z9Return True if `name` is a considered as an archive file.�TF)r�lowerr)�nameZext�r#�B/usr/lib/python3.8/site-packages/pip/_internal/req/constructors.py�is_archive_file4sr%cCs6t�d|�}d}|r*|�d�}|�d�}n|}||fS)Nz^(.+)(\[[^\]]+\])$r �)�re�match�group)�path�m�extrasZpath_no_extrasr#r#r$� _strip_extras=s   r-cCs|s t�Std|���jS)N� placeholder)�setrr!r,)r,r#r#r$�convert_extrasJsr0c Cs`|}t|�\}}tj�|�rptj�tj�|d��shd�tj�|��}t|�}tj� |�r`|d7}t |��t |�}|� �� d�r�t|�j}|r�||td|� ��jfS||dfStD]&}|� �� d|�r�d||f}q�q�d |kr�t d �|���|�d d �d � �}t�|��s:d |d�dd�tjD��d} t | ��t|�j}|�sVt d|��||dfS)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] zsetup.pyzMFile "setup.py" not found. Directory cannot be installed in editable mode: {}zb (A "pyproject.toml" file was found, but editable mode currently requires a setup.py based build.)zfile:r.Nz%s:z%s+%s�+z�{} is not a valid editable requirement. It should either be a path to a local project or a VCS URL (beginning with svn+, git+, hg+, or bzr+).r rzFor --editable=%s only z, cSsg|]}|jd�qS)z+URL�r")�.0Zbackendr#r#r$� �sz"parse_editable..z is currently supportedzZCould not detect requirement name for '%s', please specify one with #egg=your_package_name)r-�osr*�isdir�exists�join�format�abspathr �isfilerrr!� startswithr � egg_fragmentrr,r�splitZ get_backendZbackends) � editable_req�urlZ url_no_extrasr,�msgZpyproject_pathZ package_nameZversion_controlZvc_typeZ error_messager#r#r$rQsb    �� � �  �� �� ��c Cs�d}tj�|�r�d}zFt|d��2}tt|����|dd|ddd7}W5QRXWq�tk r�tj d |d d �Yq�Xn |d |7}|S) z�Returns helpful msg in case requirements file does not exist, or cannot be parsed. :params req: Requirements file path �z It does exist.�rz The argument you provided z(%s) appears to be az" requirements file. If that is thez# case, use the '-r' flag to installz" the packages specified within it.z2Cannot parse '%s' as requirements fileT)�exc_infoz File '%s' does not exist.) r5r*r7�open�nextr�readr�logger�debug)�reqrA�fpr#r#r$�deduce_helpful_msg�s.  ������ rLc@seZdZdd�ZdS)�RequirementPartscCs||_||_||_||_dS�N)� requirement�link�markersr,)�selfrOrPrQr,r#r#r$�__init__�szRequirementParts.__init__N)�__name__� __module__� __qualname__rSr#r#r#r$rM�srMcCs`t|�\}}}|dk rFz t|�}WqJtk rBtd|��YqJXnd}t|�}t||d|�S)N�Invalid requirement: '%s')rrrrr rM)r?r"r@Zextras_overriderJrPr#r#r$�parse_req_from_editable�s rXFc CsLt|�}|jjdkr|jjnd}t|j||d|j||||r>|ni||jd� S)N�fileT) � source_dirZeditablerP� constraint� use_pep517�isolated�options� wheel_cacher,)rXrP�schemeZ file_pathr rOr,) r?� comes_fromr\r]r^r_r[�partsrZr#r#r$r�s  �cCs>tjj|krdStjjdk r,tjj|kr,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)r5r*�sep�altsepr<r2r#r#r$�_looks_like_path�s  rfcCs�t|�r0tj�|�r0t|�r$t|�Std|��t|�s�lenrHZwarning)r*r"Z urlreq_partsr#r#r$�_get_url_from_path s( ��  �rics�t|�rd}nd}||krF|�|d�\}}|��}|s.with_sourcezIt looks like a path.�=c3s|]}|�kVqdSrNr#)r3�op)� req_as_stringr#r$� jsz&parse_req_from_line..z,= is not a valid operator. Did you mean == ?rBzInvalid requirement: {!r}z Hint: {}) rr>�striprr5r*�normpathr:r r-rir`r'�searchr@rZis_wheelr�filenamer"�versionr=r0rrrdrL�any� operatorsr9rrM)r"rlZ marker_sepZmarkers_as_stringrQr*rPZextras_as_string�pr@Zwheelr,rmrJZadd_msgrAr#)rlrpr$�parse_req_from_line+sj    �     ��rzc Cs6t||�}t|j||j|j|||r&|ni|||jd� 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. )rPrQr\r]r^r_r[r,)rzr rOrPrQr,) r"rar\r]r^r_r[rlrbr#r#r$rzs  �cCszz t|�}Wn tk r,td|��YnXtjtjg}|jrh|rh|jrh|jj|krhtd|j |f��t |||||d�S)NrWzkPackages installed from PyPI cannot depend on packages which are not also hosted on PyPI. %s depends on %s )r]r_r\) rrrr Zfile_storage_domainr r@rPZnetlocr"r )Z req_stringrar]r_r\rJZdomains_not_allowedr#r#r$�install_req_from_req_string�s, � ����r{)NNFNNF)NNFNNFN)NFNN)E�__doc__Zloggingr5r'Zpip._vendor.packaging.markersrZ"pip._vendor.packaging.requirementsrrZ pip._vendor.packaging.specifiersrZpip._vendor.pkg_resourcesrrZpip._internal.exceptionsrZpip._internal.models.indexr r Zpip._internal.models.linkr Zpip._internal.pyprojectr Zpip._internal.req.req_installr Zpip._internal.utils.filetypesrZpip._internal.utils.miscrrZpip._internal.utils.typingrZpip._internal.utils.urlsrZpip._internal.vcsrrZpip._internal.wheelr�typingrrrrrrZpip._internal.cacher�__all__Z getLoggerrTrHZ _operators�keysrxr%r-r0rrL�objectrMrXrrfrirzrr{r#r#r#r$�sr            �    J� "Q� �