idY &dZddlZddlZddlZddlZddlZddlmZm Z m Z m Z m Z m Z mZmZmZmZmZddlmZddlmZmZddlmZmZmZmZmZmZmZm Z ddl!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'erdd lm(Z(d gZ)ej*e+Z,eee-ee-fZ.d e-d e/fd Z0 d de-de-de-dee-d e-f dZ1de-de-d ee-fdZ2Gdde3Z4Gdde3Z5GddZ6GddZ7e7Z8GddZ9dS)!z)Handles all VCS (version control) supportN) TYPE_CHECKINGAnyDictIterableIteratorListMappingOptionalTupleTypeUnion)SpinnerInterface) BadCommandInstallationError) HiddenTextask_path_exists backup_dir display_pathhide_url hide_valueis_installable_dirrmtree) CommandArgscall_subprocessformat_command_args make_command)get_url_scheme)LiteralvcsnamereturncNt|}|dS|gdtjzvS)z3 Return true if the name looks like a URL. NF)httphttpsfileftp)rr all_schemes)r schemes U/opt/cloudlinux/venv/lib/python3.11/site-packages/pip/_internal/vcs/versioncontrol.pyis_urlr*9s4D ! !F ~u 555G GGrepo_urlrev project_namesubdircZ|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=)replace)r,r-r.r/egg_project_namereqs r)make_vcs_requirement_urlr7CsV$++C55  4 4 4 4"2 4 4C ) (((( 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)r8r9 orig_location last_locations r)(find_path_to_project_root_from_repo_rootrDUsM **  7??8,, } $ $ NN&    4!**  w 8,,t 7??8Y / //r+ceZdZdS)RemoteNotFoundErrorN)__name__ __module__ __qualname__r+r)rFrFrsDr+rFc$eZdZdeffd ZxZS)RemoteNotValidErrorurlcXt|||_dSN)super__init__rM)selfrM __class__s r)rQzRemoteNotValidError.__init__ws& r+)rGrHrIstrrQ __classcell__rSs@r)rLrLvsDCr+rLc eZdZdZ ddeddeedeeddfdZdefd Z e deefd Z defd Z defd Z deddfd ZdS) RevOptionsz Encapsulates a VCS-specific revision to install, along with any VCS install options. Instances of this class should be treated as if immutable. Nvc_classVersionControlr- extra_argsr!cF|g}||_||_||_d|_dS)z Args: vc_class: a VersionControl subclass. rev: the name of the revision to install. extra_args: a list of extra options. N)r[r-rY branch_name)rRrYr-r[s r)rQzRevOptions.__init__s2  J$  *.r+c2d|jjd|jdS)Nz )rYr r-rRs r)__repr__zRevOptions.__repr__s"Edm0EEEEEEr+c6|j |jjS|jSrO)r-rYdefault_arg_revr`s r)arg_revzRevOptions.arg_revs 8 =0 0xr+cjg}|j}|||j|z }||jz }|S)z< Return the VCS-specific command arguments. )rdrYget_base_rev_argsr[)rRargsr-s r)to_argszRevOptions.to_argss@l ? DM33C88 8D  r+c*|jsdSd|jdS)Nz (to revision )r-r`s 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. r[)rYmake_rev_optionsr[)rRr-s r)make_newzRevOptions.make_news!}--cdo-NNNr+NN)rGrHrI__doc__r r rTrrQrapropertyrdrhrmrqrJr+r)rXrX|s",0 //'(/c]/[) /  ////(F#FFFF#X     ,C,,,, OCOLOOOOOOr+rXcXeZdZUiZeedfed<gdZdfd Zde efdZ e de dfdZ e de efd Ze de efd Zd edddfd Zd eddfdZdededfdZdededfdZd ededfdZxZS) VcsSupportrZ _registry)sshgithgbzrsftpsvnr!Nctjj|jt dSrO)urllibparse uses_netlocextendschemesrPrQ)rRrSs r)rQzVcsSupport.__init__s<   '' 555 r+c4|jSrO)rw__iter__r`s r)rzVcsSupport.__iter__s~&&(((r+cNt|jSrO)listrwvaluesr`s r)backendszVcsSupport.backendssDN))++,,,r+c$d|jDS)Ncg|] }|j SrJ)r=).0backends r) z'VcsSupport.dirnames..s===G===r+)rr`s r)dirnameszVcsSupport.dirnamess==t}====r+cRg}|jD]}||j|SrO)rrr)rRrrs r)r'zVcsSupport.all_schemess4} , ,G NN7? + + + +r+clsct|ds"td|jdS|j|jvr9||j|j<td|jdSdS)Nr zCannot register VCS %szRegistered VCS backend: %s)hasattrr>r?rGr rwdebug)rRrs r)registerzVcsSupport.registersxsF##  NN3S\ B B B F 84> ) )'*suuDN38 $ LL5sx @ @ @ @ @ * )r+r c,||jvr |j|=dSdSrO)rwrRr s r) unregisterzVcsSupport.unregisters' 4> ! !t$$$ " !r+r8ci}|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)rwrget_repository_rootr>rr maxlen)rRr8 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)lowerrwgetrs r) get_backendzVcsSupport.get_backends'zz||~!!$'''r+)r!N)rGrHrIrwrrT__annotations__rrQrrrtrrrr'r rrr rrrrUrVs@r)rvrvs-/ItC))*///888G )(3-))))-$/0---X->$s)>>>X>T#YX AD!12AtAAAA%s%t%%%%2C2H=M4N2222.SX>N5O((1A(B((((((((r+rvceZdZUdZdZdZdZeedfe d<dZ eedfe d<dZ e ee d<e ded efd Ze d ed e efd Ze d ed efdZe d eded efdZeded eefdZdeded efdZe dCde ede ed efdZe ded efdZe deded eeee ee efffdZe ded eee eeffdZede ede ed efd Zded eeeffd!Z eded efd"Z!e d#ed$ed efd%Z"deded&ed'e#d df d(Z$deded&ed dfd)Z%deded&ed dfd*Z&e ded+e ed efd,Z'deded'e#d dfd-Z(d eded'e#d dfd.Z)e d ed efd/Z*e d ed efd0Z+e dDd4e,eeefd5ed6e ed7d8d9e e-e#d:e ed;e e.ee/fded efd?Z1e d@ed efdAZ2e d ed e efdBZ3dS)ErZrjrJ.r unset_environNrc remote_urlr!cb||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+r8cdS)z Return the path to Python project root, relative to the repo root. Return None if the project root is in the repo root. NrJrr8s 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_revision,s )))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} +)r/)get_remote_urlrr rrr7)rrr.r,revisionr/r6s r)get_src_requirementz"VersionControl.get_src_requirement3s%%h//  ( ( 2 2 0(//X//H//99%%h//&x g((.. trw{++:tE{{:r+netlocr(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)). rrrJ)rrr(s r)get_netloc_and_authz"VersionControl.get_netloc_and_authxs&|##r+ctj|\}}}}}d|vr"td||ddd}|||\}}d}d|vr=|dd\}}|s"td|tj ||||df}|||fS)z Parse the repository URL to use, and return the URL, revision, and auth info to use. Returns: (url, rev, (username, password)). rzvSorry, {!r} is a malformed VCS url. The format is +://, e.g. svn+http://myrepo/svn/MyApp#egg=MyAppNr3zyThe URL {!r} has an empty revision (after @) which is not supported. Include a revision after @ or remove @ from the URL.rj) rrurlsplit ValueErrorformatsplitrrsplitr urlunsplit) rrMr(rr<queryfrag user_passr-s r)get_url_rev_and_authz#VersionControl.get_url_rev_and_auths-3L,A,A#,F,F)eT f  ==CVC[[  c1%%a(33FFCC  $;; C++ID# '006s  l%%vvtUB&GHHC""r+usernamepasswordcgS)zM Return the RevOptions "extra arguments" to use in obtain(). rJ)rrs r) make_rev_argszVersionControl.make_rev_argss  r+c||j\}}}|\}}d}|t|}|||}|||} t || fS)zq Return the URL and RevOptions object to use in obtain(), as a tuple (url, rev_options). Nro)rsecretrrrpr) rRrM secret_urlr-rrsecret_passwordrr[ 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. /)rrunquoterstrip)rMs 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 verbosityct)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. r)rRrrMrrs r) fetch_newzVersionControl.fetch_news "!r+ct)z} Switch the repo at ``dest`` to point to ``URL``. Args: rev_options: a RevOptions object. rrRrrMrs 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+r ct)z Return whether the id of the current commit equals the given name. Args: dest: the repository directory. name: a string name. r)rrr s r)is_commit_id_equalz!VersionControl.is_commit_id_equals "!r+c||\}}tj|s|||||dS|}||r'||}|||j rt d|j t|||||jsGtdt||j |||||ntddStd|j|j t||d}n)td||j|j d }td |j|t+d |d |d }|dkrt/jd|dkrRtdt|t3||||||dS|dkrht5|} tdt|| t7j|| |||||dS|dkrItd|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 )rrrz+The plan is to install the %s repository %szWhat to do? {}rrarz Deleting %srzBacking up %s to %srzSwitching %s %s to %s%s)rr;r<existsrrmis_repository_directoryrrrr>r repo_nametitlerrr-inforr?r rrsysexitrrshutilmover) rRrrMrr rev_display existing_urlpromptresponsedest_dirs r)obtainzVersionControl.obtains6 33C88[w~~d##  NN4kYN G G G F!,,..  ' ' - -% F..t44L  sz::  ?N((** &&  ..t[_EE HKK*$T**#  KKc;7777KK FGGG NN0 T""    UFF NNB     FF 9 I    ##4#;#;F1I#F#Fq RR 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; / / / / / ?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. )rMrN)r;r<rrr)rRr8rMrs r)unpackzVersionControl.unpackVsF 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_urlbrr+ct)zR Return the current commit id of the files at the given location. rrs r)rzVersionControl.get_revisionls "!r+TraiseFcmd show_stdoutcwd on_returncodez"Literal["raise", "warn", "ignore"]extra_ok_returncodes command_desc extra_environspinnerlog_failed_cmd stdout_onlyc &t|jg|R}|t|} t||||||||j|| |  S#t $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)rrrrrrrrzCannot find command z - 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.)rr rrrFileNotFoundErrorrPermissionError) rrrrrrrrrrrs r) run_commandzVersionControl.run_commandss&38*c***  .s33L "+%9)+!/-'    !   rr=r r;r<rjoin)rr<s r)rz&VersionControl.is_repository_directorysG  4dCKRRRw~~bgll4==>>>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+rr) TNrNNNNTF)4rGrHrIr r=rrr rTrrrcr classmethodrrrrr staticmethodrrfrrrXrprrAuthInforrrrrrintrrrrrrrrr rr rrr#rrrJr+r)rZrZsG DGI!GU38_!!!%'M5c?'''%)OXc])))A3A4AAA[A [*****[* 3cc[."s"tCy"""\" S      LP ; ;3- ;4<[4I ;  ; ; ;[ ;;;;;;[;$$"%$ sE(3-#677 8$$$[$(#s#uS(3-5Q/R###[#:3-+3J+? \ 1z 1eJ E8<&*59.2#!55 49k) *55c] 5 < 5 'x}5 5sm5 S 125*+555 555[5n?3?4???[? 3 8C=   [   r+rZrO):rsloggingr;r r urllib.parsertypingrrrrrrr r r r r pip._internal.cli.spinnersrpip._internal.exceptionsrrpip._internal.utils.miscrrrrrrrrpip._internal.utils.subprocessrrrrpip._internal.utils.urlsrr__all__ getLoggerrGr>rTr)rr*r7rD ExceptionrFrLrXrvrrZrJr+r)r6s//                           877777BBBBBBBB                     433333 '  8 $ $ # - .HHHHHHIM+.8@ $00!0 c]0000:     )   ) @O@O@O@O@O@O@O@OFM(M(M(M(M(M(M(M(`jlloooooooooor+