o 7]h D@s^UdZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z m Z m Z mZmZmZmZddlmZddlmZmZddlmZddlmZdd lmZdd lmZdd lm Z e rmdd lm!Z!dd l"m#Z#dgZ$e ee%e&fZ'e e&gee&effZ(e)dej*Z+e)dZ,e)dZ-ej.ej/ej0ej1ej2ej3ej4ej5ej6ej7ej8ej9ej:ej;gZd<ej?ej@ejAgZBee dej=fe>d<ddeBDZCGdddZDGdddZE   dDde&dededd eejd!eFd"eeDf d#dZGd$e&d"e'fd%d&ZH dEd'eEd eejd"eDfd(d)ZI   dFd*ede&d+e%dedd eejdeed"dfd,d-ZJ   dFd'eEd eejdeddeed"eeDf d.d/ZKGd0d1d1ZLdedd"e(fd2d3ZMd'e&d"ee&e&ffd4d5ZNGd6d7d7eOZPd"ejQfd8d9ZRd:e'd"e'fd;d<ZSd:e'd"e'fd=d>ZTd:e'd"e'fd?d@ZUdAe&ded"ee&e&ffdBdCZVdS)Gz Requirements file parsing N)Values) TYPE_CHECKINGAnyCallableDictIterableIteratorListOptionalTuple) cmdoptions)InstallationErrorRequirementsFileParseError) SearchScope) PipSession)raise_for_status) auto_decode)get_url_scheme)NoReturn) PackageFinderparse_requirementsz^(http|https|file):z (^|\s+)#.*$z#(?P\$\{(?P[A-Z0-9_]+)\}).SUPPORTED_OPTIONSSUPPORTED_OPTIONS_REQcCsg|]}t|jqS)strdest).0orrNsrc@sHeZdZ  d dededededeeeefdeeddfd d ZdS) ParsedRequirementN requirement is_editable comes_from constraintoptions line_sourcereturncCs(||_||_||_||_||_||_dSN)r!r"r#r%r$r&)selfr!r"r#r$r%r&rrr__init__Rs   zParsedRequirement.__init__)NN) __name__ __module__ __qualname__rboolr rrr*rrrrr Qs$r c @s.eZdZdedededededdf dd ZdS) ParsedLinefilenamelinenoargsoptsr$r'NcCs^||_||_||_||_|rd|_d|_||_dS|jr*d|_d|_|jd|_dSd|_dS)NTFr)r0r1r3r$is_requirementr"r! editables)r)r0r1r2r3r$rrrr*ds  zParsedLine.__init__)r+r,r-rintrr.r*rrrrr/csr/Fr0sessionfinderrr%r$r'c csHt|}t||}|||D]}t||||d}|dur!|VqdS)aqParse a requirements file and yield ParsedRequirement instances. :param filename: Path or url of requirements file. :param session: PipSession instance. :param finder: Instance of pip.index.PackageFinder. :param options: cli options. :param constraint: If true, parsing a constraint file rather than requirements file. )r%r8r7N)get_line_parserRequirementsFileParserparse handle_line) r0r7r8r%r$ line_parserparser parsed_line parsed_reqrrrr~s contentcCs,t|dd}t|}t|}t|}|S)zxSplit, filter, and join lines, and return a line iterator :param content: the content of the requirements file )start) enumerate splitlines join_linesignore_commentsexpand_env_variables)rA lines_enumrrr preprocesss rJlinecCsd|jrdnd|j|j}|jsJ|jr!t|j|j||jdS|r*t ||j i}t D]}||j j vrD|j j |rD|j j |||<q.d|jd|j}t|j|j||j||dS)Nz{} {} (line {})z-cz-r)r!r"r#r$line  of )r!r"r#r$r%r&) formatr$r0r1r4r"r r!r check_install_build_globalr3SUPPORTED_OPTIONS_REQ_DEST__dict__)rKr%line_comes_from req_optionsrr&rrrhandle_requirement_lines:  rTr3r1cs8r|jr |j_|jrjfdd|jD|r|j}|j}|jr)|jg}|jdur0g}|jr9||j|jr_|jd}tj tj |} tj | |} tj | rZ| }|||rf||t||d} | |_|jrv||jr}||r|jpgD]} d|d|} |j| | dqdSdSdS) Nc3s|] }|jvr|VqdSr()features_enabled)rfr%rr sz%handle_option_line..Tr) find_links index_urlsrLrM)source)require_hashesrUextendrYrZ index_urlno_indexextra_index_urlsospathdirnameabspathjoinexistsappendupdate_index_urlsr search_scopepreset_allow_all_prereleases prefer_binaryset_prefer_binary trusted_hostsadd_trusted_host)r3r0r1r8r%r7rYrZvaluereq_dirrelative_to_reqs_filerihostr[rrWrhandle_option_linesR       $rtcCs0|jr t||}|St|j|j|j|||dS)aHandle a single parsed requirements line; This can result in creating/yielding requirements, or updating the finder. :param line: The parsed line to be processed. :param options: CLI options. :param finder: The finder - updated by non-requirement lines. :param session: The session - updated by non-requirement lines. Returns a ParsedRequirement object if the line is a requirement line, otherwise returns None. 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. N)r4rTrtr3r0r1)rKr%r8r7r@rrrr<s r<c@speZdZdededdfddZdededee fd d Z dededee fd d Z dededee fd dZ dS)r:r7r=r'NcCs||_||_dSr()_session _line_parser)r)r7r=rrrr*<s zRequirementsFileParser.__init__r0r$ccs|||EdHdS)z*Parse a given file, yielding parsed lines.N)_parse_and_recurse)r)r0r$rrrr;DszRequirementsFileParser.parseccs|||D]L}|jsP|jjs|jjrP|jjr!|jjd}d}n|jjd}d}t|r6tj ||}nt|sFt j t j ||}|||EdHq|VqdS)NrFT) _parse_filer4r3 requirements constraints SCHEME_REsearchurllibr;urljoinrarbrercrw)r)r0r$rKreq_pathnested_constraintrrrrwHs,     z)RequirementsFileParser._parse_and_recursec cst||j\}}t|}|D]0\}}z ||\}} Wnty5} z d|d| j} t| d} ~ wwt|||| |VqdS)NzInvalid requirement:  )get_file_contentrurJrvOptionParsingErrormsgrr/) r)r0r$_rArI line_numberrKargs_strr3errrrrxgs& z"RequirementsFileParser._parse_file) r+r,r-r LineParserr*rr.rr/r;rwrxrrrrr:;s"  r:cs"dtdtttfffdd }|S)NrKr'csJt}|}d|_rj|_t|\}}|t||\}}||fSr() build_parserget_default_valuesr^format_controlbreak_args_options parse_argsshlexsplit)rKr>defaultsr options_strr3rr8rr parse_line~s z#get_line_parser..parse_line)rr r)r8rrrrr9}sr9cCsd|d}g}|dd}|D]}|ds|drn |||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)r startswithrgpopre)rKtokensr2r%tokenrrrrs    rc@seZdZdeddfddZdS)rrr'NcCs ||_dSr()rr)rrrrr*s zOptionParsingError.__init__)r+r,r-rr*rrrrrsrcCsNtjdd}tt}|D] }|}||q dtdtddfdd}||_|S) z7 Return a parser for parsing requirement lines F)add_help_optionr)rr'rcSst|r()rrrrr parser_exitsz!build_parser..parser_exit)optparse OptionParserrr add_optionrrexit)r>option_factoriesoption_factoryoptionrrrrrs  rrIccsd}g}|D]A\}}|drt|r`_. Valid characters in variable names follow the `POSIX standard `_ and are limited to uppercase letter, digits and the `_` (underscore). N) ENV_VAR_REfindallragetenvreplace)rIrrKenv_varvar_namerprrrrHs   rHurlc Cst|}|dvr||}t||j|jfSz%t|d}t|}Wdn 1s.wYW||fSW||fStyO}zt d|d}~ww)aGets the content of a file; it may be a filename, file: URL, or http: URL. Returns (location, content). Content is unicode. Respects # -*- coding: declarations on the retrieved files. :param url: File path or url. :param session: PipSession instance. )httphttpsfilerbNz"Could not open requirements file: ) rgetrrtextopenrreadOSErrorr )rr7schemeresprVrAexcrrrrs    r)NNFr()NNN)W__doc__rrarer urllib.parser}rtypingrrrrrrr r r pip._internal.clir pip._internal.exceptionsr r!pip._internal.models.search_scoperpip._internal.network.sessionrpip._internal.network.utilsrpip._internal.utils.encodingrpip._internal.utils.urlsrr"pip._internal.index.package_finderr__all__r6r ReqFileLinesrcompileIr{rrr^extra_index_urlr_rzryeditablerY no_binary only_binaryrlr\rj trusted_hostuse_new_featurerOption__annotations__install_optionsglobal_optionshashrrPr r/r.rrJrTrtr<r:r9r ExceptionrrrrFrGrHrrrrrs ,            1 ? ,B "