U .e7 @sdZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl mZddlmZddlmZdd lmZdd lmZmZdd lmZer 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.dZ1e.dZ2ej3ej4ej5ej6ej7ej8ej9ej:ej;ejej?g Z@ejAejBejCgZDddeDDZEd)ddZFddZGd*ddZHddZIdd ZJd!d"ZKd#d$ZLd%d&ZMd'd(ZNdS)+z Requirements file parsing )absolute_importN) filterfalse)parse) cmdoptions)get_file_contentRequirementsFileParseError) SearchScope)install_req_from_editableinstall_req_from_line)MYPY_CHECK_RUNNING)AnyCallableIteratorListNoReturnOptionalTextTuple)InstallRequirement) WheelCache) PackageFinder) PipSessionparse_requirementsz^(http|https|file):z (^|\s+)#.*$z#(?P\$\{(?P[A-Z0-9_]+)\})cCsg|]}t|jqS)strdest).0orr>/usr/lib/python3.8/site-packages/pip/_internal/req/req_file.py Ksr Fc csj|dkrtdt|||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_fromsession) use_pep517 constraint) TypeErrorr preprocess process_line)filenamefinderr!optionsr"r$ wheel_cacher#_content lines_enum line_numberlineZreq_iterreqrrrrNs*    cCs6t|dd}t|}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_linesignore_comments skip_regexexpand_env_variables)r-r*r.rrrr&ys  r&c ! cst|} | } d| _|r"|j| _t|\} } tjdkrB| d} | t | | \}}d| rbdnd||f}| r|r||j nd}|rt ||i}tD]&}||jkr|j|r|j|||<qd||}t| |||||| |d Vn|jr |r|j nd}t|jd ||| ||d Vn|js0|jr|jrH|jd }d}n|jd }d }t|rpt||}n"t|stjtj||}t|||||||d }|D] }|Vqn|jr|j|_n|r|j }|j!}|jr|jg}|j"d krg}|j#r|$|j#|j rd|j d }tjtj%|}tj||}tj&|rZ|}|'|t(||d}||_)|j*r|+|j,pgD] }d||} |j-|| dqdS)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_controlbreak_args_optionssys version_infoencode parse_argsshlexsplitZ isolated_moderZcheck_install_build_globalSUPPORTED_OPTIONS_REQ_DEST__dict__formatr Z editablesr requirements constraints SCHEME_REsearch urllib_parseZurljoinospathjoindirnamerrequire_hashesr@rAno_indexZextra_index_urlsextendabspathexistsappendr search_scopepreZset_allow_all_prereleasesZ trusted_hostsZadd_trusted_host)!r0r(r/r)r!r*r"r+r#r$parserdefaultsZargs_strZ options_strZoptsr,Zline_comes_fromr>Z req_optionsrr?Zreq_pathZnested_constraintZ parsed_reqsr1r@rAvalueZreq_dirZrelative_to_reqs_filer^ZhostrBrrrr's                   r'cCsf|d}g}|dd}|D]2}|ds6|dr<qRq|||dqd|d|fS)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)rK startswithr]poprV)r0tokensargsr*tokenrrrrEs    rEcsDtjdd}tt}|D]}|}||qfdd}||_|S)z7 Return a parser for parsing requirement lines F)Zadd_help_optioncsd|f}t|dS)NzInvalid requirement: %s %sr)selfmsgr0rr parser_exit6s z!build_parser..parser_exit)optparseZ OptionParserSUPPORTED_OPTIONSSUPPORTED_OPTIONS_REQZ add_optionexit)r0r`Zoption_factoriesZoption_factoryZoptionrmrrlrrC(s   rCccsd}g}|D]v\}}|dr(t|rjt|r:d|}|r^|||d|fVg}q||fVq |sr|}||dq |r|d|fVdS)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\rc)endswith COMMENT_REmatchr]rVstrip)r.Zprimary_line_numberZnew_liner/r0rrrr6Bs     r6ccs4|D]*\}}td|}|}|r||fVqdS)z1 Strips comments and filter empty lines. rsN)rusubrw)r.r/r0rrrr7`s   r7cs2|r |jnd}|r.t|tfdd|}|S)zs Skip lines that match '--skip-requirements-regex' pattern Note: the regex pattern is only built once Ncs|dS)Nr2)rR)epatternrrvzskip_regex..)Zskip_requirements_regexrecompiler)r.r*r8rrzrr8ls  r8ccsL|D]B\}}t|D]$\}}t|}|s.q|||}q||fVqdS)aReplace 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_REfindallrTgetenvreplace)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.sessionrintZ ReqFileLines__all__rIrQrurrPZeditablerOrYrDr@Zextra_index_urlZ always_unzipZ no_binaryZ only_binaryr_Z trusted_hostrXroZinstall_optionsZglobal_optionshashrprLrr&r'rErCr6r7r8r9rrrrs        (       +