U .e48@sdZddlZddlZddlZddlmZddlmZmZddl m Z ddl m Z m Z ddlmZddlmZmZdd lmZdd lmZdd lmZdd lmZdd lmZmZddlmZddl m!Z!ddl"m#Z#m$Z$ddl%m&Z&erddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-ddl.m/Z/dddgZ0e1e2Z3e j45Z6ddZ7ddZ8ddZ9ddZ:ddZ;Gd d!d!e<Z=d"d#Z>d/d%dZ?d&d'Z@d(d)ZAd*d+ZBd0d,dZCd1d-d.ZDdS)2a~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)make_pyproject_path)InstallRequirement)ARCHIVE_EXTENSIONS)is_installable_dirsplitext)MYPY_CHECK_RUNNING) path_to_url)is_urlvcs)Wheel)AnyDictOptionalSetTupleUnion) WheelCacheinstall_req_from_editableinstall_req_from_lineparse_editablecCs t|d}|tkrdSdS)z9Return True if `name` is a considered as an archive file.TF)rlowerr)nameZextr#B/usr/lib/python3.8/site-packages/pip/_internal/req/constructors.pyis_archive_file4sr%cCs6td|}d}|r*|d}|d}n|}||fS)Nz^(.+)(\[[^\]]+\])$r )rematchgroup)pathmextrasZpath_no_extrasr#r#r$ _strip_extras=s   r-cCs|s tStd|jS)N placeholder)setrr!r,)r,r#r#r$convert_extrasJsr0c Cs`|}t|\}}tj|rptjtj|dshdtj|}t|}tj |r`|d7}t |t |}| drt|j}|r||td| jfS||dfStD]&}| d|rd||f}qqd |krt d ||d d d  }t|s:d |dddtjDd} t | t|j}|sVt d|||dfS)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:r.Nz%s:z%s+%s+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 rzFor --editable=%s only z, cSsg|]}|jdqS)z+URLr").0Zbackendr#r#r$ sz"parse_editable..z is currently supportedzZCould not detect requirement name for '%s', please specify one with #egg=your_package_name)r-osr*isdirexistsjoinformatabspathr isfilerrr! startswithr egg_fragmentrr,rsplitZ get_backendZbackends) editable_requrlZ url_no_extrasr,msgZpyproject_pathZ package_nameZversion_controlZvc_typeZ error_messager#r#r$rQsb          c Csd}tj|rd}zFt|d2}tt||dd|ddd7}W5QRXWqtk rtj d |d d YqXn |d |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.rz The argument you provided z(%s) appears to be az" requirements file. If that is thez# case, use the '-r' flag to installz" the packages specified within it.z2Cannot parse '%s' as requirements fileT)exc_infoz File '%s' does not exist.) r5r*r7opennextrreadrloggerdebug)reqrAfpr#r#r$deduce_helpful_msgs.   rLc@seZdZddZdS)RequirementPartscCs||_||_||_||_dSN) requirementlinkmarkersr,)selfrOrPrQr,r#r#r$__init__szRequirementParts.__init__N)__name__ __module__ __qualname__rSr#r#r#r$rMsrMcCs`t|\}}}|dk rFz t|}WqJtk rBtd|YqJXnd}t|}t||d|S)NInvalid requirement: '%s')rrrrr rM)r?r"r@Zextras_overriderJrPr#r#r$parse_req_from_editables rXFc CsLt|}|jjdkr|jjnd}t|j||d|j||||r>|ni||jd S)NfileT) source_dirZeditablerP constraint use_pep517isolatedoptions wheel_cacher,)rXrPschemeZ file_pathr rOr,) r? comes_fromr\r]r^r_r[partsrZr#r#r$rs  cCs>tjj|krdStjjdk r,tjj|kr,dS|dr: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)r5r*sepaltsepr<r2r#r#r$_looks_like_paths  rfcCst|r0tj|r0t|r$t|Std|t|slenrHZwarning)r*r"Z urlreq_partsr#r#r$_get_url_from_path s(   ricst|rd}nd}||krF||d\}}|}|s.with_sourcezIt looks like a path.=c3s|]}|kVqdSrNr#)r3op) req_as_stringr#r$ jsz&parse_req_from_line..z,= is not a valid operator. Did you mean == ?rBzInvalid requirement: {!r}z Hint: {}) rr>striprr5r*normpathr:r r-rir`r'searchr@rZis_wheelrfilenamer"versionr=r0rrrdrLany operatorsr9rrM)r"rlZ marker_sepZmarkers_as_stringrQr*rPZextras_as_stringpr@Zwheelr,rmrJZadd_msgrAr#)rlrpr$parse_req_from_line+sj         rzc Cs6t||}t|j||j|j|||r&|ni|||jd 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. )rPrQr\r]r^r_r[r,)rzr rOrPrQr,) r"rar\r]r^r_r[rlrbr#r#r$rzs  cCszz t|}Wn tk r,td|YnXtjtjg}|jrh|rh|jrh|jj|krhtd|j |ft |||||dS)NrWzkPackages installed from PyPI cannot depend on packages which are not also hosted on PyPI. %s depends on %s )r]r_r\) rrrr Zfile_storage_domainr r@rPZnetlocr"r )Z req_stringrar]r_r\rJZdomains_not_allowedr#r#r$install_req_from_req_strings,  r{)NNFNNF)NNFNNFN)NFNN)E__doc__Zloggingr5r'Zpip._vendor.packaging.markersrZ"pip._vendor.packaging.requirementsrrZ pip._vendor.packaging.specifiersrZpip._vendor.pkg_resourcesrrZpip._internal.exceptionsrZpip._internal.models.indexr r Zpip._internal.models.linkr Zpip._internal.pyprojectr Zpip._internal.req.req_installr Zpip._internal.utils.filetypesrZpip._internal.utils.miscrrZpip._internal.utils.typingrZpip._internal.utils.urlsrZpip._internal.vcsrrZpip._internal.wheelrtypingrrrrrrZpip._internal.cacher__all__Z getLoggerrTrHZ _operatorskeysrxr%r-r0rrLobjectrMrXrrfrirzrr{r#r#r#r$sr                J "Q