3 Bu_K@sVdZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl mZmZddlmZddlmZdd lmZdd lmZdd lmZerdd lmZdd lmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ddl%m&Z&ddl'm(Z(ee$e)e#fZ*ee#ge$e+effZ,dgZ-ej.dej/Z0ej.dZ1ej.dZ2e j3e j4e j5e j6e j7e j8e j9e j:e j;e je j?e j@gZAe jBe jCe jDgZEddeEDZFGdddeGZHGdddeGZId7ddZJddZKd8ddZLd9d d!ZMd:d"d#ZNGd$d%d%eGZOd&d'ZPd(d)ZQGd*d+d+eRZSd,d-ZTd.d/ZUd0d1ZVd2d3ZWd;d4d5ZXej.d6ej/ZYdS)\$\{(?P[A-Z0-9_]+)\})cCsg|]}t|jqS)strdest).0orr/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-1.el7.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_internal/req/req_file.py Lsrc@seZdZdddZdS)ParsedRequirementNcCs(||_||_||_||_||_||_dS)N) requirement is_editable comes_fromoptions constraint line_source)selfr!r"r#r%r$r&rrr__init__Ps zParsedRequirement.__init__)NN)__name__ __module__ __qualname__r(rrrrr Osr c@seZdZddZdS) ParsedLinecCs`||_||_||_||_||_|r6d|_d|_||_n&|jrVd|_d|_|jd|_nd|_dS)NTFr) filenamelinenor#optsr%is_requirementr"r! editables)r'r-r.r#argsr/r%rrrr(cs zParsedLine.__init__N)r)r*r+r(rrrrr,bsr,Fc csLt|}t|||}x2|j||D]"}t||||d} | dk r"| Vq"WdS)aParse 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 comes_from: Origin description of requirements. :param options: cli options. :param constraint: If true, parsing a constraint file rather than requirements file. )r$findersessionN)get_line_parserRequirementsFileParserr handle_line) r-r4r3r#r$r% line_parserparser parsed_line parsed_reqrrrrs cCs,t|jdd}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)content lines_enumrrr preprocesss rEcCsdj|jrdnd|j|j}|js&t|jrBt|j|j||jdS|rTt j ||j i}x4t D],}||j j kr^|j j |r^|j j |||<q^Wdj|j|j}t|j|j||j||dSdS)Nz{} {} (line {})z-cz-r)r!r"r#r%z line {} of {})r!r"r#r%r$r&)formatr%r-r.r0AssertionErrorr"r r!rcheck_install_build_globalr/SUPPORTED_OPTIONS_REQ_DEST__dict__)liner$line_comes_from req_optionsrr&rrrhandle_requirement_lines.   rNcs(r4|jr|j_|jr4jjfdd|jD|r$|j}|j}|jrT|jg}|jdkrbg}|jrt|j|j|jr|jd}tj j tj j |} tj j | |} tj j | r| }|j|t||d} | |_|jr|j|jr|j|r$x.|jpgD] } dj||} |j| | dqWdS)Nc3s|]}|jkr|VqdS)N)features_enabled)rf)r$rr sz%handle_option_line..Tr) find_links index_urlsz line {} of {})source)require_hashesrOextendrRrS index_urlno_indexextra_index_urlsospathdirnameabspathjoinexistsappendr search_scopepreset_allow_all_prereleases prefer_binaryset_prefer_binary trusted_hostsrFadd_trusted_host)r/r-r.r3r$r4rRrSvaluereq_dirrelative_to_reqs_filerahostrTr)r$rhandle_option_linesD       rlcCs4|jrt||}|St|j|j|j|||dSdS)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)r0rNrlr/r-r.)rKr$r3r4r;rrrr7s r7c@s,eZdZddZddZddZddZd S) r6cCs||_||_||_dS)N)_session _line_parser _comes_from)r'r4r8r#rrrr(CszRequirementsFileParser.__init__ccs x|j||D] }|VqWdS)z3Parse a given file, yielding parsed lines. N)_parse_and_recurse)r'r-r%rKrrrrNszRequirementsFileParser.parseccsx|j||D]}|j r|jjs*|jjr|jjrD|jjd}d}n|jjd}d}tj|rltj||}n tj|st j j t j j ||}x"|j ||D] }|VqWq|VqWdS)NrFT) _parse_filer0r/ requirements constraints SCHEME_REsearch urllib_parseurljoinrZr[r^r\rp)r'r-r%rKreq_pathnested_constraint inner_linerrrrpUs"      z)RequirementsFileParser._parse_and_recursec cst||j|jd\}}t|}xr|D]j\}}y|j|\}} Wn8tk rv} zdj|| j} t| WYdd} ~ XnXt |||j|| |Vq$WdS)N)r#zInvalid requirement: {} {}) get_file_contentrmrorErnOptionParsingErrorrFmsgrr,) r'r-r%_rCrD line_numberrKargs_strr/er}rrrrqvs z"RequirementsFileParser._parse_fileN)r)r*r+r(rrprqrrrrr6Bs !r6csfdd}|S)Ncs^t}|j}d|_r j|_t|\}}tjdkr@|jd}|jt j ||\}}||fS)Nutf8)rrr) build_parserget_default_valuesrWformat_controlbreak_args_optionssys version_infoencode parse_argsshlexsplit)rKr9defaultsr options_strr/r~)r3rr parse_lines   z#get_line_parser..parse_liner)r3rr)r3rr5s r5cCsh|jd}g}|dd}x8|D]0}|jds8|jdr.parser_exit)optparse OptionParserSUPPORTED_OPTIONSSUPPORTED_OPTIONS_REQ add_optionexit)r9option_factoriesoption_factoryoptionrrrrrs  rccsd}g}x|D]\}}|jd s,tj|rztj|r>d|}|rn|j||dk sXt|dj|fVg}q||fVq|s|}|j|jdqW|r|dk st|dj|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\r)endswith COMMENT_REmatchr`rGr^strip)rDprimary_line_numbernew_linerrKrrrr@s$     r@ccs8x2|D]*\}}tjd|}|j}|r||fVqWdS)z1 Strips comments and filter empty lines. rN)rsubr)rDrrKrrrrAs  rAccsTxN|D]F\}}x2tj|D]$\}}tj|}|s2q|j||}qW||fVqWdS)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_REfindallrZgetenvreplace)rDrrKenv_varvar_namerhrrrrBs rBc Cs$t|}|d kr.|j|}t||j|jfS|dkr|rT|jdrTtdj|||jddd}|j dd}t j |}|r|j dd|jd dd}t j|}|jdrd|jd}|}y&t|d }t|j}Wd QRXWn2tk r} ztd j| WYd d } ~ XnX||fS)aZGets 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. :param comes_from: Origin description of requirements. httphttpsfilez6Requirements file {} references URL {}, which is local:r<r/|rbNz$Could not open requirements file: {})rr)r getrurltextrrrFrr_url_slash_drive_rergrouprvunquotelstripopenr readIOError) rr4r#schemerespr[rrPrCexcrrrr{#s4         r{z /*([a-z])\|)NNNF)N)NNN)NNN)N)Z__doc__ __future__rrrZrerrZpip._vendor.six.moves.urllibrrvZpip._internal.clirpip._internal.exceptionsrr!pip._internal.models.search_scoperpip._internal.network.utilsrpip._internal.utils.encodingr pip._internal.utils.typingr pip._internal.utils.urlsr r typingr rrrrrrrr"pip._internal.index.package_finderrpip._internal.network.sessionrintZ ReqFileLinesrZ LineParser__all__compileIrtrrrWextra_index_urlrXrsrreditablerR no_binary only_binaryrdrUrb trusted_hostuse_new_featurerinstall_optionsglobal_optionshashrrIobjectr r,rrErNrlr7r6r5r Exceptionr|rr@rArBr{rrrrrs         ,    !  . 7 )N   -