U ��.e�7� @s�dZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl mZddlmZddlmZdd lmZdd lmZmZdd lmZe�r dd lmZmZmZmZmZm Z m!Z!m"Z"dd l#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*ee"e+e!fZ,dgZ-e�.dej/�Z0e�.d�Z1e�.d�Z2ej3ej4ej5ej6ej7ej8ej9ej:ej;ejej?g Z@ejAejBejCgZDdd�eDD�ZEd)dd�ZFdd�ZGd*dd�ZHdd�ZIdd �ZJd!d"�ZKd#d$�ZLd%d&�ZMd'd(�ZNdS)+z Requirements file parsing �)�absolute_importN)� filterfalse)�parse)� cmdoptions)�get_file_content��RequirementsFileParseError)� SearchScope)�install_req_from_editable�install_req_from_line)�MYPY_CHECK_RUNNING)�Any�Callable�Iterator�List�NoReturn�Optional�Text�Tuple)�InstallRequirement)� WheelCache)� PackageFinder)� PipSession�parse_requirementsz^(http|https|file):z (^|\s+)#.*$z#(?P\$\{(?P[A-Z0-9_]+)\})cCsg|]}t|�j��qS�)�str�dest)�.0�orr�>/usr/lib/python3.8/site-packages/pip/_internal/req/req_file.py� Ksr Fc csj|dkrtd��t|||d�\}} t| |�} | D]4\} } t| || |||||||d� } | D] }|VqXq0dS)a1Parse 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 :param use_pep517: Value of the --use-pep517 option. NzCparse_requirements() missing 1 required keyword argument: 'session')� comes_from�session)� use_pep517� constraint)� TypeErrorr� preprocess� process_line)�filename�finderr!�optionsr"r$� wheel_cacher#�_�content� lines_enum� line_number�lineZreq_iter�reqrrrrNs*��    �cCs6t|��dd�}t|�}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�expand_env_variables)r-r*r.rrrr&ys  r&c ! cs�t|�} | ��} d| _|r"|j| _t|�\} } tjdkrB| �d�} | �t � | �| �\}}d| rbdnd||f}| r�|r||j nd}|r�t � ||�i}tD]&}||jkr�|j|r�|j|||<q�d�||�}t| |||||| |d �V�n�|j�r |r�|j nd}t|jd ||| ||d �V�n�|j�s0|j�r�|j�rH|jd }d}n|jd }d }t�|��rpt�||�}n"t�|��s�tj�tj�|�|�}t|||||||d �}|D] }|V�q�n�|j�r�|j|_n�|�r�|j }|j!}|j�r�|jg}|j"d k�rg}|j#�r|�$|j#�|j �rd|j d }tj�tj�%|��}tj�||�}tj�&|��rZ|}|�'|�t(||d�}||_)|j*�r�|�+�|j,�p�gD] }d�||�} |j-|| d��q�dS)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-rFz line {} of {})r!r#�isolatedr*r+r$� line_sourcer)r!r#r$r>r+T)r$r+)� find_links� index_urls)�source).� build_parserZget_default_values� index_urlZformat_control�break_args_options�sys� version_info�encode� parse_args�shlex�splitZ isolated_moderZcheck_install_build_global�SUPPORTED_OPTIONS_REQ_DEST�__dict__�formatr Z editablesr � requirements� constraints� SCHEME_RE�search� urllib_parseZurljoin�os�path�join�dirnamer�require_hashesr@rA�no_indexZextra_index_urls�extend�abspath�exists�appendr � search_scope�preZset_allow_all_prereleasesZ trusted_hostsZadd_trusted_host)!r0r(r/r)r!r*r"r+r#r$�parser�defaultsZargs_strZ options_strZoptsr,Zline_comes_fromr>Z req_optionsrr?Zreq_pathZnested_constraintZ parsed_reqsr1r@rA�valueZreq_dirZrelative_to_reqs_filer^ZhostrBrrrr'�s�   � �  � �     �      � r'cCsf|�d�}g}|dd�}|D]2}|�d�s6|�d�r<qRq|�|�|�d�qd�|�d�|�fS)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)rK� startswithr]�poprV)r0�tokens�argsr*�tokenrrrrEs    rEcsDtjdd�}tt}|D]}|�}|�|�q�fdd�}||_|S)z7 Return a parser for parsing requirement lines F)Zadd_help_optioncsd�|f}t|��dS)NzInvalid requirement: %s %sr)�self�msg�r0rr� parser_exit6s z!build_parser..parser_exit)�optparseZ OptionParser�SUPPORTED_OPTIONS�SUPPORTED_OPTIONS_REQZ add_option�exit)r0r`Zoption_factoriesZoption_factoryZoptionrmrrlrrC(s   rCccs�d}g}|D]v\}}|�d�r(t�|�rjt�|�r:d|}|r^|�|�|d�|�fVg}q�||fVq |sr|}|�|�d��q |r�|d�|�fVdS)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�\rc�)�endswith� COMMENT_RE�matchr]rV�strip)r.Zprimary_line_numberZnew_liner/r0rrrr6Bs     r6ccs4|D]*\}}t�d|�}|��}|r||fVqdS)z1 Strips comments and filter empty lines. rsN)ru�subrw)r.r/r0rrrr7`s   r7cs2|r |jnd}|r.t�|��t�fdd�|�}|S)zs Skip lines that match '--skip-requirements-regex' pattern Note: the regex pattern is only built once Ncs��|d�S)Nr2)rR)�e��patternrr�v�zskip_regex..)Zskip_requirements_regex�re�compiler)r.r*r8rrzrr8ls  r8ccsL|D]B\}}t�|�D]$\}}t�|�}|s.q|�||�}q||fVqdS)a�Replace all environment variables that can be retrieved via `os.getenv`. The only allowed format for environment variables defined in the requirement file is `${MY_VARIABLE_1}` to ensure two things: 1. Strings that contain a `$` aren't accidentally (partially) expanded. 2. Ensure consistency across platforms for requirement files. These points are the result of a discussion on the `github pull request #3514 `_. Valid characters in variable names follow the `POSIX standard `_ and are limited to uppercase letter, digits and the `_` (underscore). N)� ENV_VAR_RE�findallrT�getenv�replace)r.r/r0Zenv_varZvar_namerbrrrr9zs  r9)NNNNFNN)NNNNNNF)O�__doc__Z __future__rrnrTr~rJrFZpip._vendor.six.movesrZpip._vendor.six.moves.urllibrrSZpip._internal.clirZpip._internal.downloadrZpip._internal.exceptionsrZ!pip._internal.models.search_scoper Zpip._internal.req.constructorsr r Zpip._internal.utils.typingr �typingr rrrrrrrZpip._internal.reqrZpip._internal.cacherZpip._internal.indexrZpip._internal.network.sessionr�intZ ReqFileLines�__all__r�IrQrur�rPZeditablerOrYrDr@Zextra_index_urlZ always_unzipZ no_binaryZ only_binaryr_Z trusted_hostrXroZinstall_optionsZglobal_options�hashrprLrr&r'rErCr6r7r8r9rrrr�s�        (      ��� +�