zk//:dZddlmZddlZddlZddlZddlZddlZddl m Z m Z m Z ddl mZmZddlmZmZmZddlmZddlmZmZdd lmZmZmZmZmZmZm Z m!Z!dd l"m#Z#m$Z$m%Z%m&Z&d gZ'ej(e)Z*e+ee,ee,fZ-d&dZ. d'd(dZ/d)dZ0Gdde1Z2Gdde1Z3edGd d!Z4Gd"d#Z5e5Z6Gd$d%Z7dS)*z)Handles all VCS (version control) support) annotationsN)IterableIteratorMapping) dataclassfield)AnyLiteralOptional)SpinnerInterface) BadCommandInstallationError) HiddenTextask_path_exists backup_dir display_pathhide_url hide_valueis_installable_dirrmtree) CommandArgscall_subprocessformat_command_args make_commandvcsnamestrreturnboolcxtj|j}|sdS|gdtjzvS)z3 Return true if the name looks like a URL. F)httphttpsfileftp)urllibparseurlsplitschemer all_schemes)rr(s /builddir/build/BUILD/imunify360-venv-2.6.2/opt/imunify360/venv/lib/python3.11/site-packages/pip/_internal/vcs/versioncontrol.pyis_urlr+-sB\ " "4 ( ( /F u 555G GGrepo_urlrev project_namesubdir str | Nonectj|d}|dd}|d|d|}|r|d|z }|S)z Return the URL for a VCS requirement. Args: repo_url: the remote VCS url, with any needed VCS prefix (e.g. "git+"). project_name: the (unescaped) project name. /-_@z#egg=z&subdirectory=)r%r&quotereplace)r-r.r/r0 quoted_revegg_project_namereqs r*make_vcs_requirement_urlr<7sm##C--J#++C55  ; ; ; ;)9 ; ;C ) (((( Jr,location repo_rootcN|}t|sS|}tj|}||krtd|dSt|Stj||rdStj||S)z Find the the Python project's root by searching up the filesystem from `location`. Return the path to project root relative to `repo_root`. Return None if the project root is `repo_root`, or cannot be found. zOCould not find a Python project for directory %s (tried all parent directories)N)rospathdirnameloggerwarningsamefilerelpath)r=r> orig_location last_locations r*(find_path_to_project_root_from_repo_rootrIJsM **  7??8,, } $ $ NN&    4!**  w 8,,t 7??8Y / //r,ceZdZdS)RemoteNotFoundErrorN)__name__ __module__ __qualname__r,r*rKrKgsDr,rKc eZdZdfd ZxZS)RemoteNotValidErrorurlrcXt|||_dSN)super__init__rR)selfrR __class__s r*rVzRemoteNotValidError.__init__ls& r,)rRr)rLrMrNrV __classcell__rXs@r*rQrQks=r,rQT)frozenceZdZUdZded<dZded<eeZded <dZ ded <dd Z e ddZ ddZ ddZddZdS) RevOptionsz Encapsulates a VCS-specific revision to install, along with any VCS install options. Args: vc_class: a VersionControl subclass. rev: the name of the revision to install. extra_args: a list of extra options. type[VersionControl]vc_classNr1r.)default_factoryr extra_args branch_namerrc2d|jjd|jdS)Nz )r_rr.rWs r*__repr__zRevOptions.__repr__s"Edm0EEEEEEr,c6|j |jjS|jSrT)r.r_default_arg_revres r*arg_revzRevOptions.arg_revs 8 =0 0xr,cjg}|j}|||j|z }||jz }|S)z< Return the VCS-specific command arguments. )rir_get_base_rev_argsra)rWargsr.s r*to_argszRevOptions.to_argss@l ? DM33C88 8D  r,c*|jsdSd|jdS)Nz (to revision )r.res r* to_displayzRevOptions.to_displays$x 2+++++r,cD|j||jS)z Make a copy of the current instance, but with a new rev. Args: rev: the name of the revision for the new object. ra)r_make_rev_optionsra)rWr.s r*make_newzRevOptions.make_news!}--cdo-NNNr,)rr)rr1)rr)r.rrr])rLrMrN__doc____annotations__r.rlistrarbrfpropertyrirmrrrvrOr,r*r]r]qs#"""C#eD999J9999"K""""FFFFX    ,,,, OOOOOOr,r]ceZdZUiZded<gdZdfd ZddZedd Z edd Z edd Z ddZ ddZ d dZd!dZd"dZxZS)# VcsSupportzdict[str, VersionControl] _registry)sshgithgbzrsftpsvnrNonectjj|jt dSrT)r%r& uses_netlocextendschemesrUrV)rWrXs r*rVzVcsSupport.__init__s<   '' 555 r, Iterator[str]c4|jSrT)r}__iter__res r*rzVcsSupport.__iter__s~&&(((r,list[VersionControl]cNt|jSrT)ryr}valuesres r*backendszVcsSupport.backendssDN))++,,,r, list[str]c$d|jDS)Ncg|] }|j SrO)rB).0backends r* z'VcsSupport.dirnames..s===G===r,)rres r*dirnameszVcsSupport.dirnamess==t}====r,cRg}|jD]}||j|SrT)rrr)rWrrs r*r)zVcsSupport.all_schemess4} , ,G NN7? + + + +r,clsr^ct|ds"td|jdS|j|jvr9||j|j<td|jdSdS)NrzCannot register VCS %szRegistered VCS backend: %s)hasattrrCrDrLrr}debug)rWrs r*registerzVcsSupport.registersxsF##  NN3S\ B B B F 84> ) )'*suuDN38 $ LL5sx @ @ @ @ @ * )r,rrc,||jvr |j|=dSdSrT)r}rWrs r* unregisterzVcsSupport.unregisters' 4> ! !t$$$ " !r,r=VersionControl | Noneci}|jD]@}||}|std||j|||<A|sdSt |t}||S)zv Return a VersionControl object if a repository of that type is found at the given directory. zDetermine that %s uses VCS: %sN)key)r}rget_repository_rootrCrrmaxlen)rWr= vcs_backends vcs_backend repo_pathinner_most_repo_paths r*get_backend_for_dirzVcsSupport.get_backend_for_dirs  >0022 2 2K#77AAI  LL98[EU V V V&1L # # 4 #0022 # #K,,,""""-tr,c^|}|j|S)r)lowerr}getrs r* get_backendzVcsSupport.get_backends'zz||~!!$'''r,)rr)rr)rr)rr)rr^rr)rrrr)r=rrr)r(rrr)rrrr)rLrMrNr}rxrrVrrzrrr)rrrrrrYrZs@r*r|r|s7+-I----888G ))))---X->>>X>X AAAA%%%%2222.((((((((r,r|cNeZdZUdZdZdZdZded<dZded<dZ ded<e dVd Z e dWdZ e dXdZ e dYdZedZdZd[dZe d\d]dZe d^dZe d_d#Ze d`d%Zedad*Zdbd-Zedcd.Ze ddd1Zded6Z dfded8Z dfded9Ze dgd;Zdhd<Zdid=Ze djd>Z e djd?Z!e dkdldRZ"e dmdTZ#e dWdUZ$dS)nVersionControlrorOztuple[str, ...]r unset_environNr1rh remote_urlrrrcb||jd S)z Return whether the vcs prefix (e.g. "git+") should be added to a repository's remote url when used in a requirement. :)r startswithr)rrs r*should_add_vcs_url_prefixz(VersionControl.should_add_vcs_url_prefixs/ ##%%00CH@@@@r,r=cdS)z Return the path to Python project root, relative to the repo root. Return None if the project root is in the repo root. NrOrr=s r*get_subdirectoryzVersionControl.get_subdirectory s tr,repo_dirc,||S)zR Return the revision string that should be used in a requirement. ) get_revision)rrs r*get_requirement_revisionz'VersionControl.get_requirement_revisions )))r,r/c||}||r |jd|}||}||}t ||||}|S)aC Return the requirement string to use to redownload the files currently at the given repository directory. Args: project_name: the (unescaped) project name. The return value has a form similar to the following: {repository_url}@{revision}#egg={project_name} +)r0)get_remote_urlrrrrr<)rrr/r-revisionr0r;s r*get_src_requirementz"VersionControl.get_src_requirements%%h//  ( ( 2 2 0(//X//H//99%%h//&xs ur,raCommandArgs | Noner]c*t|||pgS)z Return a RevOptions object. Args: rev: the name of a revision to install. extra_args: a list of extra options. rt)r])rr.ras r*ruzVersionControl.make_rev_optionsKs#sz/?R@@@@r,repoctj|\}}|tjjpt |S)zs posix absolute paths start with os.path.sep, win32 ones start with drive (like c:\folder) )r@rA splitdriversepr)rrdrivetails r*_is_local_repositoryz#VersionControl._is_local_repositoryXs> g((.. trw{++:tE{{:r,netlocr()tuple[str, tuple[str | None, str | None]]c |dfS)aZ Parse the repository URL's netloc, and return the new netloc to use along with auth information. Args: netloc: the original repository URL netloc. scheme: the repository URL's scheme without the vcs prefix. This is mainly for the Subversion class to override, so that auth information can be provided via the --username and --password options instead of through the URL. For other subclasses like Git without such an option, auth information must stay in the URL. Returns: (netloc, (username, password)). NNrO)rrr(s r*get_netloc_and_authz"VersionControl.get_netloc_and_authas&|##r, tuple[str, str | None, AuthInfo]ctj|\}}}}}d|vrtd|d|ddd}|||\}}d}d|vrM|dd\}}|std|dtj|}tj ||||d f}|||fS) z Parse the repository URL to use, and return the URL, revision, and auth info to use. Returns: (url, rev, (username, password)). rzSorry, zk is a malformed VCS url. The format is +://, e.g. svn+http://myrepo/svn/MyApp#egg=MyAppNr6zThe URL zm has an empty revision (after @) which is not supported. Include a revision after @ or remove @ from the URL.ro) r%r&r' ValueErrorsplitrrsplitrunquote urlunsplit) rrRr(rrAqueryfrag user_passr.s r*get_url_rev_and_authz#VersionControl.get_url_rev_and_authvs$-3L,A,A#,F,F)eT f  =#===  c1%%a(33FFCC  $;; C++ID# '0s000 ,&&s++Cl%%vvtUB&GHHC""r,usernamepasswordHiddenText | NonercgS)zM Return the RevOptions "extra arguments" to use in obtain(). rO)rrs r* make_rev_argszVersionControl.make_rev_argss  r,rtuple[HiddenText, RevOptions]c||j\}}}|\}}d}|t|}|||}|||} t || fS)zq Return the URL and RevOptions object to use in obtain(), as a tuple (url, rev_options). Nrt)rsecretrrrur) rWrR secret_urlr.rrsecret_passwordrra rev_optionss r*get_url_rev_optionsz"VersionControl.get_url_rev_optionss &*%>%>sz%J%J" C$-!/&*  &!/22H''(;; ++CJ+GG  ##[00r,cftj|dS)zi Normalize a URL for comparison by unquoting it and removing any trailing slash. r3)r%r&rrstrip)rRs r* normalize_urlzVersionControl.normalize_urls( |##C((//444r,url1url2cZ||||kS)zV Compare two repo URLs for identity, ignoring incidental differences. )r)rrrs r* compare_urlszVersionControl.compare_urlss+   &&#*;*;D*A*AAAr,r verbosityintrct)a Fetch a revision from a repository, in the case that this is the first fetch from the repository. Args: dest: the directory to fetch the repository to. rev_options: a RevOptions object. verbosity: verbosity level. rrWrrRrrs r* fetch_newzVersionControl.fetch_news "!r,rct)z} Switch the repo at ``dest`` to point to ``URL``. Args: rev_options: a RevOptions object. rrs r*switchzVersionControl.switch "!r,ct)z Update an already-existing repo to the given ``rev_options``. Args: rev_options: a RevOptions object. rrs r*updatezVersionControl.updaterr,rct)z Return whether the id of the current commit equals the given name. Args: dest: the repository directory. name: a string name. r)rrrs r*is_commit_id_equalz!VersionControl.is_commit_id_equals "!r,c||\}}tj|s|||||dS|}||r)||}|||j rt d|j t|||||jsItdt||j ||||||ntddStd|j|j t||d}n)td||j|j d }td |j|t+d |d |d }|dkrt-jd|dkrRtdt|t1||||||dS|dkrht3|} tdt|| t5j|| |||||dS|dkrKtd|j t||||||||dSdS)a/ Install or update in editable mode the package represented by this VersionControl object. :param dest: the repository directory in which to install or update. :param url: the repository URL starting with a vcs prefix. :param verbosity: verbosity level. )rNz)%s in %s exists, and has correct URL (%s)zUpdating %s %s%sz$Skipping because already up-to-date.z%s %s in %s exists with URL %s)z%(s)witch, (i)gnore, (w)ipe, (b)ackup )siwbz0Directory %s already exists, and is not a %s %s.)z(i)gnore, (w)ipe, (b)ackup )rr r z+The plan is to install the %s repository %sz What to do? rrar z Deleting %sr zBacking up %s to %srzSwitching %s %s to %s%s)rr@rAexistsrrris_repository_directoryrrrrCr repo_nametitlerrr.inforrDrrsysexitrrshutilmover) rWrrRrr rev_display existing_urlpromptresponsedest_dirs r*obtainzVersionControl.obtains8 33C88[w~~d##  NN4kYN G G G F!,,..  ' ' - -% F..t44L  sz::  ?N((** &&  ..t[_EE HKK*$T**#  KKc;)KLLLLKK FGGG NN0 T""    UFF NNB     FF 9 I    ##>6!9#>#>q JJ s?? HRLLL s?? NN=,t*<*< = = = 4LLL NN4kYN G G G F s??!$''H NN0,t2D2Dh O O O Kh ' ' ' NN4kYN G G G F s?? KK)T""     KKc;)K D D D D D ?r,ctj|rt|||||dS)z Clean up current location and download the url repository (and vcs infos) into location :param url: the repository URL starting with a vcs prefix. :param verbosity: verbosity level. )rRrN)r@rAr rr)rWr=rRrs r*unpackzVersionControl.unpackJsF 7>>( # #  8    H# ;;;;;r,ct)z Return the url used at location Raises RemoteNotFoundError if the repository does not have a remote url configured. rrs r*rzVersionControl.get_remote_urlVrr,ct)zR Return the current commit id of the files at the given location. rrs r*rzVersionControl.get_revision`s "!r,TraiseFcmdlist[str] | CommandArgs show_stdoutcwd on_returncode"Literal['raise', 'warn', 'ignore']extra_ok_returncodesIterable[int] | None command_desc extra_environMapping[str, Any] | NonespinnerSpinnerInterface | Nonelog_failed_cmd stdout_onlyc ht|jg|R}|t|} t||||||||j|| |  S#t $rt d|jdt$r!t d|jd|jdt$rt d|jdwxYw) z Run a VCS subcommand This is simply a wrapper around call_subprocess that adds the VCS command name, and checks that the VCS is available N)r%r'r)r*rr,r.r/zCannot find command z - invalid PATHz - do you have z installed and in your PATH?zNo permission to execute z - install it locally, globally (ask admin), or check your PATH. See possible solutions at https://pip.pypa.io/en/latest/reference/pip_freeze/#fixing-permission-denied.) rrrrrNotADirectoryErrorr FileNotFoundErrorPermissionError) rr!r#r$r%r'r)r*r,r.r/s r* run_commandzVersionControl.run_commandgs7&38*c***  .s33L" "+%9)+!/-'    " Q Q QOCHOOOPP P    >>r,c4||r|SdS)ay Return the "root" (top-level) directory controlled by the vcs, or `None` if the directory is not in any. It is meant to be overridden to implement smarter detection mechanisms for specific vcs. This can do more than is_repository_directory() alone. For example, the Git override checks that Git is actually available. N)rrs r*rz"VersionControl.get_repository_roots$  & &x 0 0 Otr,)rrrr)r=rrr1)rrrr)rrr/rrr)r.rrr)rRrrrrrr)r.r1rarrr])rrrr)rrr(rrr)rRrrr)rr1rrrr)rRrrr)rRrrr)rrrrrr) rrrRrrr]rrrr)r)rrrr1rr)rrrRrrrrr)r=rrRrrrrr)r=rrr) TNr NNNNTF)r!r"r#rr$r1r%r&r'r(r)r1r*r+r,r-r.rr/rrr)rArrr)%rLrMrNrrBrrrxrrh classmethodrrrr staticmethodrkrrurrrrrrrrrrrrrrrr4rrrOr,r*rrsw DGI!G!!!!%'M''''"&O&&&&AAA[A[***[* [."""\"    FJ A A A A[ A;;;[;$$$[$(###[#<\ 1 1 1 1555\5BBB[B " " " "& " " " " "( " " " " """"["WEWEWEWEr < < < <"""[""""[" !rrr1)8rw __future__rloggingr@rr urllib.parser%collections.abcrrr dataclassesrrtypingr r r pip._internal.cli.spinnersr pip._internal.exceptionsr rpip._internal.utils.miscrrrrrrrrpip._internal.utils.subprocessrrrr__all__ getLoggerrLrCtuplerAuthInfor+r<rI ExceptionrKrQr]r|rrrOr,r*rIs//"""""" 7777777777(((((((( 877777BBBBBBBB                     '  8 $ $ # - .HHHHFJ&0000:     )   )  $3O3O3O3O3O3O3O3OlM(M(M(M(M(M(M(M(`jll||||||||||r,