U n a'\@sdZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl mZmZddlmZddlmZmZmZmZmZmZdd lmZmZdd lmZdd lmZer&dd l m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+dd l,m-Z-ddlm.Z.ddlm/Z/e)e'e0e'e0fZ1dgZ2e3e4Z5ddZ6dddZ7ddZ8Gddde9Z:Gddde;ZGddde;Z?dS) z)Handles all VCS (version control) support)absolute_importN) pkg_resources)parse) BadCommandInstallationError)samefile)ask_path_exists backup_dir display_pathhide_url hide_valuermtree)call_subprocess make_command)MYPY_CHECK_RUNNING)get_url_scheme) AnyDictIterableIteratorListMappingOptionalTextTupleTypeUnion)SpinnerInterface) HiddenText) CommandArgsvcscCs*t|}|dkrdS|ddddgtjkS)z3 Return true if the name looks like a URL. NFhttphttpsfileftp)rr all_schemes)nameschemer(aC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-6mt8ur68\pip\_internal\vcs\versioncontrol.pyis_url.sr*cCs.t|}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={})r to_filenameformat)repo_urlrev project_namesubdiregg_project_namereqr(r(r)make_vcs_requirement_url9s r3cCs`|}tjtj|dsD|}tj|}||krtd|dSqt||rRdStj||S)z Find the path to `setup.py` by searching up the filesystem from `location`. Return the path to `setup.py` relative to `repo_root`. Return None if `setup.py` is in `repo_root` or cannot be found. zsetup.pyzGCould not find setup.py for directory %s (tried all parent directories)N) ospathexistsjoindirnameloggerwarningrrelpath)location repo_root orig_location last_locationr(r(r)!find_path_to_setup_from_repo_rootJs  r@c@s eZdZdS)RemoteNotFoundErrorN)__name__ __module__ __qualname__r(r(r(r)rAfsrAc@sFeZdZdZdddZddZeddZd d Zd d Z d dZ dS) RevOptionsz Encapsulates a VCS-specific revision to install, along with any VCS install options. Instances of this class should be treated as if immutable. NcCs(|dkr 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) extra_argsr.vc_class branch_name)selfrGr.rFr(r(r)__init__ss zRevOptions.__init__cCsd|jj|jS)Nz)r,rGr&r.rIr(r(r)__repr__szRevOptions.__repr__cCs|jdkr|jjS|jSN)r.rGdefault_arg_revrKr(r(r)arg_revs zRevOptions.arg_revcCs0g}|j}|dk r"||j|7}||j7}|S)z< Return the VCS-specific command arguments. N)rOrGget_base_rev_argsrF)rIargsr.r(r(r)to_argss  zRevOptions.to_argscCs|js dSd|jS)Nz (to revision {}))r.r,rKr(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. rF)rGmake_rev_optionsrF)rIr.r(r(r)make_newszRevOptions.make_new)NN) rBrCrD__doc__rJrLpropertyrOrRrTrWr(r(r(r)rEjs    rEcseZdZiZddddddgZfddZd d Zed d Zed dZ eddZ ddZ ddZ ddZ ddZddZZS) VcsSupportsshgithgbzrsftpsvncs:tj|jttddr(tj|jtt|dS)N uses_fragment) urllib_parse uses_netlocextendschemesgetattrrasuperrZrJrK __class__r(r)rJs zVcsSupport.__init__cCs |jSrM) _registry__iter__rKr(r(r)rkszVcsSupport.__iter__cCst|jSrM)listrjvaluesrKr(r(r)backendsszVcsSupport.backendscCsdd|jDS)NcSsg|] }|jqSr()r8).0backendr(r(r) sz'VcsSupport.dirnames..)rnrKr(r(r)dirnamesszVcsSupport.dirnamescCs g}|jD]}||jq |SrM)rnrdre)rIrerpr(r(r)r%s zVcsSupport.all_schemescCsHt|dstd|jdS|j|jkrD||j|j<td|jdS)Nr&zCannot register VCS %szRegistered VCS backend: %s)hasattrr9r:rBr&rjdebug)rIclsr(r(r)registers   zVcsSupport.registercCs||jkr|j|=dSrM)rjrIr&r(r(r) unregisters zVcsSupport.unregistercCsXi}|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)rjrmget_repository_rootr9rtr&maxlen)rIr< vcs_backends vcs_backend repo_pathinner_most_repo_pathr(r(r)get_backend_for_dirs   zVcsSupport.get_backend_for_dircCs&|jD]}||jkr |Sq dS)9 Return a VersionControl object or None. N)rjrmre)rIr'r~r(r(r)get_backend_for_schemes  z!VcsSupport.get_backend_for_schemecCs|}|j|S)r)lowerrjgetrwr(r(r) get_backendszVcsSupport.get_backend)rBrCrDrjrerJrkrYrnrrr%rvrxrrr __classcell__r(r(rhr)rZs      rZc @s@eZdZdZdZdZdZdZdZe ddZ e ddZ e dd Z e d d Z ed d ZddZe d:ddZe ddZddZe ddZe ddZeddZddZeddZe d d!Zd"d#Zd$d%Zd&d'Ze d(d)Zd*d+Zd,d-Ze d.d/Z e d0d1Z!e d;d4d5Z"e d6d7Z#e d8d9Z$dS)<VersionControlrSr(NcCs|d|j S)z Return whether the vcs prefix (e.g. "git+") should be added to a repository's remote url when used in a requirement. z{}:)r startswithr,r&)ru remote_urlr(r(r)should_add_vcs_url_prefixsz(VersionControl.should_add_vcs_url_prefixcCsdS)z~ Return the path to setup.py, relative to the repo root. Return None if setup.py is in the repo root. Nr(rur<r(r(r)get_subdirectory'szVersionControl.get_subdirectorycCs ||S)zR Return the revision string that should be used in a requirement. ) get_revision)rurepo_dirr(r(r)get_requirement_revision0sz'VersionControl.get_requirement_revisioncCsV||}|dkrdS||r.d|j|}||}||}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} Nz{}+{})r0)get_remote_urlrr,r&rrr3)rurr/r-revisionr0r2r(r(r)get_src_requirement8s    z"VersionControl.get_src_requirementcCstdS)z Return the base revision arguments for a vcs command. Args: rev: the name of a revision to install. Cannot be None. NNotImplementedError)r.r(r(r)rPTs z VersionControl.get_base_rev_argscCsdS)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()rIurldestr(r(r)is_immutable_rev_checkout_s z(VersionControl.is_immutable_rev_checkoutcCst|||dS)z Return a RevOptions object. Args: rev: the name of a revision to install. extra_args: a list of extra options. rU)rE)rur.rFr(r(r)rVms zVersionControl.make_rev_optionscCs&tj|\}}|tjjp$t|S)zy posix absolute paths start with os.path.sep, win32 ones start with drive (like c:\folder) )r4r5 splitdriversepbool)rurepodrivetailr(r(r)_is_local_repositoryysz#VersionControl._is_local_repositorycCstdS)z Export the repository at the url to the destination location i.e. only download the files, without vcs informations :param url: the repository URL starting with a vcs prefix. NrrIr<rr(r(r)exportszVersionControl.exportcCs|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()runetlocr'r(r(r)get_netloc_and_authsz"VersionControl.get_netloc_and_authc Cst|\}}}}}d|kr*td||ddd}|||\}}d}d|krx|dd\}}|sxtd|t||||df}|||fS)z Parse the repository URL to use, and return the URL, revision, and auth info to use. Returns: (url, rev, (username, password)). +zvSorry, {!r} is a malformed VCS url. The format is +://, e.g. svn+http://myrepo/svn/MyApp#egg=MyAppN@zyThe URL {!r} has an empty revision (after @) which is not supported. Include a revision after @ or remove @ from the URL.rS) rburlsplit ValueErrorr,splitrrsplitr urlunsplit) rurr'rr5queryfrag user_passr.r(r(r)get_url_rev_and_auths( z#VersionControl.get_url_rev_and_authcCsgS)zM Return the RevOptions "extra arguments" to use in obtain(). r()usernamepasswordr(r(r) make_rev_argsszVersionControl.make_rev_argsc CsT||j\}}}|\}}d}|dk r.t|}|||}|j||d} t|| fS)z Return the URL and RevOptions object to use in obtain() and in some cases export(), as a tuple (url, rev_options). NrU)rsecretr rrVr ) rIr secret_urlr.rrsecret_passwordrrF rev_optionsr(r(r)get_url_rev_optionss z"VersionControl.get_url_rev_optionscCst|dS)zi Normalize a URL for comparison by unquoting it and removing any trailing slash. /)rbunquoterstriprr(r(r) normalize_urlszVersionControl.normalize_urlcCs||||kS)zV Compare two repo URLs for identity, ignoring incidental differences. )r)ruurl1url2r(r(r) compare_urlsszVersionControl.compare_urlscCstdS)z 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. NrrIrrrr(r(r) fetch_news zVersionControl.fetch_newcCstdS)z} Switch the repo at ``dest`` to point to ``URL``. Args: rev_options: a RevOptions object. Nrrr(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.updatecCstdS)z Return whether the id of the current commit equals the given name. Args: dest: the repository directory. name: a string name. Nr)rurr&r(r(r)is_commit_id_equal s z!VersionControl.is_commit_id_equalc Cs||\}}tj|s,||||dS|}||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 }|d kr&td|dkrZt dt|t|||||dS|dkrt|}t dt||t||||||dS|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. Nz)%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)rr4r5r6rrTis_repository_directoryrrrr9rt repo_nametitler rr.inforr:r&rr,sysexitr r shutilmover) rIrrr rev_display existing_urlpromptresponsedest_dirr(r(r)obtains           zVersionControl.obtaincCs&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. rN)r4r5r6r rrr(r(r)unpackss zVersionControl.unpackcCstdS)z Return the url used at location Raises RemoteNotFoundError if the repository does not have a remote url configured. Nrrr(r(r)rs zVersionControl.get_remote_urlcCstdS)zR Return the current commit id of the files at the given location. Nrrr(r(r)rszVersionControl.get_revisionTraisec Cszt|jf|}z t||||||||j|| d WStk rt} z&| jtjkrbtdjft nW5d} ~ XYnXdS)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 ) on_returncodeextra_ok_returncodes command_desc extra_environ unset_environspinnerlog_failed_cmdzWCannot find command {cls.name!r} - do you have {cls.name!r} installed and in your PATH?N) rr&rrOSErrorerrnoENOENTrr,locals) rucmd show_stdoutcwdrrrrrrer(r(r) run_commands& zVersionControl.run_commandcCs,td||j|jtjtj||jS)zL Return whether a directory path is a repository directory. zChecking in %s for %s (%s)...)r9rtr8r&r4r5r6r7)rur5r(r(r)rs z&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)rzs z"VersionControl.get_repository_root)NN)TNrNNNNT)%rBrCrDr&r8rrerrN classmethodrrrr staticmethodrPrrVrrrrrrrrrrrrrrrrrrrzr(r(r(r)rst                 ^    ' r)N)@rX __future__rrloggingr4rr pip._vendorrZpip._vendor.six.moves.urllibrrbpip._internal.exceptionsrrpip._internal.utils.compatrpip._internal.utils.miscrr r r r r pip._internal.utils.subprocessrrpip._internal.utils.typingrpip._internal.utils.urlsrtypingrrrrrrrrrrrpip._internal.cli.spinnersrrrstrZAuthInfo__all__ getLoggerrBr9r*r3r@ ExceptionrAobjectrErZr rr(r(r(r)s<       4     I^