U 巀gW@sdZddlZddlZddlZddlZddlZddlmZm Z ddl m Z m Z m Z mZmZmZmZmZmZmZmZddlmZddlmZmZddlmZmZmZmZm Z m!Z!m"Z"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(d gZ)e*e+Z,eee-ee-fZ.e-e/d d d Z0de-e-e-ee-e-d ddZ1e-e-ee-dddZ2Gddde3Z4Gddde3Z5eddGdddZ6GdddZ7e7Z8GdddZ9dS) z)Handles all VCS (version control) supportN) dataclassfield) AnyDictIterableIteratorListLiteralMappingOptionalTupleTypeUnion)SpinnerInterface) BadCommandInstallationError) HiddenTextask_path_exists backup_dir display_pathhide_url hide_valueis_installable_dirrmtree) CommandArgscall_subprocessformat_command_args make_commandvcsnamereturncCs,tj|j}|sdS|ddddgtjkS)z3 Return true if the name looks like a URL. Fhttphttpsfileftp)urllibparseurlsplitschemer all_schemes)r r)r+N/opt/hc_python/lib/python3.8/site-packages/pip/_internal/vcs/versioncontrol.pyis_url2sr-)repo_urlrev project_namesubdirr!cCs6|dd}|d|d|}|r2|d|7}|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/r0r1egg_project_namereqr+r+r,make_vcs_requirement_url<s r8)location repo_rootr!cCsV|}t|s6|}tj|}||krtd|dSqtj||rHdStj||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)r9r: orig_location last_locationr+r+r,(find_path_to_project_root_from_repo_rootNs  rDc@s eZdZdS)RemoteNotFoundErrorN)__name__ __module__ __qualname__r+r+r+r,rEksrEcs"eZdZedfdd ZZS)RemoteNotValidErrorurlcst|||_dSN)super__init__rK)selfrK __class__r+r,rNps zRemoteNotValidError.__init__)rFrGrHstrrN __classcell__r+r+rPr,rIosrIT)frozenc@seZdZUdZeded<dZeeed<e e dZ e ed<dZ eeed<ed d d Zeeed d d Ze d ddZed ddZeddddZdS) 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. VersionControlvc_classNr/)default_factory extra_args branch_namer!cCsd|jjd|jdS)Nz )rWr r/rOr+r+r,__repr__szRevOptions.__repr__cCs|jdkr|jjS|jSrL)r/rWdefault_arg_revr]r+r+r,arg_revs zRevOptions.arg_revcCs0g}|j}|dk r"||j|7}||j7}|S)z< Return the VCS-specific command arguments. N)r`rWget_base_rev_argsrY)rOargsr/r+r+r,to_argss  zRevOptions.to_argscCs|js dSd|jdS)Nz (to revision )r/r]r+r+r, to_displayszRevOptions.to_displayr/r!cCs|jj||jdS)z Make a copy of the current instance, but with a new rev. Args: rev: the name of the revision for the new object. rY)rWmake_rev_optionsrY)rOr/r+r+r,make_newszRevOptions.make_new)rFrGrH__doc__r __annotations__r/r rRrlistrYrrZr^propertyr`rcrgrkr+r+r+r,rUus   rUcseZdZUiZeedfed<ddddddgZd d fd d Ze ed d dZ e e dd ddZ e e ed ddZe e ed ddZedd dddZed dddZeeddddZeedddd Zeeddd!d"ZZS)# VcsSupportrV _registrysshgithgbzrsftpsvnNr[cstjj|jtdSrL)r&r' uses_netlocextendschemesrMrNr]rPr+r,rNszVcsSupport.__init__cCs |jSrL)rq__iter__r]r+r+r,r{szVcsSupport.__iter__cCst|jSrL)rnrqvaluesr]r+r+r,backendsszVcsSupport.backendscCsdd|jDS)NcSsg|] }|jqSr+)r=).0backendr+r+r, sz'VcsSupport.dirnames..)r}r]r+r+r,dirnamesszVcsSupport.dirnamescCs g}|jD]}||jq |SrL)r}ryrz)rOrzrr+r+r,r*s zVcsSupport.all_schemes)clsr!cCsHt|dstd|jdS|j|jkrD||j|j<td|jdS)Nr zCannot register VCS %szRegistered VCS backend: %s)hasattrr>r?rFr rqdebug)rOrr+r+r,registers   zVcsSupport.registerrcCs||jkr|j|=dSrL)rqrOr r+r+r, unregisters zVcsSupport.unregisterr9r!cCsXi}|jD],}||}|s"qtd||j|||<q|sDdSt|td}||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)rqr|get_repository_rootr>rr maxlen)rOr9 vcs_backends vcs_backend repo_pathinner_most_repo_pathr+r+r,get_backend_for_dirs   zVcsSupport.get_backend_for_dir)r)r!cCs&|jD]}||jkr |Sq dS)9 Return a VersionControl object or None. N)rqr|rz)rOr)rr+r+r,get_backend_for_schemes  z!VcsSupport.get_backend_for_schemecCs|}|j|S)r)lowerrqgetrr+r+r, get_backendszVcsSupport.get_backend)rFrGrHrqrrRrmrzrNrr{rorr}rr*r rrr rrrrSr+r+rPr,rps  rpc@seZdZUdZdZdZdZeedfe d<dZ eedfe d<dZ e ee d<e eedd d Ze ee ed d d Ze eedddZe eeedddZeeeedddZeeedddZe dQe ee eedddZe eedddZe eeeeee ee effd d!d"Ze eeee eefd#d$d%Zee ee eed&d'd(Zeeeefd#d)d*Z eeed#d+d,Z!e eeed-d.d/Z"eeee#dd0d1d2Z$eeedd3d4d5Z%eeedd3d6d7Z&e ee eed8d9d:Z'eee#dd;dd?d@Z)e eed dAdBZ*e eed dCdDZ+e dRe,eeefee edHe e-e#e ee e.ee/fe e0eeedI dJdKZ1e eedLdMdNZ2e ee ed dOdPZ3dS)SrVrdr+.rz unset_environNr_) remote_urlr!cCs||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 )rrr+r+r,should_add_vcs_url_prefix sz(VersionControl.should_add_vcs_url_prefixrcCsdS)z Return the path to Python project root, relative to the repo root. Return None if the project root is in the repo root. Nr+rr9r+r+r,get_subdirectoryszVersionControl.get_subdirectory)repo_dirr!cCs ||S)zR Return the revision string that should be used in a requirement. ) get_revision)rrr+r+r,get_requirement_revisionsz'VersionControl.get_requirement_revision)rr0r!cCsL||}||r$|jd|}||}||}t||||d}|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} +)r1)get_remote_urlrr rrr8)rrr0r.revisionr1r7r+r+r,get_src_requirement s    z"VersionControl.get_src_requirementrhcCstdS)z Return the base revision arguments for a vcs command. Args: rev: the name of a revision to install. Cannot be None. NNotImplementedErrorrfr+r+r,ra8sz VersionControl.get_base_rev_args)rKdestr!cCsdS)aZ Return true if the commit hash checked out at dest matches the revision in url. Always return False, if the VCS does not support immutable commit hashes. This method does not check if there are local uncommitted changes in dest after checkout, as pip currently has no use case for that. Fr+)rOrKrr+r+r,is_immutable_rev_checkoutBs z(VersionControl.is_immutable_rev_checkout)r/rYr!cCst|||p gdS)z Return a RevOptions object. Args: rev: the name of a revision to install. extra_args: a list of extra options. ri)rU)rr/rYr+r+r,rjOs zVersionControl.make_rev_options)repor!cCs&tj|\}}|tjjp$t|S)zs posix absolute paths start with os.path.sep, win32 ones start with drive (like c:\folder) )r;r< splitdriversepbool)rrdrivetailr+r+r,_is_local_repository\sz#VersionControl._is_local_repository)netlocr)r!cCs|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)). )NNr+)rrr)r+r+r,get_netloc_and_authesz"VersionControl.get_netloc_and_auth)rKr!c Cstj|\}}}}}d|kr.td|d|ddd}|||\}}d}d|kr~|dd\}}|s~td|dtj||||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=MyAppNr4zThe URL zm has an empty revision (after @) which is not supported. Include a revision after @ or remove @ from the URL.rd) r&r'r( ValueErrorsplitrrsplitr urlunsplit) rrKr)rr<queryfrag user_passr/r+r+r,get_url_rev_and_authzs   z#VersionControl.get_url_rev_and_auth)usernamepasswordr!cCsgS)zM Return the RevOptions "extra arguments" to use in obtain(). r+)rrr+r+r, make_rev_argsszVersionControl.make_rev_argsc CsT||j\}}}|\}}d}|dk r.t|}|||}|j||d} t|| fS)zq Return the URL and RevOptions object to use in obtain(), as a tuple (url, rev_options). Nri)rsecretrrrjr) rOrK secret_urlr/rrsecret_passwordrrY rev_optionsr+r+r,get_url_rev_optionss z"VersionControl.get_url_rev_optionscCstj|dS)zi Normalize a URL for comparison by unquoting it and removing any trailing slash. /)r&r'unquoterstriprJr+r+r, normalize_urlszVersionControl.normalize_url)url1url2r!cCs||||kS)zV Compare two repo URLs for identity, ignoring incidental differences. )r)rrrr+r+r, compare_urlsszVersionControl.compare_urls)rrKr verbosityr!cCstdS)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. Nr)rOrrKrrr+r+r, fetch_news zVersionControl.fetch_new)rrKrr!cCstdS)z} Switch the repo at ``dest`` to point to ``URL``. Args: rev_options: a RevOptions object. NrrOrrKrr+r+r,switchszVersionControl.switchcCstdS)z Update an already-existing repo to the given ``rev_options``. Args: rev_options: a RevOptions object. Nrrr+r+r,updateszVersionControl.update)rr r!cCstdS)z Return whether the id of the current commit equals the given name. Args: dest: the repository directory. name: a string name. Nr)rrr r+r+r,is_commit_id_equals z!VersionControl.is_commit_id_equal)rrKrr!c Cs||\}}tj|s0|j||||ddS|}||r||}|||j rt d|j t|||||jst dt||j |||||n t ddSt d|j|j t||d}nt d||j|j d }t d |j|td |d |d }|dkr*td|dkrbt dt|t||j||||ddS|dkrt|} t dt|| t|| |j||||ddS|dkrt d|j t|||||||dS)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 %sz What to do? rrarz Deleting %srzBacking up %s to %srzSwitching %s %s to %s%s)rr;r<existsrrgis_repository_directoryrrrr>r repo_nametitlerrr/inforr?r rsysexitrrshutilmover) rOrrKrr rev_display existing_urlpromptresponsedest_dirr+r+r,obtains           zVersionControl.obtain)r9rKrr!cCs(tj|rt||j|||ddS)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. )rKrN)r;r<rrr)rOr9rKrr+r+r,unpackCs zVersionControl.unpackcCstdS)z Return the url used at location Raises RemoteNotFoundError if the repository does not have a remote url configured. Nrrr+r+r,rOszVersionControl.get_remote_urlcCstdS)zR Return the current commit id of the files at the given location. Nrrr+r+r,rYszVersionControl.get_revisionTraiseFz"Literal["raise", "warn", "ignore"]) cmd show_stdoutcwd on_returncodeextra_ok_returncodes command_desc extra_environspinnerlog_failed_cmd stdout_onlyr!c Cst|jf|}|dkr t|}z"t||||||||j|| | d WStk rhtd|jdYnRtk rtd|jd|jdYn&tk rtd|jdYnXdS) 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 - 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.) rr rrrNotADirectoryErrorrFileNotFoundErrorPermissionError) rrrrrrrrrrrr+r+r, run_command`s6  zVersionControl.run_command)r<r!cCs,td||j|jtjtj||jS)zL Return whether a directory path is a repository directory. zChecking in %s for %s (%s)...)r>rr=r r;r<rjoin)rr<r+r+r,rsz&VersionControl.is_repository_directorycCs||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)rrr+r+r,rs z"VersionControl.get_repository_root)NN) TNrNNNNTF)4rFrGrHr r=rrzr rRrmrr_r classmethodrrrrr staticmethodrrarrrUrjrrAuthInforrrrrrintrrrrrrrrrrr rrrrrr+r+r+r,rVs         Y   9rV)N):rlloggingr;rr urllib.parser& dataclassesrrtypingrrrrrr r r r r rpip._internal.cli.spinnersrpip._internal.exceptionsrrpip._internal.utils.miscrrrrrrrrpip._internal.utils.subprocessrrrr__all__ getLoggerrFr>rRrrr-r8rD ExceptionrErIrUrprrVr+r+r+r,sD4 (     6P