3
zYði–.  ã               @   sx  d Z 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	m
Z ddlm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 dd
lmZ dgZejdejƒZejdƒZejejejej ej!ej"ej#ej$ej%ej&ej'ej(ej)ej*ej+ej,ej-ej.ej/ej0ej1gZ2ej3ej4ej5gZ6dd„ e6D ƒZ7d dd„Z8dd„ Z9d!dd„Z:dd„ Z;dd„ Z<dd„ Z=dd„ Z>dd„ Z?dS )"z
Requirements file parsing
é    )Úabsolute_importN)Úparse)Úfilterfalse)Úget_file_content)ÚInstallRequirement)ÚRequirementsFileParseError)ÚRemovedInPip10Warning)Ú
cmdoptionsÚparse_requirementsz^(http|https|file):z(^|\s)+#.*$c             C   s   g | ]}|ƒ j ‘qS © )Údest)Ú.0Úor   r   ú//tmp/pip-build-ue6tjl93/pip/pip/req/req_file.pyú
<listcomp>=   s    r   Fc             c   sp   |dkrt dƒ‚t| ||d�\}}t||ƒ}	x>|	D ]6\}
}t|| |
||||||d�	}x|D ]
}|V  qZW q2W dS )a÷  Parse a requirements file and yield InstallRequirement instances.

    :param filename:    Path or url of requirements file.
    :param finder:      Instance of pip.index.PackageFinder.
    :param comes_from:  Origin description of requirements.
    :param options:     cli options.
    :param session:     Instance of pip.download.PipSession.
    :param constraint:  If true, parsing a constraint file rather than
        requirements file.
    :param wheel_cache: Instance of pip.wheel.WheelCache
    NzCparse_requirements() missing 1 required keyword argument: 'session')Ú
comes_fromÚsession)Ú
constraint)Ú	TypeErrorr   Ú
preprocessÚprocess_line)ÚfilenameÚfinderr   Úoptionsr   r   Úwheel_cacheÚ_ÚcontentÚ
lines_enumÚline_numberÚlineÚreq_iterÚreqr   r   r   r
   @   s    


c             C   s.   t | jƒ dd�}t|ƒ}t|ƒ}t||ƒ}|S )z˜Split, filter, and join lines, and return a line iterator

    :param content: the content of the requirements file
    :param options: cli options
    é   )Ústart)Ú	enumerateÚ
splitlinesÚ
join_linesÚignore_commentsÚ
skip_regex)r   r   r   r   r   r   r   a   s
    
r   c	          	   c   s
  t ƒ }	|	jƒ }
d|
_|r |j|
_t| ƒ\}}tjdk r@|jdƒ}|	jt	j
|ƒ|
ƒ\}}d|r`dnd||f }|rÞ|rz|jnd	}|rŽtj||ƒ i }x.tD ]&}||jkr˜|j| r˜|j| ||< q˜W tj||||||d
�V  �n(|j�r&|rð|jnd	}|�r |jnd}tj|jd |||||d�V  �nà|j�s6|j�rÈ|j�rN|jd }d	}n|jd }d}tj|ƒ�rvtj||ƒ}n"tj|ƒ�s˜tjjtjj|ƒ|ƒ}t|||||||d�}	x|	D ]}|V  �q´W �n>|j �rÜ|j |_ �n*|�r|j!�röt"j#dt$ƒ |j%�r
t"j#dt$ƒ |j&�rt"j#dt$ƒ |j�r0|jg|_'|j(d	k�rPd	|_(t)j*j+|jƒ |j,dk�rbg |_'|j-�rx|j'j.|j-ƒ |j/�rÊ|j/d }tjjtjj0|ƒƒ}tjj||ƒ}tjj1|ƒ�r¾|}|j/j2|ƒ |j3�rØd|_4|j5�ræd|_5|j6�r|j7j.dd„ |j6D ƒƒ dS )a#  Process a single requirements line; This can result in creating/yielding
    requirements, or updating the finder.

    For lines that contain requirements, the only options that have an effect
    are from SUPPORTED_OPTIONS_REQ, and they are scoped to the
    requirement. Other options from SUPPORTED_OPTIONS may be present, but are
    ignored.

    For lines that do not contain requirements, the only options that have an
    effect are from SUPPORTED_OPTIONS. Options from SUPPORTED_OPTIONS_REQ may
    be present, but are ignored. These lines may contain multiple options
    (although our docs imply only one is supported), and all our parsed and
    affect the finder.

    :param constraint: If True, parsing a constraints file.
    :param options: OptionParser options that we may update
    Né   é   é   Úutf8z%s %s (line %s)z-cz-rF)r   Úisolatedr   r   r   )r   r   Údefault_vcsr-   r   T)r   r   z�--allow-external has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.z“--allow-all-external has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.z‘--allow-unverified has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.c             s   s   | ]}d |d fV  qdS )Ú*Nr   )r   Úhostr   r   r   ú	<genexpr>ú   s    zprocess_line.<locals>.<genexpr>)r)   r*   r+   )8Úbuild_parserÚget_default_valuesÚ	index_urlÚformat_controlÚbreak_args_optionsÚsysÚversion_infoÚencodeÚ
parse_argsÚshlexÚsplitÚisolated_moder	   Úcheck_install_build_globalÚSUPPORTED_OPTIONS_REQ_DESTÚ__dict__r   Ú	from_lineÚ	editablesr.   Úfrom_editableÚrequirementsÚconstraintsÚ	SCHEME_REÚsearchÚurllib_parseÚurljoinÚosÚpathÚjoinÚdirnamer
   Úrequire_hashesÚallow_externalÚwarningsÚwarnr   Úallow_all_externalÚallow_unverifiedÚ
index_urlsÚ	use_wheelÚpipÚindexÚfmt_ctl_no_use_wheelÚno_indexÚextra_index_urlsÚextendÚ
find_linksÚabspathÚexistsÚappendÚpreÚallow_all_prereleasesÚprocess_dependency_linksÚtrusted_hostsÚsecure_origins)r   r   r   r   r   r   r   r   r   ÚparserÚdefaultsÚargs_strÚoptions_strÚoptsr   Úline_comes_fromr-   Úreq_optionsr   r.   Úreq_pathÚnested_constraintr!   ÚvalueÚreq_dirÚrelative_to_reqs_filer   r   r   r   n   s¤    










r   c             C   sh   | j dƒ}g }|dd… }x8|D ]0}|jdƒs8|jdƒr<P q |j|ƒ |jdƒ q W dj|ƒdj|ƒfS )z½Break up the line into an args and options string.  We only want to shlex
    (and then optparse) the options, not the args.  args can contain markers
    which are corrupted by shlex.
    ú Nú-z--r   )r<   Ú
startswithr_   ÚpoprL   )r   ÚtokensÚargsr   Útokenr   r   r   r6   ý   s    


r6   c              C   sD   t jdd�} tt }x|D ]}|ƒ }| j|ƒ qW dd„ }|| _| S )z7
    Return a parser for parsing requirement lines
    F)Úadd_help_optionc             S   s   t |ƒ‚d S )N)r   )ÚselfÚmsgr   r   r   Úparser_exit  s    z!build_parser.<locals>.parser_exit)ÚoptparseÚOptionParserÚSUPPORTED_OPTIONSÚSUPPORTED_OPTIONS_REQÚ
add_optionÚexit)re   Úoption_factoriesÚoption_factoryÚoptionr{   r   r   r   r2     s    
r2   c             c   s¢   d}g }x€| D ]x\}}|j dƒ s,tj|ƒrntj|ƒr>d| }|rb|j|ƒ |dj|ƒfV  g }q†||fV  q|sv|}|j|jdƒƒ qW |rž|dj|ƒfV  dS )z’Joins a line ending in '' with the previous line (except when following
    comments).  The joined line takes on the index of the first line.
    Nú\rq   Ú )ÚendswithÚ
COMMENT_REÚmatchr_   rL   Ústrip)r   Úprimary_line_numberÚnew_liner   r   r   r   r   r&   "  s     

r&   c             c   s8   x2| D ]*\}}t jd|ƒ}|jƒ }|r||fV  qW dS )z1
    Strips comments and filter empty lines.
    r†   N)rˆ   ÚsubrŠ   )r   r   r   r   r   r   r'   ?  s
    r'   c                s2   |r
|j nd}|r.tj|ƒ‰ t‡ fdd„| ƒ} | S )zs
    Skip lines that match '--skip-requirements-regex' pattern

    Note: the regex pattern is only built once
    Nc                s   ˆ j | d ƒS )Nr"   )rG   )Úe)Úpatternr   r   Ú<lambda>T  s    zskip_regex.<locals>.<lambda>)Úskip_requirements_regexÚreÚcompiler   )r   r   r(   r   )r�   r   r(   J  s    

r(   )NNNNFN)NNNNNF)@Ú__doc__Ú
__future__r   rJ   r’   r;   r7   r|   rP   Zpip._vendor.six.moves.urllibr   rH   Zpip._vendor.six.movesr   rV   Úpip.downloadr   Zpip.req.req_installr   Úpip.exceptionsr   Zpip.utils.deprecationr   r	   Ú__all__r“   ÚIrF   rˆ   rE   ÚeditablerD   rY   r4   r\   Úextra_index_urlrO   rR   Úno_allow_externalÚallow_unsafeÚno_allow_unsaferU   Úno_use_wheelÚalways_unzipÚ	no_binaryÚonly_binaryr`   rb   Útrusted_hostrN   r~   Úinstall_optionsÚglobal_optionsÚhashr   r?   r
   r   r   r6   r2   r&   r'   r(   r   r   r   r   Ú<module>   sn   
 
   
 