3
LY                 @   s,  d dl mZ d dlZd dlZd dlZd dlZ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 d dlmZ d dlmZ d dlmZmZ d dl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" d dl#Z$d dl%m&Z&m'Z'm(Z( d dl)m*Z*m+Z+m,Z,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2m3Z3m4Z4m5Z5 d dl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZF d dlGmHZH d dlImJZJ d dlKmLZL d dlMmNZN d dlOmPZP d dlQmRZR d dlSmTZT d dl#mUZUmVZV ejWeXZYejZj[j\ Z]dd Z^dd Z_G dd de`Zad d! Zbd$d"d#ZcdS )%    )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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Wheelc             C   s6   t jd| }d }|r*|jd}|jd}n| }||fS )Nz^(.+)(\[[^\]]+\])$      )rematchgroup)pathmextraspath_no_extras r?   f/private/var/folders/7d/20zwc49s3kn54d3vgq8bd4640000gn/T/pip-build-an2lx5zf/pip/pip/req/req_install.py_strip_extras9   s    
rA   c             C   s   t dd | D S )Nc             s   s   | ]}t j|V  qd S )N)r   
safe_extra).0extrar?   r?   r@   	<genexpr>F   s    z_safe_extras.<locals>.<genexpr>)set)r=   r?   r?   r@   _safe_extrasE   s    rG   c               @   s  e Zd ZdQddZedRddZedSdd	Zd
d Zdd Zdd Z	e
dd Ze
dd Zdd Zdd Zdd Ze
dd Ze
dd Ze
dd Zd d! Zd"d# Zd$d% Zd&d' Zejd(Ze
d)d* Zd+d, ZdTd-d.ZdUd/d0Zd1d2 Zd3d4 Zd5d6 Z d7d8 Z!dVd9d:Z"g ddfd;d<Z#d=d> Z$d?d@ Z%dAdB Z&f dfdCdDZ'dEdF Z(e
dGdH Z)dWdIdJZ*dKdL Z+e
dMdN Z,dXdOdPZ-dS )YInstallRequirementNFTc                sJ  f | _ t tjryt  W nd tk
r   tjj kr@d}n.d krft	 fddt
D  rfd}ntj }td |f Y nX t j | _  | _|| _|| _|| _|| _|| _| | _| _|| _|	d k	r|	| _n oވ j| _d | _d | _d | _d | _d | _|| _d | _ d | _!d| _"d| _#d | _$|r.|ni | _%|| _&d| _'|
| _(d S )Nz%It looks like a path. Does it exist ?=c             3   s   | ]}| kV  qd S )Nr?   )rC   op)reqr?   r@   rE   V   s    z.InstallRequirement.__init__.<locals>.<genexpr>z,= is not a valid operator. Did you mean == ?zInvalid requirement: '%s'
%sF))r=   
isinstancer   string_typesr   r
   osr;   sepany	operators	traceback
format_excr   rG   rK   
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	pycompilepreparedisolated)selfrK   rT   rV   rW   rY   r[   rc   rj   r\   rl   ri   wheel_cacherU   add_msgr?   )rK   r@   __init__K   sN     zInstallRequirement.__init__c             C   sp   ddl m} t||\}	}
}|
jdr0t|
}nd }| |	||d||
|||rP|ni |d	}|d k	rlt||_|S )Nr   )Linkzfile:T)rV   rW   rY   rU   rl   ri   rn   )	pip.indexrq   parse_editable
startswithr   rG   r=   )clseditable_reqrT   default_vcsrl   ri   rn   rU   rq   nameurlextras_overriderV   resr?   r?   r@   from_editable   s     



z InstallRequirement.from_editablec          
   C   s  ddl m} t|rd}nd}||krR|j|d\}}	|	j }	|	sHd}	qVt|	}	nd}	|j }d}
tjjtjj	|}d}d}t|r||}nt
|\}}tjj|rtjj|ks|jdrt|std| |t|}n0t|rtjj|stjd	| |t|}|r||jd
krPtjd|jrP|ttjjtjj	|j}|jrtt|j}d|j|jf }
n|j}
n|}
|r|ni }| |
|||	||||d}|rtt d| j!|_!|S )zCreates an InstallRequirement from a name, which might be a
        requirement, directory containing 'setup.py', filename, or URL.
        r   )rq   z; ;r6   N.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)rY   r\   rl   ri   rn   rU   placeholder)"rr   rq   r   splitstripr	   rN   r;   normpathabspathrA   isdirrO   rt   r!   r   r   r   isfileloggerwarningschemer8   searchry   is_wheelr5   filenamerx   versionegg_fragmentrG   r   r=   )ru   rx   rT   rl   ri   rn   rU   rq   
marker_sepr\   rK   r;   rY   r=   pwheelr{   r?   r?   r@   	from_line   sb    





zInstallRequirement.from_linec             C   s   | j r(t| j }| jr:|d| jj 7 }n| jr6| jjnd }| jd k	rX|dt| jj 7 }| jrt| jt	j
rt| j}n
| jj }|r|d| 7 }|S )Nz from %sz in %sz
 (from %s))rK   strrY   ry   r_   r   locationrT   rL   r   rM   	from_path)rm   srT   r?   r?   r@   __str__   s    


zInstallRequirement.__str__c             C   s   d| j jt| | jf S )Nz<%s object: %s editable=%r>)	__class____name__r   rW   )rm   r?   r?   r@   __repr__  s    zInstallRequirement.__repr__c             C   s^   | j dkr|j| || _ | jdk	rZ| rZ| j }| jj| j | j| _ || j krZtjd| j  dS )a  Ensure 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.
        NzUsing cached wheel link: %s)rY   find_requirementrX   cached_wheelrx   r   debug)rm   finderupgraderequire_hashesold_linkr?   r?   r@   populate_link	  s    

z InstallRequirement.populate_linkc             C   s   | j jS )N)rK   	specifier)rm   r?   r?   r@   r     s    zInstallRequirement.specifierc             C   s$   | j }t|dko"tt|jdkS )zReturn whether I am pinned to an exact version.

        For example, some-package==1.2 is pinned; some-package>1.2 is not.
        r6   =====)r   r   )r   lennextiteroperator)rm   r   r?   r?   r@   	is_pinned!  s    zInstallRequirement.is_pinnedc             C   sR   | j d krd S t| j }| jrNt| jtjr4| j}n
| jj }|rN|d| 7 }|S )Nz->)rK   r   rT   rL   r   rM   r   )rm   r   rT   r?   r?   r@   r   +  s    


zInstallRequirement.from_pathc             C   s   | j d k	r| j S | jd kr<tjjtjdd| _ || _| j S | jrN| j	j
 }n| j	}tjj|sttjd| t| tjj||S )Nz-buildzpip-zCreating directory %s)ra   rK   rN   r;   realpathtempfilemkdtemprb   rW   rx   lowerexistsr   r   r(   join)rm   	build_dirrx   r?   r?   r@   build_location8  s    

z!InstallRequirement.build_locationc             C   s   | j dk	rdS | jdk	st| js&t| js0t| j}d| _| j| j}tjj|rdt	dt
| tjd| t
|t
| tj|| || _d| _|| _ d| _dS )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 by self.egg_info_path to fix the temporary build
        directory.
        Nz<A package already exists in %s; please remove it to continuez,Moving package %s from %s to new location %s)rV   rK   AssertionErrorra   rb   r   rN   r;   r   r   r   r   r   shutilmover^   )rm   old_locationnew_locationr?   r?   r@   _correct_build_locationS  s(    



z*InstallRequirement._correct_build_locationc             C   s    | j d krd S ttj| j jS )N)rK   r   r   	safe_namerx   )rm   r?   r?   r@   rx   s  s    
zInstallRequirement.namec             C   s   t jj| j| jr| jjpdS )N )rN   r;   r   rV   rY   subdirectory_fragment)rm   r?   r?   r@   setup_py_diry  s    zInstallRequirement.setup_py_dirc             C   s   | j std|  ydd l}W n: tk
rX   tdd kr@d}ntj }td| Y nX tj	j
| jd}tjrt|tjr|jtj }|S )NzNo source dir for %sr   
setuptoolszPlease install setuptools.zWCould not import setuptools which is required to install from a source distribution.
%szsetup.py)rV   r   r   ImportErrorr*   rR   rS   r   rN   r;   r   r   r   PY2rL   	text_typeencodesysgetfilesystemencoding)rm   r   ro   setup_pyr?   r?   r@   r     s    zInstallRequirement.setup_pyc             C   sZ  | j s
t| jr$tjd| j| j ntjd| j| j t x t| j }t	j
d|g}| jrd|dg7 }|dg }| jrzg }n tjj| jd}t| ddg}t|| | jdd	d
 W d Q R X | jstt| j d trd}nd}tdj| j d || j d g| _| j  nDt| j d }t| jj|krVtjd| j| j|| j t|| _d S )Nz2Running setup.py (path:%s) egg_info for package %sz7Running setup.py (path:%s) egg_info for package from %sz-cz--no-user-cfgegg_infozpip-egg-infoz
--egg-baseFzpython setup.py egg_info)cwdshow_stdoutcommand_descr   z==z===r   NamezuRunning setup.py (path:%s) egg_info for package %s produced metadata for project name %s. Fix your #egg=%s fragments.)rV   r   rx   r   r   r   rY   r/   r0   r   
executablerl   rW   rN   r;   r   r   r)   r%   rK   rL   parse_versionpkg_infor   r   r   r   r   )rm   scriptbase_cmdegg_info_cmdegg_base_optionegg_info_dirrJ   metadata_namer?   r?   r@   run_egg_info  sP    





zInstallRequirement.run_egg_infoc             C   sV   | j d k	r&| j j|sd S | j j|S | js0t| j|}tjj|sJd S t	|}|S )N)
r_   has_metadataget_metadatarV   r   egg_info_pathrN   r;   r   r&   )rm   r   datar?   r?   r@   egg_info_data  s    


z InstallRequirement.egg_info_datac                s|  | j d krl| jr| j}ntjj| jd}tj|}| jrg }xtj|D ]\ }}x t	j
D ]}||kr^|j| q^W xjt|D ]^}tjjtjj |ddstjjtjj |ddr|j| q|dks|dkr|j| qW |j fdd	|D  qLW d
d	 |D }|s$td||f |s:td||f t|dkrX|jdd d tjj||d | _ tjj| j |S )Nzpip-egg-infobinpythonScriptsz
Python.exetesttestsc                s   g | ]}t jj |qS r?   )rN   r;   r   )rC   dir)rootr?   r@   
<listcomp>  s   z4InstallRequirement.egg_info_path.<locals>.<listcomp>c             S   s   g | ]}|j d r|qS )z	.egg-info)endswith)rC   fr?   r?   r@   r     s    z$No files/directories in %s (from %s)r6   c             S   s(   | j tjjtjjr"| j tjjp$d S )Nr   )countrN   r;   rO   altsep)xr?   r?   r@   <lambda>  s   z2InstallRequirement.egg_info_path.<locals>.<lambda>)keyr   )r^   rW   rV   rN   r;   r   r   listdirwalkr3   dirnamesremovelistlexistsr   extendr   r   r   sort)rm   r   base	filenamesdirsfilesr   r?   )r   r@   r     sB    
z InstallRequirement.egg_info_pathc             C   s@   t  }| jd}|s*tjdt| jd |j|p4d |j S )NzPKG-INFOzNo PKG-INFO file found in %sr   )r   r   r   r   r   r   feedclose)rm   r   r   r?   r?   r@   r     s    
zInstallRequirement.pkg_infoz	\[(.*?)\]c             C   s
   t | jS )N)r*   rx   )rm   r?   r?   r@   installed_version   s    z$InstallRequirement.installed_versionc             C   sV   | j s
t| j d }| jjr<|| jjkr<tjd| | j ntjdt	| j ||  d S )Nr   z'Requested %s, but installing version %sz;Source in %s has version %s, which satisfies requirement %s)
rV   r   r   rK   r   r   r   r   r   r   )rm   r   r?   r?   r@   assert_source_matches_version$  s    

z0InstallRequirement.assert_source_matches_versionc             C   s   | j stjd| j d S | js"t| js,t| j jdkr<d S d| j jksXtd| j j | jsbd S | j jj	dd\}}t
j|}|r|| j j}|r|j| j q|j| j ndstd| j |f d S )Nz>Cannot update repository at %s; repository location is unknownr   +zbad url: %rr6   r   z+Unexpected version control type (in %s): %s)rY   r   r   rV   rW   r   r   ry   rc   r   r3   get_backendobtainexport)rm   r   vc_typery   backendvcs_backendr?   r?   r@   update_editable5  s,    


z"InstallRequirement.update_editablec                sx  | j  std| jf | jp"| j}t|j}t|sTtj	d|j
|tj d| _dS |t krxtj	d|j
| d| _dS t|}t|}djtj|j}|jotjj|j}t|jdd}|o|jjdo|jj| r|j|j |jd	r2x|jd	j D ](}	tjj tjj!|j|	}
|j|
 qW n|jd
r|jdrV|jd ng  xj fdd|jd
j D D ]J}tjj!|j|}
|j|
 |j|
d  |j|
d  |j|
d  qxW nH|rt"j#dj| jt$ |j| n |jjdrH|j|j tjj%|jd }tjj!tjj&|jd}|j'|d|  n|r|jjdrxt(j)j*|D ]}
|j|
 qjW n|rt+|d}tjj,|j- j. }W dQ R X ||jkst/d|| j|jf |j| tjj!tjj&|d}|j'||j ntj0d||j |jdr|j1drxZ|j2dD ]L}t3|rJt4}nt5}|jtjj!|| t6r6|jtjj!||d  q6W |jdrdt7j8ri }ndd#i}t9j:f |}|j;t<|j=d |j>drdx|j?dD ]\}}t3|rt4}nt5}|jtjj!|| t6r|jtjj!||d   |jtjj!||d!  |jtjj!||d"  qW |j@| || _Ad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.Cannot uninstall requirement %s, not installedz1Not uninstalling %s at %s, outside environment %sTNz<Not uninstalling %s at %s, as it is in the standard library.z{0}.egg-infor;   z	.egg-infozinstalled-files.txtztop_level.txtznamespace_packages.txtc                s   g | ]}|r| kr|qS r?   r?   )rC   r   )
namespacesr?   r@   r     s    z0InstallRequirement.uninstall.<locals>.<listcomp>z.pyz.pycz.pyozUninstalling 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.eggr6   zeasy-install.pthz./z
.dist-inforz;Egg-link %s does not match installed location of %s (at %s)z)Not sure how to uninstall: %s - Check: %sscriptsz.batzentry_points.txt
delimitersrI   console_scriptsz.exez.exe.manifestz
-script.py)rI   )Bcheck_if_existsr   rx   r_   r`   r+   r   r,   r   infor   r   prefixrf   r   r2   r$   formatr   to_filenameproject_namer   rN   r;   r   getattr	_providerr   addr   r   
splitlinesr   r   warningswarnr.   r   dirnameadd_pthpipr   uninstallation_pathsopennormcasereadliner   r   r   metadata_isdirmetadata_listdirr"   r   r   r   r   r   r   SafeConfigParserreadfpr'   get_metadata_lineshas_sectionitemsr   re   )rm   auto_confirmdist	dist_pathpaths_to_removedevelop_egg_linkdevelop_egg_link_egg_infoegg_info_existsdistutils_egg_infoinstalled_filer;   top_level_pkgeasy_install_eggeasy_install_pthfhlink_pointerr   bin_dirri   configrx   valuer?   )r   r@   	uninstallR  s    








zInstallRequirement.uninstallc             C   s$   | j r| j j  ntjd| j d S )Nz'Can't rollback %s, nothing uninstalled.)re   rollbackr   errorrx   )rm   r?   r?   r@   rollback_uninstall  s    z%InstallRequirement.rollback_uninstallc             C   s*   | j r| j j  n| js&tjd| j d S )Nz%Can't commit %s, nothing uninstalled.)re   commitrf   r   r2  rx   )rm   r?   r?   r@   commit_uninstall  s
    z#InstallRequirement.commit_uninstallc             C   s  | j s
td}d| j| j d f }tjj||}tjj|rtdt	| d}|dkr^d	}nj|dkrt
jd
t	| tj| nF|dkrt|}t
jdt	|t	| tj|| n|dkrtjd |rtj|dtjdd}tjjtjj| j}xtj|D ]\}	}
}d|
kr"|
jd xR|
D ]J}tjj|	|}| j||}tj| jd | d }d|_|j|d q(W xL|D ]D}|tkrq|tjj|	|}| j||}|j|| jd |  q|W qW |j  t
j dt	| d S )NTz	%s-%s.zipr   z8The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)bort iwbaFzDeleting %szBacking up %s to %sr6   )
allowZip64zpip-egg-info/i     r   zSaved %s)r6  r7  r8  r9  i  )!rV   r   rx   r   rN   r;   r   r   r   r   r   r   r   r    r   r   r   exitzipfileZipFileZIP_DEFLATEDr  r   r   r   _clean_zip_nameZipInfoexternal_attrwritestrr   writer   r  )rm   r   create_archivearchive_namearchive_pathresponse	dest_filezipr   dirpathr   r   r  rx   zipdirr   r?   r?   r@   archive  sX    







"zInstallRequirement.archivec             C   sJ   |j |tjj s"td||f |t|d d  }|jtjjd}|S )Nz$name %r doesn't start with prefix %rr6   r;  )rt   rN   r;   rO   r   r   replace)rm   rx   r  r?   r?   r@   rB  5  s
    z"InstallRequirement._clean_zip_namec                s0   |sd} j d k	r(t fdd|D S dS d S )Nr   c             3   s   | ]} j jd |iV  qdS )rD   N)r\   evaluate)rC   rD   )rm   r?   r@   rE   D  s   z3InstallRequirement.match_markers.<locals>.<genexpr>T)r   )r\   rP   )rm   extras_requestedr?   )rm   r@   match_markers=  s    


z InstallRequirement.match_markersc          ,      s^  | j r| j|||d d S | jrZtjj| j}tjj|| j | j	| j |d d| _
d S || jjdg 7 }|| jjdg 7 }| jrt|dg }tjdd}tjj|d	}z| j|| |}d
| jf }	t|	.}
t  t|| | jd|
d W d Q R X W d Q R X tjj|s&tjd| d S d| _
| jr8d S  fdd}t|H}x@|D ](}tjj|}|jdrT||}P qTW tj d|  d S W d Q R X g }t|P}xH|D ]@}|j! }tjj"|r|tjj#7 }|j$tjj%||| qW W d Q R X tjj|d}t|d}|j&dj|d  W d Q R X W d tjj|rPtj'| t(| X d S )N)r  )r   r  Tglobal_optionsinstall_optionsz--no-user-cfgz-recordzpip-zinstall-record.txtzRunning setup.py install for %sF)r   r   spinnerzRecord file %s not foundc                s(    d kst jj|  r| S t | S d S )N)rN   r;   isabsr   )r;   )r   r?   r@   prepend_rootz  s    z0InstallRequirement.install.<locals>.prepend_rootz	.egg-infoz;Could not find .egg-info directory in install record for %szinstalled-files.txtr7  
))rW   install_editabler   r  r   wheel_versionrV   check_compatibilityrx   r4   rd   ri   getrl   r   r   r   rN   r;   r   get_install_argsr1   r/   r%   r   r   r   r   r[   r  r  r   r   r   r   rO   appendrelpathrF  r   r   )rm   rU  rT  r   r  r   temp_locationrecord_filenameinstall_argsmsgrV  rX  r   line	directoryr   	new_linesr   inst_files_pathr?   )r   r@   installI  sv    




"
zInstallRequirement.installc             C   s   | j dkr| j|| _ | j S )aA  Ensure 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)rV   r   )rm   
parent_dirr?   r?   r@   ensure_has_source_dir  s    

z(InstallRequirement.ensure_has_source_dirc             C   s   t jdg}|jd |jt| j  |t|dd|g 7 }| jsJ|dg7 }|d k	r^|d|g7 }|d k	rr|d|g7 }| jr|dg7 }n
|d	g7 }t rd
t	j
  }|dtjjt jdd|| jg7 }|S )Nz-uz-cri  z--recordz#--single-version-externally-managedz--rootz--prefixz	--compilez--no-compiler   z--install-headersincludesite)r   r   r_  r0   r   r   r[   rj   r   r   get_python_versionrN   r;   r   r  rx   )rm   rT  rb  r   r  rc  
py_ver_strr?   r?   r@   r^    s(    



z#InstallRequirement.get_install_argsc             C   sd   | j r6tjjtjj| j tr6tjd| j  t| j  d| _ | j	rZtjj| j	rZt| j	 d| _	dS )zVRemove the source files from this requirement, if they are marked
        for deletionzRemoving source in %sN)
rV   rN   r;   r   r   r   r   r   r   ra   )rm   r?   r?   r@   remove_temporary_source  s    

z*InstallRequirement.remove_temporary_sourcec             C   s   t jd| j | jr"t|dg }|r>dj|g}t|| }t < ttj	dt
| j gt| ddg t| | jdd W d Q R X d	| _d S )
NzRunning setup.py develop for %sz--no-user-cfgz--prefix={0}z-cdevelopz	--no-depsF)r   r   T)r   r  rx   rl   r   r  r/   r%   r   r   r0   r   r   rd   )rm   rU  rT  r  prefix_paramr?   r?   r@   rZ    s     z#InstallRequirement.install_editablec             C   s   | j dkrdS yFtt| j }d|_tjt|| _| jrR| jrR| j| _d| _dS W nx tj	k
rj   dS  tj
k
r   tj| j j}| jrt|r|| _qt rt|rtd|j|jf n|| _Y nX dS )zFind 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)rK   r   r   r]   r   get_distributionr_   rW   r`   DistributionNotFoundVersionConflictrx   rg   r"   r   r#   r   r
  r   )rm   	no_markerexisting_distr?   r?   r@   r    s2    

z"InstallRequirement.check_if_existsc             C   s   | j o| j jS )N)rY   r   )rm   r?   r?   r@   r     s    zInstallRequirement.is_wheelc             C   s*   t | j| j|| j| j||| j| jd	 d S )N)userhomer   r  rj   rl   )r4   rx   rK   rg   rh   rj   rl   )rm   wheeldirr   r  r?   r?   r@   r4      s    
z#InstallRequirement.move_wheel_filesc             C   sX   | j djd}tjj|}tj||}tjjtjj|d }tj	tjj|||dS )zAReturn a pkg_resources.Distribution built from self.egg_info_pathr   r;  r   )r
  metadata)
r   rstriprN   r;   r  r   PathMetadatasplitextbasenameDistribution)rm   r   base_dirr{  	dist_namer?   r?   r@   get_dist+  s    
zInstallRequirement.get_distc             C   s   t | jjdi S )zReturn whether any known-good hashes are specified as options.

        These activate --require-hashes mode; hashes specified as part of a
        URL do not.

        hashes)boolri   r]  )rm   r?   r?   r@   has_hash_options6  s    z#InstallRequirement.has_hash_optionsc             C   sJ   | j jdi j }|r| jn| j}|rB|jrB|j|jg 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  )
ri   r]  copyrY   rZ   hash
setdefault	hash_namer_  r-   )rm   trust_internetgood_hashesrY   r?   r?   r@   r  @  s
    
zInstallRequirement.hashes)NFNFTTNFNNF)NNFNNF)NFNNF)T)F)N)NN)T).r   
__module____qualname__rp   classmethodr|   r   r   r   r   propertyr   r   r   r   r   rx   r   r   r   r   r   r   r8   compile_requirements_section_rer   r   r   r0  r3  r5  rO  rB  rS  ri  rk  r^  rp  rZ  r  r   r4   r  r  r  r?   r?   r?   r@   rH   I   sb      
;   M
 :6


 $0
W)

rH   c             C   s   t jd| }|r|jd} | S )z2
        Strip req postfix ( -dev, 0.2, etc )
    z^(.*?)(?:-dev|-\d.*)$r6   )r8   r   r:   )rK   r9   r?   r?   r@   _strip_postfixV  s    
r  c             C   s  ddl m} | }d}tjd|}|r:|jd}|jd}n|}tjj|rttjjtjj	|dslt
d| t|}|j jd	r||j}|r||td
|j  jfS ||dfS x,tD ]$}|j jd| rd||f }P qW d|kr|r
tjdt |d | }nt
d|  |jddd j }	tj|	s`d|  dj	dd tjD  d }
t
|
||j}|sxt
d|st
d|  t||dfS )a   Parses 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   )rq   Nz^(.+)(\[[^\]]+\])$r6   r7   zsetup.pyz;Directory %r is not installable. File 'setup.py' not found.zfile: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+zFor --editable=%s only z, c             S   s   g | ]}|j d  qS )z+URL)rx   )rC   r   r?   r?   r@   r     s    z"parse_editable.<locals>.<listcomp>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)rr   rq   r8   r9   r:   rN   r;   r   r   r   r   r   r   rt   r   r   r=   r3   r  r  r.   r   r   backendsr  )rv   rw   rq   ry   r=   r<   url_no_extraspackage_nameversion_controlr   error_messager?   r?   r@   rs   b  s`    





rs   )N)d
__future__r   loggingrN   r8   r   r   r   rR   r  r?  	distutilsr   distutils.utilr   email.parserr   pip._vendorr   r   Zpip._vendor.packagingr   Zpip._vendor.packaging.markersr	   Z"pip._vendor.packaging.requirementsr
   r   pip._vendor.packaging.utilsr   Zpip._vendor.packaging.versionr   r   r   pip._vendor.six.movesr   	pip.wheelr  
pip.compatr   r   r   pip.downloadr   r   r   r   pip.exceptionsr   r   pip.locationsr   r   r   r   	pip.utilsr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   pip.utils.hashesr-   Zpip.utils.deprecationr.   pip.utils.loggingr/   pip.utils.setuptools_buildr0   pip.utils.uir1   pip.req.req_uninstallr2   pip.vcsr3   r4   r5   	getLoggerr   r   	Specifier
_operatorskeysrQ   rA   rG   objectrH   r  rs   r?   r?   r?   r@   <module>   s`   H
        