3
LY.                 @   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   c/private/var/folders/7d/20zwc49s3kn54d3vgq8bd4640000gn/T/pip-build-an2lx5zf/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 )zSplit, 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	}|rtj|| i }x.tD ]&}||jkr|j| r|j| ||< qW 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|stjjtjj||}t|||||||d}	x|	D ]}|V  qW n>|j r|j |_ n*|r|j!rt"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rd|_4|j5rd|_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 )zBreak 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 )zJoins 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   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   
 
   
 