U .e~S@sdZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl mZddlmZddlmZmZmZmZmZmZdd lmZmZdd lmZdd lmZerdd lm 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%e.e%e.fZ/dgZ0e1e2Z3ddZ4dddZ5ddZ6Gddde7Z8Gddde9Z:Gddde9Z;e;Z)r&r=r!r(r>r#r#r$__repr__szRevOptions.__repr__cCs|jdkr|jjS|jSN)r(r=default_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)rDr=get_base_rev_argsr<)r>argsr(r#r#r$to_argss  zRevOptions.to_argscCs|js dSd|jS)Nz (to revision {}))r(r&r@r#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. r<)r=make_rev_optionsr<)r>r(r#r#r$make_newszRevOptions.make_new)NN) r8r9r:__doc__r?rApropertyrDrGrIrLr#r#r#r$r;js    r;cs|eZdZiZddddddgZfddZd d Zed d Zed dZ eddZ ddZ ddZ ddZ ddZZS) VcsSupportZsshZgitZhgZbzrZsftpZsvncs:tj|jttddr(tj|jtt|dS)N uses_fragment) urllib_parseZ uses_netlocextendschemesgetattrrPsuperrOr?r@ __class__r#r$r?s zVcsSupport.__init__cCs |jSrB) _registry__iter__r@r#r#r$rYszVcsSupport.__iter__cCst|jSrB)listrXvaluesr@r#r#r$backendsszVcsSupport.backendscCsdd|jDS)NcSsg|] }|jqSr#)r1).0backendr#r#r$ sz'VcsSupport.dirnames..)r\r@r#r#r$dirnamesszVcsSupport.dirnamescCs g}|jD]}||jq |SrB)r\rRrS)r>rSr^r#r#r$r s zVcsSupport.all_schemescCsHt|dstd|jdS|j|jkrD||j|j<td|jdS)Nr!zCannot register VCS %szRegistered VCS backend: %s)hasattrr2r3r8r!rXdebug)r>clsr#r#r$registers   zVcsSupport.registercCs||jkr|j|=dSrB)rXr>r!r#r#r$ unregisters zVcsSupport.unregistercCs6|jD]&}||r td||j|Sq dS)zv Return a VersionControl object if a repository of that type is found at the given directory. zDetermine that %s uses VCS: %sN)rXr[controls_locationr2rbr!)r>r5Z vcs_backendr#r#r$get_backend_for_dirs  zVcsSupport.get_backend_for_dircCs|}|j|S)z9 Return a VersionControl object or None. )lowerrXgetrer#r#r$ get_backendszVcsSupport.get_backend)r8r9r:rXrSr?rYrNr\r`r rdrfrhrk __classcell__r#r#rVr$rOs      rOc @s8eZdZdZdZdZdZdZdZe ddZ e ddZ e dd Z e d d Z ed d Ze d8ddZe ddZddZe ddZe ddZeddZddZeddZe ddZd d!Zd"d#Zd$d%Ze d&d'Zd(d)Zd*d+Ze d,d-Ze d.d/Z e d9d2d3Z!e d4d5Z"e d6d7Z#dS):VersionControlrHr#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{}:)ri startswithr&r!)rcZ 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#rcr5r#r#r$get_subdirectoryszVersionControl.get_subdirectorycCs ||S)zR Return the revision string that should be used in a requirement. ) get_revision)rcrepo_dirr#r#r$get_requirement_revisionsz'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{}+{})r*)get_remote_urlror&r!rtrqr,)rcrsr)r'Zrevisionr*r+r#r#r$get_src_requirements    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$rE8sz VersionControl.get_base_rev_argscCst|||dS)z Return a RevOptions object. Args: rev: the name of a revision to install. extra_args: a list of extra options. rJ)r;)rcr(r<r#r#r$rKBs 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) )r-r. splitdrivernsepbool)rcZrepoZdrivetailr#r#r$_is_local_repositoryNsz#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. Nrwr>r5urlr#r#r$exportXszVersionControl.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#)rcnetlocr"r#r#r$get_netloc_and_authbsz"VersionControl.get_netloc_and_authc Cst|\}}}}}d|kr*td||ddd}|||\}}d}d|krf|dd\}}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@rH)rQZurlsplit ValueErrorr&splitrrsplitZ urlunsplit) rcrr"rr.ZqueryZfrag user_passr(r#r#r$get_url_rev_and_authus 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). NrJ)rsecretr rrKr ) r>rZ secret_urlr(rrZsecret_passwordrr< 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. /)rQZunquoterstriprr#r#r$ normalize_urlszVersionControl.normalize_urlcCs||||kS)zV Compare two repo URLs for identity, ignoring incidental differences. )r)rcZurl1Zurl2r#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. Nrwr>destrrr#r#r$ fetch_news zVersionControl.fetch_newcCstdS)z} Switch the repo at ``dest`` to point to ``URL``. Args: rev_options: a RevOptions object. Nrwrr#r#r$switchszVersionControl.switchcCstdS)z Update an already-existing repo to the given ``rev_options``. Args: rev_options: a RevOptions object. Nrwrr#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. Nrw)rcrr!r#r#r$is_commit_id_equals 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|dkrXt 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? %srrarz Deleting %srzBacking up %s to %srzSwitching %s %s to %s%s)rr-r.r/rrIis_repository_directoryrurrr2rb repo_nametitler rr(inforr3r!rsysexitr rshutilZmover) r>rrrZ rev_displayZ existing_urlpromptZresponseZdest_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)r-r.r/r rr~r#r#r$unpack?s zVersionControl.unpackcCstdS)z Return the url used at location Raises RemoteNotFoundError if the repository does not have a remote url configured. Nrwrpr#r#r$ruKszVersionControl.get_remote_urlcCstdS)zR Return the current commit id of the files at the given location. Nrwrpr#r#r$rrUszVersionControl.get_revisionTraisec Cs|t|jf|}z t||||||||j|| d WStk rv} z(| jtjkrdtd|j|jfnW5d} ~ 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_cmdzCCannot find command %r - do you have %r installed and in your PATH?N)rr!r rOSErrorerrnoZENOENTr) rccmdZ show_stdoutcwdrrrrrrer#r#r$ run_command\s&  zVersionControl.run_commandcCs,td||j|jtjtj||jS)zL Return whether a directory path is a repository directory. zChecking in %s for %s (%s)...)r2rbr1r!r-r.r/r0)rcr.r#r#r$rs z&VersionControl.is_repository_directorycCs ||S)a6 Check if a location is controlled by the vcs. 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. )rrpr#r#r$rgs z VersionControl.controls_location)NN)TNrNNNNT)$r8r9r:r!r1rrSrrC classmethodrorqrtrv staticmethodrErKr}rrrrrrrrrrrrrrurrrrrgr#r#r#r$rmsr                 ]    ' rm)N)>rMZ __future__rrZloggingr-rrZ pip._vendorrZpip._vendor.six.moves.urllibrrQZpip._internal.exceptionsrZpip._internal.utils.compatrZpip._internal.utils.miscrrr r r r Zpip._internal.utils.subprocessr rZpip._internal.utils.typingrZpip._internal.utils.urlsrtypingrrrrrrrrrrZpip._internal.utils.uirrrstrZAuthInfo__all__Z getLoggerr8r2r%r,r6 Exceptionr7objectr;rOrrmr#r#r#r$s<        0     HG