o gY @sdZddlZddlZddlZddlZddlZddlmZm Z m Z m Z m Z m Z mZmZmZmZmZddlmZddlmZmZddlmZmZmZmZmZmZmZm Z ddl!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'erldd lm(Z(d gZ)e*e+Z,eee-ee-fZ.d e-d e/fd dZ0 d#de-de-de-dee-d e-f ddZ1de-de-d ee-fddZ2Gddde3Z4Gddde3Z5GdddZ6Gdd d Z7e7Z8Gd!d"d"Z9dS)$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)LiteralvcsnamereturncCs&t|}|dur dS|gdtjvS)z3 Return true if the name looks like a URL. NF)httphttpsfileftp)rr all_schemes)rschemer'B/usr/lib/python3/dist-packages/pip/_internal/vcs/versioncontrol.pyis_url9sr)repo_urlrev project_namesubdircCs6|dd}|d|d|}|r|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+r,r-egg_project_namereqr'r'r(make_vcs_requirement_urlCs r4location repo_rootcCs\|}t|s|}tj|}||krtd|dSt|rtj||r'dStj||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)r5r6 orig_location last_locationr'r'r((find_path_to_project_root_from_repo_rootUs   r@c@s eZdZdS)RemoteNotFoundErrorN)__name__ __module__ __qualname__r'r'r'r(rArsrAcs"eZdZdeffdd ZZS)RemoteNotValidErrorurlcst|||_dSN)super__init__rF)selfrF __class__r'r(rIws  zRemoteNotValidError.__init__)rBrCrDstrrI __classcell__r'r'rKr(rEvsrEc @seZdZdZ  ddeddeedeeddfdd Zdefd d Z e deefd d Z defddZ defddZ deddfddZdS) 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 cCs(|durg}||_||_||_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)rRr+rP branch_name)rJrPr+rRr'r'r(rIs   zRevOptions.__init__cCsd|jjd|jdS)Nz )rPrr+rJr'r'r(__repr__szRevOptions.__repr__cCs|jdur |jjS|jSrG)r+rPdefault_arg_revrUr'r'r(arg_revs zRevOptions.arg_revcCs0g}|j}|dur||j|7}||j7}|S)z< Return the VCS-specific command arguments. N)rXrPget_base_rev_argsrR)rJargsr+r'r'r(to_argss  zRevOptions.to_argscCs|jsdSd|jdS)Nz (to revision )r+rUr'r'r( to_displayszRevOptions.to_displaycCs|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. rR)rPmake_rev_optionsrR)rJr+r'r'r(make_newszRevOptions.make_newNN)rBrCrD__doc__r r rMrrIrVpropertyrXr[r_rbr'r'r'r(rO|s&   rOcseZdZUiZeedfed<gdZdfdd Zde efdd Z e de dfd d Z e de efd d Ze de efddZdedddfddZdeddfddZdededfddZdededfddZdededfddZZS) VcsSupportrQ _registry)sshgithgbzrsftpsvnr Ncstjj|jtdSrG)urllibparse uses_netlocextendschemesrHrIrUrKr'r(rIszVcsSupport.__init__cCs |jSrG)rg__iter__rUr'r'r(rss zVcsSupport.__iter__cCst|jSrG)listrgvaluesrUr'r'r(backendsszVcsSupport.backendscCsdd|jDS)NcSsg|]}|jqSr')r9).0backendr'r'r( sz'VcsSupport.dirnames..)rvrUr'r'r(dirnamesszVcsSupport.dirnamescCs g}|jD]}||jq|SrG)rvrqrr)rJrrrxr'r'r(r%s zVcsSupport.all_schemesclscCsLt|dstd|jdS|j|jvr$||j|j<td|jdSdS)NrzCannot register VCS %szRegistered VCS backend: %s)hasattrr:r;rBrrgdebug)rJr{r'r'r(registers  zVcsSupport.registerrcCs||jvr |j|=dSdSrG)rgrJrr'r'r( unregisters  zVcsSupport.unregisterr5cCsXi}|jD]}||}|sqtd||j|||<q|s"dSt|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)rgruget_repository_rootr:r}rmaxlen)rJr5 vcs_backends vcs_backend repo_pathinner_most_repo_pathr'r'r(get_backend_for_dirs   zVcsSupport.get_backend_for_dirr&cCs&|jD] }||jvr|SqdS)9 Return a VersionControl object or None. N)rgrurr)rJr&rr'r'r(get_backend_for_schemes  z!VcsSupport.get_backend_for_schemecCs|}|j|S)r)lowerrggetrr'r'r( get_backends zVcsSupport.get_backend)r N)rBrCrDrgrrM__annotations__rrrIrrsrerrvrzr%r r~rr rrrrNr'r'rKr(rfs  rfc@sZeZdZUdZdZdZdZeedfe d<dZ eedfe d<dZ e ee d<e ded efd d Ze d ed e efd dZe ded efddZe deded efddZeded eefddZdeded efddZe d\de ede ed efddZe ded efd d!Ze d"ed#ed eeee ee efffd$d%Ze ded eee eeffd&d'Zed(e ed)e ed efd*d+Zded eeeffd,d-Z eded efd.d/Z!e d0ed1ed efd2d3Z"deded4ed5e#d df d6d7Z$deded4ed dfd8d9Z%deded4ed dfd:d;Z&e dedZ'deded5e#d dfd?d@Z(d eded5e#d dfdAdBZ)e d ed efdCdDZ*e d ed efdEdFZ+e G  H     G Id]dJe,eeefdKedLe edMdNdOe e-e#dPe edQe e.ee/fdRe e0dSedTed efdUdVZ1e dWed efdXdYZ2e d ed e efdZd[Z3dS)^rQr\r'.rr unset_environNrW 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)r{rr'r'r(should_add_vcs_url_prefixsz(VersionControl.should_add_vcs_url_prefixr5cCdS)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'r{r5r'r'r(get_subdirectory$szVersionControl.get_subdirectoryrepo_dircCs ||S)zR Return the revision string that should be used in a requirement. ) get_revision)r{rr'r'r(get_requirement_revision,s z'VersionControl.get_requirement_revisionr,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} +)r-)get_remote_urlrrrrr4)r{rr,r*revisionr-r3r'r'r(get_src_requirement3s   z"VersionControl.get_src_requirementr+cCt)z Return the base revision arguments for a vcs command. Args: rev: the name of a revision to install. Cannot be None. NotImplementedErrorr^r'r'r(rYKz VersionControl.get_base_rev_argsrFdestcCr)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')rJrFrr'r'r(is_immutable_rev_checkoutUs z(VersionControl.is_immutable_rev_checkoutrRcCst|||dS)z Return a RevOptions object. Args: rev: the name of a revision to install. extra_args: a list of extra options. r`)rO)r{r+rRr'r'r(rabs zVersionControl.make_rev_optionsrepocCs&tj|\}}|tjjpt|S)zs posix absolute paths start with os.path.sep, win32 ones start with drive (like c:\folder) )r7r8 splitdriversepbool)r{rdrivetailr'r'r(_is_local_repositoryosz#VersionControl._is_local_repositorynetlocr&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)). rcr')r{rr&r'r'r(get_netloc_and_authxsz"VersionControl.get_netloc_and_authc Cstj|\}}}}}d|vrtd||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=MyAppNr0zyThe URL {!r} has an empty revision (after @) which is not supported. Include a revision after @ or remove @ from the URL.r\) rnrourlsplit ValueErrorformatsplitrrsplitr urlunsplit) r{rFr&rr8queryfrag user_passr+r'r'r(get_url_rev_and_auths$ z#VersionControl.get_url_rev_and_authusernamepasswordcCsgS)zM Return the RevOptions "extra arguments" to use in obtain(). r')rrr'r'r( make_rev_argszVersionControl.make_rev_argsc CsT||j\}}}|\}}d}|durt|}|||}|j||d} t|| fS)zq Return the URL and RevOptions object to use in obtain(), as a tuple (url, rev_options). Nr`)rsecretrrrar) rJrF secret_urlr+rrsecret_passwordrrR 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. /)rnrounquoterstrip)rFr'r'r( normalize_urlszVersionControl.normalize_urlurl1url2cCs||||kS)zV Compare two repo URLs for identity, ignoring incidental differences. )r)r{rrr'r'r( compare_urlsszVersionControl.compare_urlsr verbositycCr)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)rJrrFrrr'r'r( fetch_news zVersionControl.fetch_newcCr)z} Switch the repo at ``dest`` to point to ``URL``. Args: rev_options: a RevOptions object. rrJrrFrr'r'r(switchrzVersionControl.switchcCr)z Update an already-existing repo to the given ``rev_options``. Args: rev_options: a RevOptions object. rrr'r'r(updaterzVersionControl.updatercCr)z Return whether the id of the current commit equals the given name. Args: dest: the repository directory. name: a string name. r)r{rrr'r'r(is_commit_id_equals z!VersionControl.is_commit_id_equalc Cs||\}}tj|s|j||||ddS|}||rl||}|||j r\t d|j t|||||jsUt dt||j |||||dSt ddSt d|j|j t||d}n t d||j|j d }t d |j|td |d |d }|dkrtd|dkrt dt|t||j||||ddS|dkrt|} t dt|| t|| |j||||ddS|dkrt d|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)rr7r8existsrr_is_repository_directoryrrrr:r} repo_nametitlerrr+inforr;rrrsysexitrrshutilmover) rJrrFrr rev_display existing_urlpromptresponsedest_dirr'r'r(obtains      zVersionControl.obtaincCs(tj|r t||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. )rFrN)r7r8rrr)rJr5rFrr'r'r(unpackVs zVersionControl.unpackcCr)z Return the url used at location Raises RemoteNotFoundError if the repository does not have a remote url configured. rrr'r'r(rbrzVersionControl.get_remote_urlcCr)zR Return the current commit id of the files at the given location. rrr'r'r(rlszVersionControl.get_revisionTraiseFcmd show_stdoutcwd on_returncodez"Literal["raise", "warn", "ignore"]extra_ok_returncodes command_desc extra_environspinnerlog_failed_cmd stdout_onlyc Cst|jg|R}|durt|}zt||||||||j|| | d WSty6td|jd|jdtyEtd|jdw)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.)rrrrrFileNotFoundErrorrPermissionError) r{rrrrrrrrrrr'r'r( run_commandss8    zVersionControl.run_commandr8cCs,td||j|jtjtj||jS)zL Return whether a directory path is a repository directory. zChecking in %s for %s (%s)...)r:r}r9rr7r8rjoin)r{r8r'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_rootrc) TNrNNNNTF)4rBrCrDrr9rrrr rMrrrWr classmethodrrrrr staticmethodrrYrrrOrarrAuthInforrrrrrintrrrrrrrrr rrrr rrrr'r'r'r(rQs      "     Y       7rQrG):rdloggingr7rr urllib.parserntypingrrrrrrrr r r r pip._internal.cli.spinnersr pip._internal.exceptionsrrpip._internal.utils.miscrrrrrrrrpip._internal.utils.subprocessrrrrpip._internal.utils.urlsrr__all__ getLoggerrBr:rMrrr)r4r@ ExceptionrArErOrfrrQr'r'r'r(sV4 (      CP