U ��.e��@sLddlmZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z ddlmZddlmZddlmZddlmZdd lmZdd lmZmZdd lmZdd lmZdd lm Z ddl!m"Z"ddl#m$Z$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/m0Z0ddl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;mm?Z?ddl@mAZAddlBmCZCmDZDddlEmFZFddlGmHZHddlImJZJddlKmLZLeH�r.ddlMmNZNmOZOmPZPmQZQmRZRmSZSmTZTddlmUZUddlVmWZWdd lXmYZYdd!lZm[Z[dd"l\m]Z]dd#l^m_Z_e�`ea�ZbGd$d%�d%ec�ZddS)&�)�absolute_importN)� change_root)� pkg_resources�six)� Requirement)�canonicalize_name)�Version)�parse)�Pep517HookCaller)� pep425tags�wheel)�NoOpBuildEnvironment)�InstallationError)�Link)�get_metadata_generator)�load_pyproject_toml�make_pyproject_path)�UninstallPathSet)� native_str)�Hashes)� indent_log)�PIP_DELETE_MARKER_FILENAME�has_delete_marker_file) �_make_build_dir�ask_path_exists� backup_dir� display_path�dist_in_install_path�dist_in_site_packages�dist_in_usersite� ensure_dir�get_installed_version�hide_url�redact_auth_from_url�rmtree)� get_metadata)�make_setuptools_shim_args)�call_subprocess�runner_with_spinner_message)� TempDirectory)�MYPY_CHECK_RUNNING)�running_under_virtualenv)�vcs)�Any�Dict�Iterable�List�Optional�Sequence�Union)�BuildEnvironment)� WheelCache)� PackageFinder)� Distribution)� SpecifierSet)�Markerc @speZdZdZdPdd�Zdd�Zd d �Zd d �Zd d�Ze dd��Z e dd��Z e dd��Z e dd��Z dQdd�Ze dd��ZdRdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Ze d(d)��ZdSd*d+�Ze d,d-��Ze d.d/��Ze d0d1��Zd2d3�Zd4d5�Zd6d7�Ze d8d9��Zd:d;�Zdd?�Z!dTd@dA�Z"dUdBdC�Z#dVdDdE�Z$dFdG�Z%dHdI�Z&dJdK�Z'dWdLdM�Z(dNdO�Z)dS)X�InstallRequirementz� Represents something that may be installed later on, may have information about where to fetch the relevant requirement and also contains logic for installing the said requirement. NF�c Cs||_||_| |_|dkr"d|_ntj�tj�|��|_||_| |_ |dkr`|r`|j r`t |j �}||_ |_ | rx| |_n |r�dd�|jD�|_nt�|_|dkr�|r�|j}||_d|_d|_d|_d|_d|_| r�| ni|_d|_d|_||_t�|_d|_d|_g|_d|_ ||_!dS)NcSsh|]}t�|��qSr;)rZ safe_extra��.0�extrar;r;�A/usr/lib/python3.8/site-packages/pip/_internal/req/req_install.py� wsz.InstallRequirement.__init__..F)"�req� comes_from� constraint� source_dir�os�path�normpath�abspath�editable� _wheel_cache�urlr�link� original_link�extras�set�marker�markers� satisfied_by�conflicts_with�_temp_build_dir�_ideal_build_dir�install_succeeded�optionsZpreparedZ is_direct�isolatedr � build_env�metadata_directory�pyproject_requires�requirements_to_check�pep517_backend� use_pep517) �selfrArBrDrIrLrQr^rXrWZ wheel_cacherCrNr;r;r?�__init__TsH  �  zInstallRequirement.__init__cCs�|jr,t|j�}|jrD|dt|jj�7}n|jr@t|jj�}nd}|jdk rb|dt|jj�7}|jr�t |jt j �r~|j}n |j� �}|r�|d|7}|S)Nz from %szz in %sz (from %s)) rA�strrLr#rKrRr�locationrB� isinstancer� string_types� from_path�r_�srBr;r;r?�__str__�s     zInstallRequirement.__str__cCsd|jjt|�|jfS)Nz<%s object: %s editable=%r>)� __class__�__name__rarI�r_r;r;r?�__repr__�s �zInstallRequirement.__repr__cs>t|��t��}�fdd�t|�D�}dj|jjd�|�d�S)z>An un-tested helper for getting state, for debugging. c3s|]}d�|�|�VqdS)z{}={!r}N)�format)r=�attr�Z attributesr;r?� �sz2InstallRequirement.format_debug..z<{name} object: {{{state}}}>z, )�name�state)�vars�sortedrmrirj�join)r_�namesrrr;ror?� format_debug�s ��zInstallRequirement.format_debugcCsh|jdkr|�||�|_|jdk rd|sd|j}t��}|jj|j|j|d�|_||jkrdt�d|j�dS)aEnsure that if a link can be found for this, that it is found. Note that self.link may still be None - if Upgrade is False and the requirement is already installed. If require_hashes is True, don't use the wheel cache, because cached wheels, always built locally, have different hashes than the files downloaded from the index server and thus throw false hash mismatches. Furthermore, cached wheels at present have undeterministic contents due to file modification times. N)rLZ package_name�supported_tagszUsing cached wheel link: %s) rLZfind_requirementrJr Z get_supported�getrq�logger�debug)r_�finderZupgradeZrequire_hashesZold_linkrxr;r;r?� populate_link�s � z InstallRequirement.populate_linkcCs |jdkrdStt�|jj��S�N)rArrZ safe_namerqrkr;r;r?rq�s zInstallRequirement.namecCs|jjSr~)rA� specifierrkr;r;r?r�szInstallRequirement.specifiercCs$|j}t|�dko"tt|��jdkS)z�Return whether I am pinned to an exact version. For example, some-package==1.2 is pinned; some-package>1.2 is not. �>�==�===)r�len�next�iter�operator)r_Z specifiersr;r;r?� is_pinned�s �zInstallRequirement.is_pinnedcCs t|j�Sr~)r!rqrkr;r;r?�installed_versionsz$InstallRequirement.installed_versioncs0|sd}�jdk r(t�fdd�|D��SdSdS)N)�c3s|]}�j�d|i�VqdS)r>N)rQZevaluater<rkr;r?rps�z3InstallRequirement.match_markers..T)rQ�any)r_Zextras_requestedr;rkr?� match_markers s  �z InstallRequirement.match_markerscCst|j�di��S)z�Return whether any known-good hashes are specified as options. These activate --require-hashes mode; hashes specified as part of a URL do not. �hashes)�boolrWryrkr;r;r?�has_hash_optionss z#InstallRequirement.has_hash_optionsTcCsJ|j�di���}|r|jn|j}|rB|jrB|�|jg��|j�t |�S)a�Return a hash-comparer that considers my option- and URL-based hashes to be known-good. Hashes in URLs--ones embedded in the requirements file, not ones downloaded from an index server--are almost peers with ones from flags. They satisfy --require-hashes (whether it was implicitly or explicitly activated) but do not activate it. md5 and sha224 are not allowed in flags, which should nudge people toward good algos. We always OR all hashes together, even ones from URLs. :param trust_internet: Whether to trust URL-based (#md5=...) hashes downloaded from the internet, as by populate_link() r�) rWry�copyrLrM�hash� setdefaultZ hash_name�appendr)r_Ztrust_internetZ good_hashesrLr;r;r?r�#s  zInstallRequirement.hashescCsR|jdkrdSt|j�}|jrNt|jtj�r4|j}n |j��}|rN|d|7}|S)z@Format a nice indicator to show where this "comes from" Nz->)rArarBrcrrdrerfr;r;r?re9s    zInstallRequirement.from_pathcCs||jdk r|jjS|jdkr6tdd�|_||_|jjS|jrH|j��}n|j}tj� |�snt � d|�t |�tj� ||�S)Nz req-build��kindzCreating directory %s)rTrFrAr)rUrIrq�lowerrE�existsrzr{rru)r_� build_dirrqr;r;r?�ensure_build_locationIs      z(InstallRequirement.ensure_build_locationcCs�|jdk rdS|j}d|_|�|j�}tj�|�rBtdt|���t � d|t|j�t|��t � |j|�tj� tj�|��|_t|dd�|_|jr�|j}tjj||jd�}tj�||�}tj� tj�|��}||_d|_dS)a�Move self._temp_build_dir to "self._ideal_build_dir/self.req.name" For some requirements (e.g. a path to a directory), the name of the package is not available until we run egg_info, so the build_location will return a temporary directory and store the _ideal_build_dir. This is only called to "fix" the build directory after generating metadata. NzCannot update repository at %s; repository location is unknown�file�+r�)rK) rLrzr{rDZschemerKr�r,Z get_backendr"�obtainZexport)r_r�Zvc_typerKZ vcs_backendZ hidden_urlr;r;r?�update_editable�s �   z"InstallRequirement.update_editablecCsB|�|�st�d|j�dS|jp&|j}t�|�}|�||�|S)a� Uninstall the distribution currently satisfying this requirement. Prompts before removing or modifying files unless ``auto_confirm`` is True. Refuses to delete or modify files outside of ``sys.prefix`` - thus uninstallation within a virtual environment can only modify that virtual environment, even if the virtualenv is linked to global site-packages. z#Skipping %s as it is not installed.N) r�rzr�rqrRrSrZ from_dist�remove)r_Z auto_confirm�verboser�ZdistZuninstalled_pathsetr;r;r?� uninstall�s    zInstallRequirement.uninstallcCs(|t|�dd�}|�tjjd�}|S)Nr��/)r��replacerErFr�)r_rqr�r;r;r?�_clean_zip_name�sz"InstallRequirement._clean_zip_namecCs(tj�||�}|�||�}|jd|S)Nr�)rErFrur�rq)r_rF� parentdir�rootdirrqr;r;r?�_get_archive_names z$InstallRequirement._get_archive_namec Cs�d}d|j|jdf}tj�||�}tj�|�r�tdt|�d�}|dkrRd}nj|dkrvt� d t|��t� |�nF|d kr�t |�}t� d t|�t|��t � ||�n|d kr�t�d �|s�dStj|dtjdd�}|��tj�tj�|j��}t�|�D]�\} } } d| k�r| � d�| D]6} |j| | |d�} t�| d�}d|_|�|d��q | D]>}|tk�rn�q\|j|| |d�}tj�| |�}|�||��q\q�W5QRXt�dt|��dS)z}Saves archive to provided build_dir. Used for saving downloaded VCS requirements as part of `pip download`. Tz %s-%s.zipr�z8The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)bort )�i�w�b�ar�Fr�z Deleting %sr�zBacking up %s to %sr������N)Z allowZip64z pip-egg-info)r�r�r�i�r�zSaved %s)rqr�rErFrur�rrrzr�r�rr�r�r��exit�zipfileZZipFileZ ZIP_DEFLATED�normcaserHr��walkr�ZZipInfoZ external_attrZwritestrr�writer�)r_r�Zcreate_archiveZ archive_nameZ archive_pathZresponseZ dest_fileZ zip_output�dir�dirpathZdirnames� filenames�dirnameZ dir_arcnameZzipdir�filenameZ file_arcnamer;r;r?�archivesx �� � � �  � �zInstallRequirement.archivec  sh|dk r |ng}|jr*|j|||d�dS|jrnt�|j�} t�| |j�|j|j�|||||d�d|_ dSt |�|j � dg�}t |�|j � dg�}t dd����} tj�| jd�} |�|| �||�} td �|j��} t��*|j�| | ||jd �W5QRXW5QRXtj�| ��s8t�d | �W5QR�dSd|_ �fd d �}t| ��\}|D],}tj�|�}|�d��rX||�}�q��qXt�d|�W5QR�W5QR�dSW5QRXg}t| ��L}|D]@}|��}tj�|��r�|tjj 7}|�!tj�"||�|���q�W5QRX|�#�t$|�tj�|d�}t|d��}|�%d�|�d�W5QRXW5QRXdS)N)r�)r�r�r�r�r�r�Tr�r��recordr�zinstall-record.txtzRunning setup.py install for {})�cmdr�zRecord file %s not foundcs&�dkstj�|�s|St�|�SdSr~)rErF�isabsr)rF�r�r;r?� prepend_root�sz0InstallRequirement.install..prepend_rootr�z;Could not find .egg-info directory in install record for %szinstalled-files.txtr�� )&rIr�r�r Z wheel_versionrDZcheck_compatibilityrqr�rVr�rWryr)rErFru�get_install_argsr(rmrrYr�r�rzr{�openr�r�r��strip�isdirr�r�r��sortr r�)r_r�r�r�r�r�r�r�r�r�Ztemp_dir�record_filename� install_argsr�r��f�lineZ directoryZ egg_info_dirZ new_linesr�Zinst_files_pathr;r�r?�installEs� � � � �� ��      �"  � zInstallRequirement.installc Cs�t|j||jdd�}|dd|g7}|dg7}|dk r@|d|g7}|dk rT|d|g7}|rd|dg7}n |d g7}t�r�d t��}|d tj�t j d d ||j �g7}|S)NT)r�r�Zunbuffered_outputr�z--recordz#--single-version-externally-managedz--rootz--prefixz --compilez --no-compile�pythonz--install-headersZincludeZsite) r&r�rXr+� sysconfigZget_python_versionrErFrur�r�rq)r_r�r�r�r�r�r�Z py_ver_strr;r;r?r��s0 �      ��z#InstallRequirement.get_install_args) NFNNNFNNFr;)N)T)NNNTFT)r;N)T)FFF)NNNNTFT)*rj� __module__� __qualname__�__doc__r`rhrlrwr}�propertyrqrr�r�r�r�r�rer�r�r�r�r�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r;r;r;r?r:Ms� � W      8 + �    % �  �  B� `r:)eZ __future__rr�ZloggingrEr�r�r�r�Zdistutils.utilrZ pip._vendorrrZ"pip._vendor.packaging.requirementsrZpip._vendor.packaging.utilsrZpip._vendor.packaging.versionrr r�Zpip._vendor.pep517.wrappersr Z pip._internalr r Zpip._internal.build_envr Zpip._internal.exceptionsrZpip._internal.models.linkrZ*pip._internal.operations.generate_metadatarZpip._internal.pyprojectrrZpip._internal.req.req_uninstallrZpip._internal.utils.compatrZpip._internal.utils.hashesrZpip._internal.utils.loggingrZ pip._internal.utils.marker_filesrrZpip._internal.utils.miscrrrrrrrr r!r"r#r$Zpip._internal.utils.packagingr%Z$pip._internal.utils.setuptools_buildr&Zpip._internal.utils.subprocessr'r(Zpip._internal.utils.temp_dirr)Zpip._internal.utils.typingr*Zpip._internal.utils.virtualenvr+Zpip._internal.vcsr,�typingr-r.r/r0r1r2r3r4Zpip._internal.cacher5Zpip._internal.indexr6Zpip._vendor.pkg_resourcesr7Z pip._vendor.packaging.specifiersr8Zpip._vendor.packaging.markersr9Z getLoggerrjrz�objectr:r;r;r;r?�sV               8      $