3 PfV0@sdZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl mZmZmZmZmZddgZejeZGd d d eZeZGd d d eZd dZdS)z)Handles all VCS (version control) support)absolute_importN)parse) BadCommand) display_path backup_dircall_subprocessrmtreeask_path_existsvcsget_src_requirementcseZdZiZddddddgZfddZd d Zed d Zed dZ eddZ ddZ dddZ ddZ ddZddZZS) VcsSupportZsshZgitZhgZbzrZsftpZsvncs:tjj|jttddr(tjj|jtt|jdS)N uses_fragment) urllib_parseZ uses_netlocextendschemesgetattrr superr __init__)self) __class__/usr/lib/python3.6/__init__.pyrs zVcsSupport.__init__cCs |jjS)N) _registry__iter__)rrrrr$szVcsSupport.__iter__cCst|jjS)N)listrvalues)rrrrbackends'szVcsSupport.backendscCsdd|jDS)NcSsg|] }|jqSr)dirname).0backendrrr -sz'VcsSupport.dirnames..)r)rrrrdirnames+szVcsSupport.dirnamescCs$g}x|jD]}|j|jq W|S)N)rrr)rrrrrr all_schemes/s zVcsSupport.all_schemescCsFt|dstjd|jdS|j|jkrB||j|j<tjd|jdS)NnamezCannot register VCS %szRegistered VCS backend: %s)hasattrloggerwarning__name__r#rdebug)rclsrrrregister6s    zVcsSupport.registerNcCs<||jkr|j|=n$||jjkr.|j|j=n tjddS)Nz0Cannot unregister because no class or name given)rrr#r%r&)rr)r#rrr unregister>s    zVcsSupport.unregistercCs8x2|jjD]$}|j|r tjd||j|jSq WdS)z Return the name of the version control backend if found at given location, e.g. vcs.get_backend_name('/path/to/vcs/checkout') zDetermine that %s uses VCS: %sN)rrcontrols_locationr%r(r#)rlocationvc_typerrrget_backend_nameFs    zVcsSupport.get_backend_namecCs |j}||jkr|j|SdS)N)lowerr)rr#rrr get_backendRs zVcsSupport.get_backendcCs|j|}|r|j|SdS)N)r/r1)rr-r.rrrget_backend_from_locationWs  z$VcsSupport.get_backend_from_location)NN)r' __module__ __qualname__rrrrpropertyrr!r"r*r+r/r1r2 __classcell__rr)rrr s      r cseZdZdZdZfZd+fdd ZddZddZd d Z d d Z d dZ ddZ ddZ ddZddZddZddZddZddZdd Zd!d"Zd#d$Zd,d'd(Zed)d*ZZS)-VersionControlNcs||_tt|j||dS)N)urlrr7r)rr9argskwargs)rrrrgszVersionControl.__init__cCs"tjj|\}}|jtjjp |S)zy posix absolute paths start with os.path.sep, win32 ones start with drive (like c:\folder) )ospath splitdrive startswithsep)rZrepoZdrivetailrrr_is_local_repositoryksz#VersionControl._is_local_repositorycCs |jddS)N/_)replace)rZsurnamerrrtranslate_egg_surnameusz$VersionControl.translate_egg_surnamecCstdS)z Export the repository at the url to the destination location i.e. only download the files, without vcs informations N)NotImplementedError)rr-rrrexportyszVersionControl.exportc Cszd}d|jkst||j|jjddd}tj|\}}}}}d}d|kr^|jdd\}}tj||||df}||fS)zm Returns the correct repository URL and revision by parsing the given repository URL zvSorry, '%s' is a malformed VCS url. The format is +://, e.g. svn+http://myrepo/svn/MyApp#egg=MyApp+N@r8)r9AssertionErrorsplitrZurlsplitrsplitZ urlunsplit) rZ error_messager9schemeZnetlocr=ZqueryZfragZrevrrr get_url_revszVersionControl.get_url_revcCs4|jdj|j s td||j||j|fS)zA Returns (url, revision), where both are strings rCzBad directory: %s)rstripendswithrrLget_url get_revision)rr-rrrget_infos zVersionControl.get_infocCstj|jdS)zi Normalize a URL for comparison by unquoting it and removing any trailing slash. rC)rZunquoterQ)rr9rrr normalize_urlszVersionControl.normalize_urlcCs|j||j|kS)zV Compare two repo URLs for identity, ignoring incidental differences. )rV)rZurl1Zurl2rrr compare_urlsszVersionControl.compare_urlscCstdS)zx Called when installing or updating an editable package, takes the source path of the checkout. N)rG)rdestrrrobtainszVersionControl.obtaincCstdS)zB Switch the repo at ``dest`` to point to ``URL``. N)rG)rrXr9 rev_optionsrrrswitchszVersionControl.switchcCstdS)zO Update an already-existing repo to the given ``rev_options``. N)rG)rrXrZrrrupdateszVersionControl.updatecCstdS)zp Return True if the version is identical to what exists and doesn't need to be updated. N)rG)rrXrZrrr check_versionszVersionControl.check_versionc Csd}d}tjj|rd}tjjtjj||jr|j|}|j||rtjd|j j t |||j ||stj dt ||j ||j||qtj dqtjd|j|j t ||d}ntjd ||j|j d}|rtjd|j|td|d|d}|dkr2tj d|j t ||||j|||n~|d kr>nr|d krftjdt |t|d}nJ|d krt|} tjdt || tj|| d}n|dkrtjd|S)z Prepare a location to receive a checkout/clone. Return True if the location is ready for (and requires) a checkout/clone, False otherwise. TFz)%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%(s)witch, (i)gnore, (w)ipe, (b)ackup siwbz0Directory %s already exists, and is not a %s %s.(i)gnore, (w)ipe, (b)ackup z+The plan is to install the %s repository %szWhat to do? %srrJzSwitching %s %s to %s%sz Deleting %szBacking up %s to %sar_r`rarb)r^rer`rarb)rcrf)r<r=existsjoinrrSrWr%r(Z repo_nametitlerr]infor\r&r#r r[rrshutilZmovesysexit) rrXr9rZZ rev_displayZcheckoutpromptZ existing_urlZresponseZdest_dirrrrcheck_destinations             z VersionControl.check_destinationcCs"tjj|rt||j|dS)zq Clean up current location and download the url repository (and vcs infos) into location N)r<r=rhrrY)rr-rrrunpacks zVersionControl.unpackcCstdS)z Return a string representing the requirement needed to redownload the files currently present in location, something like: {repository_url}@{revision}#egg={project_name}-{version_identifier} N)rG)rdistr-rrrr sz"VersionControl.get_src_requirementcCstdS)z_ Return the url used at location Used in get_info or check_destination N)rG)rr-rrrrS)szVersionControl.get_urlcCstdS)z_ Return the current revision of the files at location Used in get_info N)rG)rr-rrrrT0szVersionControl.get_revisionTraisec Csf|jg|}yt|||||||Stk r`}z$|jtjkrNtd|jnWYdd}~XnXdS)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 zCannot find command %rN)r#rOSErrorerrnoENOENTr) rcmdZ show_stdoutcwdZ on_returncodeZ command_descZ extra_environZspinnererrr run_command7s  zVersionControl.run_commandcCs0tjd||j|jtjj||j}tjj|S)z Check if a location is controlled by the vcs. It is meant to be overridden to implement smarter detection mechanisms for specific vcs. zChecking in %s for %s (%s)...)r%r(rr#r<r=rirh)r)r-r=rrrr,Nsz VersionControl.controls_location)N)TNrsNNN)r'r3r4r#rrrrBrFrHrPrUrVrWrYr[r\r]rprqr rSrTrz classmethodr,r6rr)rrr7as2 U   r7c CsZtj|}|rFy|j||Stk rDtjd||j|jSXtjd||jS)NzPcannot determine version of editable source in %s (%s command not found in path)ztcannot determine version of editable source in %s (is not SVN checkout, Git clone, Mercurial clone or Bazaar branch))r r2r rr%r&r#Zas_requirement)rrr-Zversion_controlrrrr [s  )__doc__Z __future__rruZloggingr<rlrmZpip._vendor.six.moves.urllibrrZpip.exceptionsrZ pip.utilsrrrrr __all__Z getLoggerr'r%objectr r r7r rrrrs     G{