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ˆ        (      óýø +ö