3 Bu_@@sdZddlZddlZddlZddlmZddlmZmZddl m Z ddl m Z m Z ddlmZddlmZmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlm Z m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'm(Z(e#r"ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1dddgZ2ej3e4Z5e j6j7Z8ddZ9ddZ:ddZ;ddZZ?d#d$Z@d2d&dZAd'd(ZBd)d*ZCd+d,ZDd3d-dZEd4d.d/ZFd5d0d1ZGdS)6a~Backing implementation for InstallRequirement's various constructors The idea here is that these formed a major chunk of InstallRequirement's size so, moving them and support code dedicated to them outside of that class helps creates for better understandability for the rest of the code. These are meant to be used elsewhere within pip to create instances of InstallRequirement. N)Marker)InvalidRequirement Requirement) Specifier)RequirementParseErrorparse_requirements)InstallationError)PyPITestPyPI)Link)Wheel)make_pyproject_path)InstallRequirement) deprecated)ARCHIVE_EXTENSIONS)is_installable_dirsplitext)MYPY_CHECK_RUNNING) path_to_url)is_urlvcs)AnyDictOptionalSetTupleUnion)ParsedRequirementinstall_req_from_editableinstall_req_from_lineparse_editablecCs t|dj}|tkrdSdS)z9Return True if `name` is a considered as an archive file.TF)rlowerr)nameextr%/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-1.el7.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_internal/req/constructors.pyis_archive_file1sr'cCs6tjd|}d}|r*|jd}|jd}n|}||fS)Nz^(.+)(\[[^\]]+\])$r!)rematchgroup)pathmextraspath_no_extrasr%r%r& _strip_extras:s   r0cCs|s tStd|jjS)N placeholder)setrr"r.)r.r%r%r&convert_extrasGsr3c Csj|}t|\}}tjj|rptjjtjj|dshdjtjj|}t|}tjj |r`|d7}t |t |}|j j drt|j}|r||td|j jfS||tfSx.tD]&}|j j dj|rdj||}PqWd|krt d j||jdd d j }tj|s@d jd dtjD} dj|| } t | t|j}|s^t dj|||tfS)aParses an editable requirement into: - a requirement name - an URL - extras - editable options Accepted requirements: svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir .[some_extra] zsetup.pyzMFile "setup.py" not found. Directory cannot be installed in editable mode: {}zb (A "pyproject.toml" file was found, but editable mode currently requires a setup.py based build.)zfile:r1z{}:z{}+{}+z{} is not a valid editable requirement. It should either be a path to a local project or a VCS URL (beginning with svn+, git+, hg+, or bzr+).r!rz, cSsg|]}|jdqS)z+URL)r#).0bendsr%r%r& sz"parse_editable..z2For --editable={}, only {} are currently supportedzZCould not detect requirement name for '{}', please specify one with #egg=your_package_name)r0osr,isdirexistsjoinformatabspathr isfilerrr" startswithr egg_fragmentrr.r2rsplit get_backendbackends) editable_requrl url_no_extrasr.msgpyproject_path package_nameversion_controlvc_typerC error_messager%r%r&r NsN          cCsd}tjj|rtd}y8t|d$}tt|j|dj|7}WdQRXWqtk rpt j d|ddYqXn|d j|7}|S) zReturns helpful msg in case requirements file does not exist, or cannot be parsed. :params req: Requirements file path z It does exist.rzThe argument you provided ({}) appears to be a requirements file. If that is the case, use the '-r' flag to install the packages specified within it.Nz&Cannot parse '%s' as requirements fileT)exc_infoz File '{}' does not exist.) r8r,r:opennextrreadr<rloggerdebug)reqrGfpr%r%r&deduce_helpful_msgs  rWc@seZdZddZdS)RequirementPartscCs||_||_||_||_dS)N) requirementlinkmarkersr.)selfrYrZr[r.r%r%r&__init__szRequirementParts.__init__N)__name__ __module__ __qualname__r]r%r%r%r&rXsrXc Csbt|\}}}|dk rHy t|}WqLtk rDtdj|YqLXnd}t|}t||d|S)NzInvalid requirement: '{}')r rrrr<r rX)rDr#rEextras_overriderUrZr%r%r&parse_req_from_editables rbFcCs^t|}t|j||d|j||||r.|jdgng|r@|jdgng|rR|jdini|jd S)NTinstall_optionsglobal_optionshashes) comes_from user_suppliededitablerZ constraint use_pep517isolatedrcrd hash_optionsr.)rbrrYrZgetr.)rDrfrjrkoptionsrirgpartsr%r%r&rs cCs>tjj|krdStjjdk r,tjj|kr,dS|jdr:dSdS)akChecks whether the string "looks like" a path on the filesystem. This does not check whether the target actually exists, only judge from the appearance. Returns true if any of the following conditions is true: * a path separator is found (either os.path.sep or os.path.altsep); * a dot is found (which represents the current directory). TN.F)r8r,sepaltsepr?)r#r%r%r&_looks_like_paths  rscCst|r6tjj|r6t|r$t|Stdjftt |sBdStjj |rVt|S|j dd}t |dkrt|d rdSt jd|t|S)ad First, it checks whether a provided path is an installable directory (e.g. it has a setup.py). If it is, returns the path. If false, check if the path is an archive file (such as a .whl). The function checks if the path is a file. If false, if the path has an @, it will treat it as a PEP 440 URL requirement and return the path. zUDirectory {name!r} is not installable. Neither 'setup.py' nor 'pyproject.toml' found.N@r!r(rzARequirement %r looks like a filename, but the file does not exist)rsr8r,r9rrrr<localsr'r>rAlenrSwarning)r,r# urlreq_partsr%r%r&_get_url_from_path s"    rycs$t|rd}nd}||krF|j|d\}}|j}|s.with_sourcezIt looks like a path.=c3s|]}|kVqdS)Nr%)r5op) req_as_stringr%r& msz&parse_req_from_line..z,= is not a valid operator. Did you mean == ?rMzInvalid requirement: {!r}z Hint: {}]zExtras after version '{}'.z+moving the extras before version specifiersz21.0) replacementgone_in)#rrAstriprr8r,normpathr=r r0ryschemer)searchrEris_wheelr filenamer<rur@r3rrrqrWany operatorsr specifierstrendswithrrX)r#r} marker_sepmarkers_as_stringr[r,rZextras_as_stringprEwheelr.r~rUadd_msgrGspecspec_strreplacer%)r}rr&parse_req_from_line-sp             rc Csbt||}t|j||j|j|||r.|jdgng|r@|jdgng|rR|jdini||j|d S)aCreates an InstallRequirement from a name, which might be a requirement, directory containing 'setup.py', filename, or URL. :param line_source: An optional string describing where the line is from, for logging purposes in case of an error. rcrdre) rZr[rjrkrcrdrlrir.rg)rrrYrZr[rmr.) r#rfrjrkrnrir}rgror%r%r&rs cCs|y t|}Wn"tk r.tdj|YnXtjtjg}|jrj|rj|jrj|jj |krjtdj|j |t |||||dS)NzInvalid requirement: '{}'zkPackages installed from PyPI cannot depend on packages which are not also hosted on PyPI. {} depends on {} )rkrjrg) rrrr<r file_storage_domainr rErZnetlocr#r) req_stringrfrkrjrgrUdomains_not_allowedr%r%r&install_req_from_req_strings"   rc CsH|jr"t|j|j||j||d}n"t|j|j|||j|j|j|d}|S)N)rfrjrirkrg)rfrjrkrnrir}rg) is_editablerrYrfrirrnr}) parsed_reqrkrjrgrUr%r%r&#install_req_from_parsed_requirements$ r)NNFNFF)NNFNFNF)NFNF)FNF)H__doc__loggingr8r)Zpip._vendor.packaging.markersrZ"pip._vendor.packaging.requirementsrrZ pip._vendor.packaging.specifiersrZpip._vendor.pkg_resourcesrrpip._internal.exceptionsrpip._internal.models.indexr r pip._internal.models.linkr pip._internal.models.wheelr pip._internal.pyprojectr Zpip._internal.req.req_installrpip._internal.utils.deprecationrpip._internal.utils.filetypesrpip._internal.utils.miscrrpip._internal.utils.typingrpip._internal.utils.urlsrpip._internal.vcsrrtypingrrrrrrZpip._internal.req.req_filer__all__ getLoggerr^rS _operatorskeysrr'r0r3r rWobjectrXrbrrsryrrrrr%r%r%r& sp                 K "]