3 ”Reneã@s¼dZddlmZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddlmZmZmZddlmZmZddlmZdd lmZmZmZmZmZmZdd lmZm Z m!Z!m"Z"dd l#m$Z$dd l%m&Z&e$�r>dd l'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2ddlm3Z3ddlm4Z4e.e,e5e,e5fZ6dgZ7ej8e9ƒZ:dd„Z;d"dd„ZGdd„de?ƒZ@Gdd„deAƒZBGdd„deAƒZCeCƒZDGd d!„d!eAƒZEdS)$z)Handles all VCS (version control) supporté)Úabsolute_importN)Ú pkg_resources)Úparse)Ú BadCommandÚInstallationErrorÚSubProcessError)Úconsole_to_strÚsamefile)Úsubprocess_logger)Úask_path_existsÚ backup_dirÚ display_pathÚhide_urlÚ hide_valueÚrmtree)Úformat_command_argsÚ make_commandÚmake_subprocess_output_errorÚreveal_command_args)ÚMYPY_CHECK_RUNNING)Úget_url_scheme) ÚDictÚIterableÚIteratorÚListÚOptionalÚTextÚTupleÚTypeÚUnionÚMappingÚAny)Ú HiddenText)Ú CommandArgsÚvcscCs*t|ƒ}|dkrdS|ddddgtjkS)z3 Return true if the name looks like a URL. NFÚhttpÚhttpsÚfileÚftp)rr$Ú all_schemes)ÚnameÚscheme©r,ú�/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el8.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_internal/vcs/versioncontrol.pyÚis_url8sr.cCs.tj|ƒ}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_filenameÚformat)Úrepo_urlÚrevÚ project_nameÚsubdirÚegg_project_nameÚreqr,r,r-Úmake_vcs_requirement_urlCs r7TcCsf|dkr g}tj}tjjƒ}|r*|j|ƒd}t|ƒ}y.tjt |ƒtj tj |d�} | j rb| j j ƒWn6t k rš} z|rˆtjd| |ƒ‚WYdd} ~ XnXg} x@d} | jrºt| jjƒƒ} | sÀP| jƒ} | j| dƒ|| ƒq¢Wz | jƒWd| j�r| jj ƒX| j�o| j|k} | �r\| �rF|�rFt||| | jd�}tj|ƒdj| j|ƒ}t|ƒ‚dj| ƒ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. NT)ÚstdoutÚstderrÚcwdz#Error %s while executing command %sÚ )Úcmd_argsr:ÚlinesÚ exit_statuszSCommand errored out with exit status {}: {} Check the logs for full command output.Ú)r ÚdebugÚosÚenvironÚcopyÚupdaterÚ subprocessÚPopenrÚPIPEÚstdinÚcloseÚ ExceptionÚcriticalr8rÚreadlineÚrstripÚappendÚwaitÚ returncoderÚerrorr0rÚjoin)Úcmdr:Ú extra_environÚextra_ok_returncodesÚlog_failed_cmdÚlog_subprocessÚenvÚshowing_subprocessÚ command_descÚprocÚexcÚ all_outputÚlineÚproc_had_errorÚmsgÚexc_msgr,r,r-Úcall_subprocessTs`         rbcCsd|}xBtjjtjj|dƒƒsF|}tjj|ƒ}||krtjd|ƒdSqWt||ƒrVdStjj||ƒ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) rAÚpathÚexistsrRÚdirnameÚloggerÚwarningr Úrelpath)ÚlocationÚ repo_rootÚ orig_locationÚ last_locationr,r,r-Ú!find_path_to_setup_from_repo_rootªs  rmc@s eZdZdS)ÚRemoteNotFoundErrorN)Ú__name__Ú __module__Ú __qualname__r,r,r,r-rnÆsrnc@sFeZdZdZddd„Zdd„Zedd„ƒZd d „Zd d „Z d d„Z 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_argsr2Úvc_classÚ branch_name)Úselfrtr2rsr,r,r-Ú__init__Ós zRevOptions.__init__cCsdj|jj|jƒS)Nz)r0rtr*r2)rvr,r,r-Ú__repr__èszRevOptions.__repr__cCs|jdkr|jjS|jS)N)r2rtÚdefault_arg_rev)rvr,r,r-Úarg_revìs zRevOptions.arg_revcCs0g}|j}|dk r"||jj|ƒ7}||j7}|S)z< Return the VCS-specific command arguments. N)rzrtÚget_base_rev_argsrs)rvÚargsr2r,r,r-Úto_argsôs  zRevOptions.to_argscCs|js dSdj|jƒS)Nr?z (to revision {}))r2r0)rvr,r,r-Ú to_displayszRevOptions.to_displaycCs|jj||jd�S)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)rtÚmake_rev_optionsrs)rvr2r,r,r-Úmake_newszRevOptions.make_new)NN) rorprqÚ__doc__rwrxÚpropertyrzr}r~r€r,r,r,r-rrÊs   rrcs„eZdZiZddddddgZ‡fdd„Zd d „Zed d „ƒZed d„ƒZ edd„ƒZ dd„Z dd„Z dd„Z dd„Zdd„Z‡ZS)Ú VcsSupportÚsshÚgitÚhgÚbzrÚsftpÚsvncs:tjj|jƒttddƒr(tjj|jƒtt|ƒjƒdS)NÚ uses_fragment) Ú urllib_parseÚ uses_netlocÚextendÚschemesÚgetattrrŠÚsuperrƒrw)rv)Ú __class__r,r-rws zVcsSupport.__init__cCs |jjƒS)N)Ú _registryÚ__iter__)rvr,r,r-r“!szVcsSupport.__iter__cCst|jjƒƒS)N)Úlistr’Úvalues)rvr,r,r-Úbackends%szVcsSupport.backendscCsdd„|jDƒS)NcSsg|] }|j‘qSr,)re)Ú.0Úbackendr,r,r-ú -sz'VcsSupport.dirnames..)r–)rvr,r,r-Údirnames*szVcsSupport.dirnamescCs$g}x|jD]}|j|jƒq W|S)N)r–r�rŽ)rvrŽr˜r,r,r-r)/s zVcsSupport.all_schemescCsHt|dƒstjd|jƒdS|j|jkrD|ƒ|j|j<tjd|jƒdS)Nr*zCannot register VCS %szRegistered VCS backend: %s)Úhasattrrfrgror*r’r@)rvÚclsr,r,r-Úregister7s   zVcsSupport.registercCs||jkr|j|=dS)N)r’)rvr*r,r,r-Ú unregister@s zVcsSupport.unregistercCs\i}x:|jjƒD],}|j|ƒ}|s$qtjd||jƒ|||<qW|sHdSt|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)r’r•Úget_repository_rootrfr@r*ÚmaxÚlen)rvriÚ vcs_backendsÚ vcs_backendÚ repo_pathÚinner_most_repo_pathr,r,r-Úget_backend_for_dirEs    zVcsSupport.get_backend_for_dircCs&x |jjƒD]}||jkr |Sq WdS)z9 Return a VersionControl object or None. N)r’r•rŽ)rvr+r¤r,r,r-Úget_backend_for_scheme^s z!VcsSupport.get_backend_for_schemecCs|jƒ}|jj|ƒS)z9 Return a VersionControl object or None. )Úlowerr’Úget)rvr*r,r,r-Ú get_backendhszVcsSupport.get_backend)rorprqr’rŽrwr“r‚r–ršr)r�ržr§r¨r«Ú __classcell__r,r,)r‘r-rƒs      rƒc@s@eZdZdZdZdZfZfZdZe dd„ƒZ e dd„ƒZ e dd„ƒZ e d d „ƒZ ed d „ƒZd d„Ze d8dd„ƒZe dd„ƒZdd„Ze dd„ƒZe dd„ƒZedd„ƒZdd„Zedd„ƒZe dd „ƒZd!d"„Zd#d$„Zd%d&„Ze d'd(„ƒZd)d*„Zd+d,„Ze d-d.„ƒZ e d/d0„ƒZ!e d9d2d3„ƒZ"e d4d5„ƒZ#e d6d7„ƒZ$dS):ÚVersionControlr?NcCs|jƒjdj|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©Ú startswithr0r*)rœÚ remote_urlr,r,r-Úshould_add_vcs_url_prefix~sz(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,)rœrir,r,r-Úget_subdirectory‡szVersionControl.get_subdirectorycCs |j|ƒS)zR Return the revision string that should be used in a requirement. )Ú get_revision)rœÚrepo_dirr,r,r-Úget_requirement_revision�sz'VersionControl.get_requirement_revisioncCsV|j|ƒ}|dkrdS|j|ƒr.dj|j|ƒ}|j|ƒ}|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{}+{})r4)Úget_remote_urlr°r0r*r´r±r7)rœr³r3r1Úrevisionr4r6r,r,r-Úget_src_requirement˜s    z"VersionControl.get_src_requirementcCst‚dS)z™ Return the base revision arguments for a vcs command. Args: rev: the name of a revision to install. Cannot be None. N)ÚNotImplementedError)r2r,r,r-r{´s 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,)rvÚurlÚdestr,r,r-Úis_immutable_rev_checkout¿s z(VersionControl.is_immutable_rev_checkoutcCst|||d�S)z� Return a RevOptions object. Args: rev: the name of a revision to install. extra_args: a list of extra options. )rs)rr)rœr2rsr,r,r-rÍs zVersionControl.make_rev_optionscCs&tjj|ƒ\}}|jtjjƒp$t|ƒS)zy posix absolute paths start with os.path.sep, win32 ones start with drive (like c:\folder) )rArcÚ splitdriver®ÚsepÚbool)rœÚrepoÚdriveÚtailr,r,r-Ú_is_local_repositoryÙsz#VersionControl._is_local_repositorycCst‚dS)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. N)r¸)rvrir¹r,r,r-ÚexportãszVersionControl.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)). N)NNr,)rœÚnetlocr+r,r,r-Úget_netloc_and_authísz"VersionControl.get_netloc_and_authc Cs–tj|ƒ\}}}}}d|kr*tdj|ƒƒ‚|jddƒd}|j||ƒ\}}d}d|krx|jddƒ\}}|sxtdj|ƒƒ‚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)). ú+zvSorry, {!r} is a malformed VCS url. The format is +://, e.g. svn+http://myrepo/svn/MyApp#egg=MyAppéNú@zyThe URL {!r} has an empty revision (after @) which is not supported. Include a revision after @ or remove @ from the URL.r?) r‹ÚurlsplitÚ ValueErrorr0ÚsplitrÅÚrsplitrÚ urlunsplit) rœr¹r+rÄrcÚqueryÚfragÚ 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,)ÚusernameÚpasswordr,r,r-Ú make_rev_args szVersionControl.make_rev_argsc CsT|j|jƒ\}}}|\}}d}|dk r.t|ƒ}|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). N)rs)rÑÚsecretrrÔrr) rvr¹Ú secret_urlr2rÐrÒÚsecret_passwordrÓrsÚ rev_optionsr,r,r-Úget_url_rev_options(s z"VersionControl.get_url_rev_optionscCstj|ƒjdƒS)zi Normalize a URL for comparison by unquoting it and removing any trailing slash. ú/)r‹ÚunquoterM)r¹r,r,r-Ú normalize_url8szVersionControl.normalize_urlcCs|j|ƒ|j|ƒkS)zV Compare two repo URLs for identity, ignoring incidental differences. )rÜ)rœÚurl1Úurl2r,r,r-Ú compare_urlsAszVersionControl.compare_urlscCst‚dS)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¸)rvrºr¹rØr,r,r-Ú fetch_newIs zVersionControl.fetch_newcCst‚dS)z} Switch the repo at ``dest`` to point to ``URL``. Args: rev_options: a RevOptions object. N)r¸)rvrºr¹rØr,r,r-ÚswitchUszVersionControl.switchcCst‚dS)zŠ Update an already-existing repo to the given ``rev_options``. Args: rev_options: a RevOptions object. N)r¸)rvrºr¹rØr,r,r-rD_szVersionControl.updatecCst‚dS)z¬ Return whether the id of the current commit equals the given name. Args: dest: the repository directory. name: a string name. N)r¸)rœrºr*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 ƒr²t j d|j j ƒt|ƒ|ƒ|j||jƒs¤t jdt|ƒ|j |ƒ|j|||ƒn t jdƒdSt jd|j|j t|ƒ|ƒd}nt jd ||j|j ƒd}t jd |j|ƒtdj|dƒ|dƒ}|dk�r&tjdƒ|d k�rZt jdt|ƒƒt|ƒ|j|||ƒdS|d k�rœt|ƒ}t jdt|ƒ|ƒtj||ƒ|j|||ƒdS|dk�rÌt 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 ÚsÚiÚwÚbz0Directory %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? {}rrÇÚaz Deleting %szBacking up %s to %szSwitching %s %s to %s%s©rärårærç)rãrê©rårærç)rèrëéÿÿÿÿ)rÙrArcrdràr~Úis_repository_directoryrµrßrÕrfr@Ú repo_nameÚtitler râr2ÚinforDrgr*r r0ÚsysÚexitrr ÚshutilÚmoverá) rvrºr¹rØÚ rev_displayÚ existing_urlÚpromptÚresponseÚdest_dirr,r,r-Úobtainus‚           zVersionControl.obtaincCs&tjj|ƒ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. )r¹N)rArcrdrrú)rvrir¹r,r,r-ÚunpackÓs zVersionControl.unpackcCst‚dS)z– Return the url used at location Raises RemoteNotFoundError if the repository does not have a remote url configured. N)r¸)rœrir,r,r-rµßs zVersionControl.get_remote_urlcCst‚dS)zR Return the current commit id of the files at the given location. N)r¸)rœrir,r,r-r²êszVersionControl.get_revisionTcCslt|jf|žŽ}yt|||||d�Stk rf}z(|jtjkrTtdjftƒŽƒ‚n‚WYdd}~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*rbÚOSErrorÚerrnoÚENOENTrr0Úlocals)rœrSr:rTrUrVÚer,r,r-Ú run_commandòs  zVersionControl.run_commandcCs,tjd||j|jƒtjjtjj||jƒƒS)zL Return whether a directory path is a repository directory. zChecking in %s for %s (%s)...)rfr@rer*rArcrdrR)rœrcr,r,r-rísz&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í)rœrir,r,r-r s z"VersionControl.get_repository_root)NN)NNNT)%rorprqr*rerîrŽÚ unset_environryÚ classmethodr°r±r´r·Ú staticmethodr{r»rrÂrÃrÅrÑrÔrÙrÜrßràrárDrârúrûrµr²rrír r,r,r,r-r­tsJ           ^   r­)N)NNNT)Fr�Ú __future__rrýÚloggingrArórErñÚ pip._vendorrZpip._vendor.six.moves.urllibrr‹Úpip._internal.exceptionsrrrÚpip._internal.utils.compatrr Úpip._internal.utils.loggingr Úpip._internal.utils.miscr r r rrrÚpip._internal.utils.subprocessrrrrÚpip._internal.utils.typingrÚpip._internal.utils.urlsrÚtypingrrrrrrrrrr r!r"r#ÚstrZAuthInfoÚ__all__Ú getLoggerrorfr.r7rbrmrJrnÚobjectrrrƒr$r­r,r,r,r-ÚsF       4     QI^