3 �Pf���@s0ddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZddlmZddlmZmZddlmZddlmZdd lmZmZdd lmZdd lmZmZ dd l!m"Z"ddl#Z$dd l%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+m,Z,m-Z-ddl.m/Z/m0Z0ddl1m2Z2m3Z3m4Z4m5Z5ddl6m7Z7m8Z8m9Z9m:Z:m;Z;mZ>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGddlHmIZIddlJmKZKddlLmMZMddlNmOZOddlPmQZQddlRmSZSddlTmUZUddl#mVZVmWZWejXeY�ZZej[j\j]�Z^dd�Z_dd�Z`Gdd�dea�Zbd d!�Zcd$d"d#�ZddS)%�)�absolute_importN)� sysconfig)� change_root)� FeedParser)� pkg_resources�six)� specifiers)�Marker)�InvalidRequirement� Requirement)�canonicalize_name)�Version�parse)� configparser)� native_str� get_stdlib�WINDOWS)�is_url� url_to_path� path_to_url�is_archive_file)�InstallationError�UninstallationError)�bin_py�running_under_virtualenv�PIP_DELETE_MARKER_FILENAME�bin_user)� display_path�rmtree�ask_path_exists� backup_dir�is_installable_dir�dist_in_usersite�dist_in_site_packages�dist_in_install_path� egg_link_path�call_subprocess�read_text_file�FakeFile�_make_build_dir� ensure_dir�get_installed_version�normalize_path� dist_is_local)�Hashes)�RemovedInPip10Warning)� indent_log)�SETUPTOOLS_SHIM)� open_spinner)�UninstallPathSet)�vcs)�move_wheel_files�WheelcCs6tjd|�}d}|r*|jd�}|jd�}n|}||fS)Nz^(.+)(\[[^\]]+\])$��)�re�match�group)�path�m�extrasZpath_no_extras�r?�!/usr/lib/python3.6/req_install.py� _strip_extras9s   rAcCstdd�|D��S)Ncss|]}tj|�VqdS)N)rZ safe_extra)�.0�extrar?r?r@� Fsz_safe_extras..)�set)r>r?r?r@� _safe_extrasEsrFc @s�eZdZdQdd�ZedRdd��ZedSdd ��Zd d �Zd d �Zdd�Z e dd��Z e dd��Z dd�Z dd�Zdd�Ze dd��Ze dd��Ze dd��Zd d!�Zd"d#�Zd$d%�Zd&d'�Zejd(�Ze d)d*��Zd+d,�ZdTd-d.�ZdUd/d0�Zd1d2�Zd3d4�Zd5d6�Z d7d8�Z!dVd9d:�Z"gdddfd;d<�Z#d=d>�Z$d?d@�Z%dAdB�Z&fdfdCdD�Z'dEdF�Z(e dGdH��Z)dWdIdJ�Z*dKdL�Z+e dMdN��Z,dXdOdP�Z-dS)Y�InstallRequirementNFTc sJf|_t�tj�r�y t���Wndtk r�tjj�kr@d}n.d�krft �fdd�t D�� rfd}nt j �}t d�|f��YnXt�j�|_�|_||_| |_||_||_| |_||_|_||_| dk r�| |_n �oވj|_d|_d|_d|_d|_d|_||_d|_ d|_!d|_"d|_#d|_$| �r.| ni|_%||_&d|_'| |_(dS)Nz%It looks like a path. Does it exist ?�=c3s|]}|�kVqdS)Nr?)rB�op)�reqr?r@rDVsz.InstallRequirement.__init__..z,= is not a valid operator. Did you mean == ?zInvalid requirement: '%s' %sF))r>� isinstancer� string_typesr r �osr<�sep�any� operators� traceback� format_excrrFrJ� comes_from� constraint� source_dir�editable� _wheel_cache�link� original_link�as_egg�markers�marker�_egg_info_path� satisfied_by�conflicts_with�_temp_build_dir�_ideal_build_dir�update�install_succeeded� uninstalled�nothing_to_uninstall� use_user_site� target_dir�options� pycompileZprepared�isolated)�selfrJrSrUrVrXrZrbrir[rjrh� wheel_cacherT�add_msgr?)rJr@�__init__KsN       zInstallRequirement.__init__c Cspddlm}t||�\} } } | jd�r0t| �} nd} || || d|| �|||rP|ni|d� } | dk rlt| �| _| S)Nr)�Linkzfile:T)rUrVrXrTrjrhrl)� pip.indexro�parse_editable� startswithrrFr>)�cls� editable_reqrS� default_vcsrjrhrlrTro�name�urlZextras_overriderU�resr?r?r@� from_editable�s      z InstallRequirement.from_editablec Cs�ddlm}t|�rd}nd}||krR|j|d�\}} | j�} | sHd} qVt| �} nd} |j�}d} tjjtjj |��} d} d} t|�r�||�} n�t | �\}} tjj |�r�tjj |ks�|j d�r�t|�s�td|��|t|��} n0t|��rtjj|��stjd |�|t|��} | �r|| jd k�rPtjd | j��rP|ttjjtjj | j����} | j�rtt| j�}d |j|jf} n| j} n|} |�r�|ni}|| || | ||||d �}| �r�tt d| �j!�|_!|S)z�Creates an InstallRequirement from a name, which might be a requirement, directory containing 'setup.py', filename, or URL. r)roz; �;r7N�.z;Directory %r is not installable. File 'setup.py' not found.zARequirement %r looks like a filename, but the file does not exist�filez\.\./z%s==%s)rXr[rjrhrlrT� placeholder)"rpror�split�stripr rMr<�normpath�abspathrA�isdirrNrrr!rrr�isfile�logger�warning�schemer9�searchrw�is_wheelr6�filenamerv�version� egg_fragmentrFr r>)rsrvrSrjrhrlrTroZ marker_sepr[rJr<rXr>�p�wheelrxr?r?r@� from_line�sb          zInstallRequirement.from_linecCs�|jr(t|j�}|jr:|d|jj7}n|jr6|jjnd}|jdk rX|dt|jj�7}|jr�t|jt j �rt|j}n |jj �}|r�|d|7}|S)Nz from %sz in %sz (from %s)) rJ�strrXrwr^r�locationrSrKrrL� from_path)rk�srSr?r?r@�__str__�s    zInstallRequirement.__str__cCsd|jjt|�|jfS)Nz<%s object: %s editable=%r>)� __class__�__name__r�rV)rkr?r?r@�__repr__szInstallRequirement.__repr__cCs^|jdkr|j||�|_|jdk rZ| rZ|j}|jj|j|j�|_||jkrZtjd|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. NzUsing cached wheel link: %s)rXZfind_requirementrWZ cached_wheelrvr��debug)rk�finderZupgradeZrequire_hashesZold_linkr?r?r@� populate_link s  z InstallRequirement.populate_linkcCs|jjS)N)rJ� specifier)rkr?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. r7�==�===)r�r�)r��len�next�iter�operator)rkrr?r?r@� is_pinned!s zInstallRequirement.is_pinnedcCsR|jdkrdSt|j�}|jrNt|jtj�r4|j}n |jj�}|rN|d|7}|S)Nz->)rJr�rSrKrrLr�)rkr�rSr?r?r@r�+s    zInstallRequirement.from_pathcCs�|jdk r|jS|jdkr�sz4InstallRequirement.egg_info_path..cSsg|]}|jd�r|�qS)z .egg-info)�endswith)rB�fr?r?r@r��sz$No files/directories in %s (from %s)r7cSs(|jtjj�tjjr"|jtjj�p$dS)Nr)�countrMr<rN�altsep)�xr?r?r@� s z2InstallRequirement.egg_info_path..)�keyr)r]rVrUrMr<r�r��listdir�walkr4�dirnames�remove�list�lexistsr��extendrr��sort)rkr��base� filenames�dirs�filesr�r?)r�r@r��s>     z InstallRequirement.egg_info_pathcCs@t�}|jd�}|s*tjdt|jd���|j|p4d�|j�S)NzPKG-INFOzNo PKG-INFO file found in %sr�)rr�r�r�rr�Zfeed�close)rkr�r�r?r?r@r�s zInstallRequirement.pkg_infoz \[(.*?)\]cCs t|j�S)N)r+rv)rkr?r?r@�installed_version sz$InstallRequirement.installed_versioncCsL|j�d}|jjr2||jjkr2tjd||j�ntjdt|j�||�dS)Nr�z'Requested %s, but installing version %sz;Source in %s has version %s, which satisfies requirement %s) r�rJr�r�r�r�r�rrU)rkr�r?r?r@�assert_source_matches_version$s  z0InstallRequirement.assert_source_matches_versioncCs�|jstjd|j�dS|jjdkr(dS|js2dS|jjjdd�\}}tj |�}|r�||jj�}|rr|j |j�q�|j |j�ndS)Nz>Cannot update repository at %s; repository location is unknownr|�+r7) rXr�r�rUr�rbrwr~r4� get_backend�obtainZexport)rkr��vc_typerw�backendZ vcs_backendr?r?r@�update_editable5s"   z"InstallRequirement.update_editablec sT|j�std|jf��|jp"|j}t|j�}t|�sTtj d|j |t j �d|_ dS|t�krxtj d|j |�d|_ dSt|�}t|�}djtj|j��}|jo�tjj|j�}t|jdd�}|o�|jjd�o�|jj|� �r�|j|j�|jd ��r2x�|jd �j�D](} tjj tjj!|j| ��} |j| ��qWn�|jd ��r�|jd ��rV|jd ��ng�xj�fd d �|jd �j�D�D]J} tjj!|j| �} |j| �|j| d�|j| d�|j| d��qxW�n$|�r�t"j#dj|j�t$�|j|�n�|jjd��rF|j|j�tjj%|j�d} tjj!tjj&|j�d�} |j'| d| �n�|�r~|jjd��r~x�t(j)j*|�D]} |j| ��qhWnp|�r�t+|d��}tjj,|j-�j.��}WdQRX|j|�tjj!tjj&|�d�} |j'| |j�ntj/d||j�|jd��rb|j0d��rbxZ|j1d�D]L}t2|��r&t3}nt4}|jtjj!||��t5�r|jtjj!||�d��qW|jd��r@t6j7�r|i}ndd"i}t8j9f|�}|j:t;|jd�D]�\}}t2|��r�t3}nt4}|jtjj!||��t5�r�|jtjj!||�d�|jtjj!||�d �|jtjj!||�d!��q�W|j?|�||_@dS)#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.Cannot uninstall requirement %s, not installedz1Not uninstalling %s at %s, outside environment %sTNz.z.pyz.pycz.pyoz�Uninstalling a distutils installed project ({0}) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.z.eggr7zeasy-install.pthz./z .dist-info�rz)Not sure how to uninstall: %s - Check: %s�scriptsz.batzentry_points.txtZ delimitersrHZconsole_scriptsz.exez .exe.manifestz -script.py)rH)A�check_if_existsrrvr^r_r,r�r-r��infor�r��prefixrerr3r%�formatrZ to_filename� project_namer�rMr<r��getattrZ _providerr��addr�r�� splitlinesr�r��warnings�warnr/r~�dirnameZadd_pth�pipr�Zuninstallation_paths�open�normcase�readlinerr�Zmetadata_isdirZmetadata_listdirr"rrrrr�rZSafeConfigParserZreadfpr(Zget_metadata_linesZ has_section�itemsr�rd)rkZ auto_confirmZdistZ dist_pathZpaths_to_removeZdevelop_egg_linkZdevelop_egg_link_egg_infoZegg_info_existsZdistutils_egg_infoZinstalled_filer<Z top_level_pkgZeasy_install_eggZeasy_install_pthZfhZ link_pointerr�Zbin_dirrh�configrv�valuer?)r�r@� uninstallRs�                      zInstallRequirement.uninstallcCs$|jr|jj�ntjd|j�dS)Nz'Can't rollback %s, nothing uninstalled.)rdZrollbackr��errorrv)rkr?r?r@�rollback_uninstall�s z%InstallRequirement.rollback_uninstallcCs*|jr|jj�n|js&tjd|j�dS)Nz%Can't commit %s, nothing uninstalled.)rdZcommitrer�r�rv)rkr?r?r@�commit_uninstall�s  z#InstallRequirement.commit_uninstallcCs�d}d|j|j�df}tjj||�}tjj|�r�tdt|�d�}|dkrTd }nj|dkrxtj d t|��tj |�nF|dkr�t |�}tj d t|�t|��t j ||�n|dkr�tjd�|�r�tj|dtjdd �}tjjtjj|j��}x�tj|�D]�\} } } d| k�r| j d�xR| D]J} tjj| | �} |j| |�} tj|jd| d�}d|_|j|d��qWxL| D]D}|tk�r��qrtjj| |�}|j||�} |j||jd| ��qrW�q�W|j�tjdt|��dS)NTz %s-%s.zipr�z8The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)bort �i�w�b�aFz Deleting %szBacking up %s to %sr7)Z allowZip64z pip-egg-info�/i��r�zSaved %s)r�rrr�����i�)rvr�rMr<r�r�rrr�r�r�r r�r�r��exit�zipfileZZipFileZ ZIP_DEFLATEDr�r�r�r��_clean_zip_nameZZipInfoZ external_attrZwritestrr�writer�r�)rkr�Zcreate_archiveZ archive_nameZ archive_pathZresponseZ dest_file�zipr��dirpathr�r�r�rvZzipdirr�r?r?r@�archivesV           "zInstallRequirement.archivecCs(|t|�dd�}|jtjjd�}|S)Nr7r)r��replacerMr<rN)rkrvr�r?r?r@r5sz"InstallRequirement._clean_zip_namecs0|sd}�jdk r(t�fdd�|D��SdSdS)Nr�c3s|]}�jjd|i�VqdS)rCN)r[Zevaluate)rBrC)rkr?r@rDDsz3InstallRequirement.match_markers..T)r�)r[rO)rkZextras_requestedr?)rkr@� match_markers=s   z InstallRequirement.match_markersc,s`|jr|j|||d�dS|jr\tjj|j�}tjj||j�|j |j�||d�d|_ dS||j j dg�7}||j j dg�7}|j r�t|�dg}tjdd�}tjj|d �}�z�|j||�|�} d |jf} t| ��.} t��t| ||jd | d �WdQRXWdQRXtjj|��s(tjd |�dSd|_ |j�r:dS�fdd�} t|��H} x@| D](}tjj|�}|jd��rV| |�}P�qVWtj d|�dSWdQRXg}t|��P} xH| D]@}|j!�}tjj"|��r�|tjj#7}|j$tjj%| |�|���q�WWdQRXtjj|d�}t|d��} | j&dj|�d�WdQRXWdtjj|��rRtj'|�t(|�XdS)N)r�)r�r��strip_file_prefixT�global_options�install_optionsz --no-user-cfgz-recordzpip-zinstall-record.txtzRunning setup.py install for %sF)r�r��spinnerzRecord file %s not foundcs(�dkstjj|� r|St�|�SdS)N)rMr<�isabsr)r<)r�r?r@� prepend_root~sz0InstallRequirement.install..prepend_rootz .egg-infoz;Could not find .egg-info directory in install record for %szinstalled-files.txtr� ))rV�install_editabler�r�r�Z wheel_versionrUZcheck_compatibilityrvr5rcrh�getrjr�r�r�rMr<r��get_install_argsr2r0r&r�r�r�r�rZr�r�r�r�rr�rN�append�relpathr r�r)rkrrr�r�rr�Z temp_location�record_filename� install_args�msgrrr��lineZ directoryr�Z new_linesr�Zinst_files_pathr?)r�r@�installIs~               " zInstallRequirement.installcCs|jdkr|j|�|_|jS)aAEnsure that a source_dir is set. This will create a temporary build dir if the name of the requirement isn't known yet. :param parent_dir: The ideal pip parent_dir for the source_dir. Generally src_dir for editables and build_dir for sdists. :return: self.source_dir N)rUr�)rkZ parent_dirr?r?r@�ensure_has_source_dir�s  z(InstallRequirement.ensure_has_source_dircCs�tjdg}|jd�|jt|j�|t|�dd|g7}|jsJ|dg7}|dk r^|d|g7}|dk rr|d|g7}|jr�|dg7}n |d g7}t�r�d t j �}|d t j j tjd d ||j�g7}|S)Nz-uz-crz--recordz#--single-version-externally-managedz--rootz--prefixz --compilez --no-compiler�z--install-headers�includeZsite)r�r�rr1r�r�rZrirr�get_python_versionrMr<r�r�rv)rkrrr�r�rZ py_ver_strr?r?r@r�s(        z#InstallRequirement.get_install_argscCsd|jr6tjjtjj|jt��r6tjd|j�t|j�d|_|j rZtjj|j �rZt|j �d|_ dS)zVRemove the source files from this requirement, if they are marked for deletionzRemoving source in %sN) rUrMr<r�r�rr�r�rr`)rkr?r?r@�remove_temporary_source�s   z*InstallRequirement.remove_temporary_sourcec Cs�tjd|j�|jr"t|�dg}|r>dj|�g}t|�|}t��<ttj dt |j gt|�ddgt|�|j dd�WdQRXd |_ dS) NzRunning setup.py develop for %sz --no-user-cfgz --prefix={0}z-cZdevelopz --no-depsF)r�r�T)r�r�rvrjr�r�r0r&r�r�r1r�r�rc)rkrrr�Z prefix_paramr?r?r@r�s   z#InstallRequirement.install_editablec Cs�|jdkrdSyFtt|j��}d|_tjt|��|_|jrR|jrR|j|_d|_dSWn�tj k rjdStj k r�tj|jj �}|j r�t |�r�||_q�t�r�t|�r�td|j|jf��nt|�r�||_YnXdS)z�Find an installed distribution that satisfies or conflicts with this requirement, and set self.satisfied_by or self.conflicts_with appropriately. NFTzVWill not install to the user site because it will lack sys.path precedence to %s in %s)rJr r�r\rZget_distributionr^rVr_ZDistributionNotFoundZVersionConflictrvrfr"rr#rr�r�r$)rkZ no_markerZ existing_distr?r?r@r��s4    z"InstallRequirement.check_if_existscCs|jo |jjS)N)rXr�)rkr?r?r@r� szInstallRequirement.is_wheelc Cs,t|j|j||j|j|||j|j|d� dS)N)�user�homer�r�rirjr)r5rvrJrfrgrirj)rkZwheeldirr�r�rr?r?r@r5$s z#InstallRequirement.move_wheel_filescCsX|jd�jd�}tjj|�}tj||�}tjjtjj|��d}tj tjj|�||d�S)zAReturn a pkg_resources.Distribution built from self.egg_info_pathr�rr)r��metadata) r��rstriprMr<r�rZ PathMetadata�splitext�basenameZ Distribution)rkr�Zbase_dirr&Z dist_namer?r?r@�get_dist0s   zInstallRequirement.get_distcCst|jjdi��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)�boolrhr)rkr?r?r@�has_hash_options;sz#InstallRequirement.has_hash_optionscCsJ|jjdi�j�}|r|jn|j}|rB|jrB|j|jg�j|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+) rhr�copyrXrY�hash� setdefaultZ hash_namerr.)rkZtrust_internetZ good_hashesrXr?r?r@r+Es  zInstallRequirement.hashes) NFNFTTNFNNF)NNFNNF)NFNNF)T)F)N)NNN)T).r�� __module__� __qualname__rn� classmethodryr�r�r�r��propertyr�r�r�r�r�rvr�r�r�r�r�r�r9�compileZ_requirements_section_rer�r�r�r�r�r�r rrrr rr#rr�r�r5r*r-r+r?r?r?r@rGIs` ;  M      : 6    $0 \ )   rGcCstjd|�}|r|jd�}|S)z2 Strip req postfix ( -dev, 0.2, etc ) z^(.*?)(?:-dev|-\d.*)$r7)r9r�r;)rJr:r?r?r@�_strip_postfix[s  r6c Cs�ddlm}|}d}tjd|�}|r:|jd�}|jd�}n|}tjj|�rttjjtjj |d��slt d|��t |�}|j �j d �r�||�j}|r�||td |j ��jfS||dfSx,tD]$}|j �j d |�r�d ||f}Pq�Wd |k�r|�r tjdt�|d |}n t d|��|jd d�dj �} tj| ��s`d|dj dd�tjD��d} t | ��||�j}|�sxt d��|�s�t d|��t|�|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] r)roNz^(.+)(\[[^\]]+\])$r7r8zsetup.pyz;Directory %r is not installable. File 'setup.py' not found.zfile:r}z%s:z%s+%sr�zD--default-vcs has been deprecated and will be removed in the future.zb%s should either be a path to a local project or a VCS url beginning with svn+, git+, hg+, or bzr+zFor --editable=%s only z, cSsg|]}|jd�qS)z+URL)rv)rBr�r?r?r@r��sz"parse_editable..z is currently supportedz@Could not detect requirement name, please specify one with #egg=z@--editable=%s is not the right format; it must have #egg=Package)rpror9r:r;rMr<r�r�r�rrr�rrr�r r>r4r�r�r/r~r�Zbackendsr6) rtrurorwr>r=Z url_no_extrasZ package_nameZversion_controlr�Z error_messager?r?r@rqgs`            rq)N)eZ __future__rZloggingrMr9r�r�r�rQr�rZ distutilsrZdistutils.utilrZ email.parserrZ pip._vendorrrZpip._vendor.packagingrZpip._vendor.packaging.markersr Z"pip._vendor.packaging.requirementsr r Zpip._vendor.packaging.utilsr Zpip._vendor.packaging.versionr rr�Zpip._vendor.six.movesrZ pip.wheelr�Z pip.compatrrrZ pip.downloadrrrrZpip.exceptionsrrZ pip.locationsrrrrZ pip.utilsrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-Zpip.utils.hashesr.Zpip.utils.deprecationr/Zpip.utils.loggingr0Zpip.utils.setuptools_buildr1Z pip.utils.uir2Zpip.req.req_uninstallr3Zpip.vcsr4r5r6Z getLoggerr�r�Z SpecifierZ _operators�keysrPrArF�objectrGr6rqr?r?r?r@�s`        L