Rene@svdZddlmZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddlmZmZmZddlmZmZddlmZdd lmZmZmZmZmZmZdd lmZm Z m!Z!m"Z"dd l#m$Z$dd l%m&Z&e$rdd l'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2ddlm3Z3ddlm4Z4e.e,e5e,e5fZ6dgZ7ej8e9Z:ddZ;dddZ<ddddddZ=ddZ>Gddde?Z@GdddeAZBGdddeAZCeCZDGd d!d!eAZEdS)"z)Handles all VCS (version control) support)absolute_importN) pkg_resources)parse) BadCommandInstallationErrorSubProcessError)console_to_strsamefile)subprocess_logger)ask_path_exists backup_dir display_pathhide_url hide_valuermtree)format_command_args make_commandmake_subprocess_output_errorreveal_command_args)MYPY_CHECK_RUNNING)get_url_scheme) DictIterableIteratorListOptionalTextTupleTypeUnionMappingAny) HiddenText) CommandArgsvcscCs9t|}|dkrdS|ddddgtjkS)z3 Return true if the name looks like a URL. NFhttphttpsfileftp)rr$ all_schemes)nameschemer,/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_internal/vcs/versioncontrol.pyis_url8s  r.cCsAtj|}dj|||}|r=|dj|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_urlCs r7TcCs|dkrg}tj}tjj}|r=|j|d}t|}yGtjt |dtj dtj d|} | j r| j j WnAt k r} z!|rtjd| |WYdd} ~ XnXg} xVd} | jrt| jj} | sP| j} | j| d|| qWz| jWd| jr`| jj X| jov| j|k} | r| r|rtd|d|d | d | j}tj|d j| j|}t|d j| S) z Args: extra_ok_returncodes: an iterable of integer return codes that are acceptable, in addition to 0. Defaults to None, which means []. log_failed_cmd: if false, failed commands are not logged, only raised. NTstdoutstderrcwdz#Error %s while executing command %s cmd_argslines exit_statuszSCommand errored out with exit status {}: {} Check the logs for full command output.)r debugosenvironcopyupdater subprocessPopenrPIPEstdinclose Exceptioncriticalr8rreadlinerstripappendwait returncodererrorr0rjoin)cmdr: extra_environextra_ok_returncodeslog_failed_cmdlog_subprocessenvshowing_subprocess command_descprocexc all_outputlineproc_had_errormsgexc_msgr,r,r-call_subprocessTs`                 rbcCs|}x]tjjtjj|dse|}tjj|}||kr tjd|dSq Wt||rydStjj||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) rApathexistsrRdirnameloggerwarningr relpath)location repo_root orig_location last_locationr,r,r-!find_path_to_setup_from_repo_roots$ rmc@seZdZdS)RemoteNotFoundErrorN)__name__ __module__ __qualname__r,r,r,r-rns rnc@sjeZdZdZddddZddZeddZd 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:|dkrg}||_||_||_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_argsr2vc_class branch_name)selfrtr2rsr,r,r-__init__s    zRevOptions.__init__cCsdj|jj|jS)Nz)r0rtr*r2)rvr,r,r-__repr__szRevOptions.__repr__cCs |jdkr|jjS|jS)N)r2rtdefault_arg_rev)rvr,r,r-arg_revs zRevOptions.arg_revcCsBg}|j}|dk r1||jj|7}||j7}|S)z< Return the VCS-specific command arguments. N)rzrtget_base_rev_argsrs)rvargsr2r,r,r-to_argss    zRevOptions.to_argscCs|js dSdj|jS)Nr?z (to revision {}))r2r0)rvr,r,r- to_displays zRevOptions.to_displaycCs|jj|d|jS)z Make a copy of the current instance, but with a new rev. Args: rev: the name of the revision for the new object. rs)rtmake_rev_optionsrs)rvr2r,r,r-make_newszRevOptions.make_new) rorprq__doc__rwrxpropertyrzr}r~rr,r,r,r-rrs   rrcseZdZiZddddddgZfddZd d Zed d Zed dZ eddZ ddZ ddZ ddZ ddZddZS) VcsSupportsshgithgbzrsftpsvncsOtjj|jttddr8tjj|jtt|jdS)N uses_fragment) urllib_parse uses_netlocextendschemesgetattrrsuperrrw)rv) __class__r,r-rwszVcsSupport.__init__cCs |jjS)N) _registry__iter__)rvr,r,r-r!szVcsSupport.__iter__cCst|jjS)N)listrvalues)rvr,r,r-backends%szVcsSupport.backendscCsdd|jDS)NcSsg|]}|jqSr,)re).0backendr,r,r- -s z'VcsSupport.dirnames..)r)rvr,r,r-dirnames*szVcsSupport.dirnamescCs.g}x!|jD]}|j|jqW|S)N)rrr)rvrrr,r,r-r)/szVcsSupport.all_schemescCsbt|ds&tjd|jdS|j|jkr^||j|j}|j|}|s4qtjd||j|||+://, 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.r?) rurlsplit ValueErrorr0splitrrsplitr urlunsplit) rrr+rrcqueryfrag user_passr2r,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_args szVersionControl.make_rev_argsc Cs||j|j\}}}|\}}d}|dk rEt|}|j||}|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). Nrs)rsecretrrrr) rvr secret_urlr2rrsecret_passwordrrs rev_optionsr,r,r-get_url_rev_options(s   z"VersionControl.get_url_rev_optionscCstj|jdS)zi Normalize a URL for comparison by unquoting it and removing any trailing slash. /)runquoterM)rr,r,r- normalize_url8szVersionControl.normalize_urlcCs|j||j|kS)zV Compare two repo URLs for identity, ignoring incidental differences. )r)rurl1url2r,r,r- compare_urlsAszVersionControl.compare_urlscCs tdS)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. N)r)rvrrrr,r,r- fetch_newIs zVersionControl.fetch_newcCs tdS)z} Switch the repo at ``dest`` to point to ``URL``. Args: rev_options: a RevOptions object. N)r)rvrrrr,r,r-switchUszVersionControl.switchcCs tdS)z Update an already-existing repo to the given ``rev_options``. Args: rev_options: a RevOptions object. N)r)rvrrrr,r,r-rD_szVersionControl.updatecCs tdS)z Return whether the id of the current commit equals the given name. Args: dest: the repository directory. name: a string name. N)r)rrr*r,r,r-is_commit_id_equalis z!VersionControl.is_commit_id_equalc Cs||j|\}}tjj|s>|j|||dS|j}|j|r+|j|}|j||j rt j d|j j t|||j||jst jdt||j ||j|||n t jddSt jd|j|j t||d}n"t jd ||j|j d}t jd |j|tdj|d|d}|dkrtjd|d krt jdt|t||j|||dS|d kr7t|}t jdt||tj|||j|||dS|dkrxt jd|j t||||j|||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%(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? {}rraz Deleting %szBacking up %s to %szSwitching %s %s to %s%srrrr)rrrrr)rr)rrArcrdrr~is_repository_directoryrrrrfr@ repo_nametitler rr2inforDrgr*r r0sysexitrr shutilmover) rvrrr rev_display existing_urlpromptresponsedest_dirr,r,r-obtainus                  zVersionControl.obtaincCs3tjj|rt||j|d|dS)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)rArcrdrr)rvrirr,r,r-unpacks zVersionControl.unpackcCs tdS)z Return the url used at location Raises RemoteNotFoundError if the repository does not have a remote url configured. N)r)rrir,r,r-rs zVersionControl.get_remote_urlcCs tdS)zR Return the current commit id of the files at the given location. N)r)rrir,r,r-rszVersionControl.get_revisionTcCst|j|}y#t||d|d|d|SWnUtk r}z5|jtjkrwtdjtnWYdd}~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 rTrUrVzWCannot find command {cls.name!r} - do you have {cls.name!r} installed and in your PATH?N) rr*rbOSErrorerrnoENOENTrr0locals)rrSr:rTrUrVer,r,r- run_commands  zVersionControl.run_commandcCs>tjd||j|jtjjtjj||jS)zL Return whether a directory path is a repository directory. zChecking in %s for %s (%s)...)rfr@rer*rArcrdrR)rrcr,r,r-rs z&VersionControl.is_repository_directorycCs|j|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)r)rrir,r,r-rs z"VersionControl.get_repository_root)%rorprqr*rerr unset_environry classmethodrrrr staticmethodr{rrrrrrrrrrrrrDrrrrrrrrr,r,r,r-rtsJ          ^   r)Fr __future__rrloggingrArrEr pip._vendorrZpip._vendor.six.moves.urllibrrpip._internal.exceptionsrrrpip._internal.utils.compatrr pip._internal.utils.loggingr pip._internal.utils.miscr r r rrrpip._internal.utils.subprocessrrrrpip._internal.utils.typingrpip._internal.utils.urlsrtypingrrrrrrrrrr r!r"r#strZAuthInfo__all__ getLoggerrorfr.r7rbrmrJrnobjectrrrr$rr,r,r,r-sF      ."L  Q I^