3 Rene@sdZddlmZddlZddlZddlZddlZddlZddlZddl 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,e5fZ6dgZ7ej8e9Z:ddZ;d"ddZGddde?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) CommandArgsvcscCs*t|}|dkrdS|ddddgtjkS)z3 Return true if the name looks like a URL. NFhttphttpsfileftp)rr$ all_schemes)nameschemer,/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el9.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_internal/vcs/versioncontrol.pyis_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_filenameformat)repo_urlrev project_namesubdiregg_project_namereqr,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|rtjd| |WYdd} ~ XnXg} x@d} | jrt| jj} | sP| j} | j| d|| qWz | jWd| jr| jj X| jo| 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)stdoutstderrcwdz#Error %s while executing command %s )cmd_argsr:lines 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`         rbcCsd|}xBtjjtjj|dsF|}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) rApathexistsrRdirnameloggerwarningr relpath)location repo_root orig_location last_locationr,r,r-!find_path_to_setup_from_repo_roots  rmc@s eZdZdS)RemoteNotFoundErrorN)__name__ __module__ __qualname__r,r,r,r-rnsrnc@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_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_revcCs0g}|j}|dk r"||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_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. )rs)rtmake_rev_optionsrs)rvr2r,r,r-make_newszRevOptions.make_new)NN) rorprq__doc__rwrxpropertyrzr}r~rr,r,r,r-rrs   rrcseZdZiZddddddgZfddZd d Zed d Zed dZ eddZ ddZ ddZ ddZ ddZddZZS) VcsSupportsshgithgbzrsftpsvncs:tjj|jttddr(tjj|jtt|jdS)N uses_fragment) urllib_parse uses_netlocextendschemesgetattrrsuperrrw)rv) __class__r,r-rws zVcsSupport.__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- -sz'VcsSupport.dirnames..)r)rvr,r,r-dirnames*szVcsSupport.dirnamescCs$g}x|jD]}|j|jq W|S)N)rrr)rvrrr,r,r-r)/s zVcsSupport.all_schemescCsHt|dstjd|jdS|j|jkrD||j|j<tjd|jdS)Nr*zCannot register VCS %szRegistered VCS backend: %s)hasattrrfrgror*rr@)rvclsr,r,r-register7s   zVcsSupport.registercCs||jkr|j|=dS)N)r)rvr*r,r,r- unregister@s zVcsSupport.unregistercCs\i}x:|jjD],}|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)rrget_repository_rootrfr@r*maxlen)rvri vcs_backends vcs_backend repo_pathinner_most_repo_pathr,r,r-get_backend_for_dirEs    zVcsSupport.get_backend_for_dircCs&x |jjD]}||jkr |Sq WdS)z9 Return a VersionControl object or None. N)rrr)rvr+rr,r,r-get_backend_for_scheme^s z!VcsSupport.get_backend_for_schemecCs|j}|jj|S)z9 Return a VersionControl object or None. )lowerrget)rvr*r,r,r- get_backendhszVcsSupport.get_backend)rorprqrrrwrrrrr)rrrrr __classcell__r,r,)rr-rs      rc@s@eZdZdZdZdZfZfZdZe ddZ e ddZ e ddZ e d d Z ed d Zd dZe d8ddZe ddZddZe ddZe ddZeddZddZeddZe dd Zd!d"Zd#d$Zd%d&Ze d'd(Zd)d*Zd+d,Ze d-d.Z e d/d0Z!e d9d2d3Z"e d4d5Z#e d6d7Z$dS):VersionControlr?NcCs|jjdj|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,)rrir,r,r-get_subdirectoryszVersionControl.get_subdirectorycCs |j|S)zR Return the revision string that should be used in a requirement. ) get_revision)rrepo_dirr,r,r-get_requirement_revisionsz'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_urlrr0r*rrr7)rrr3r1revisionr4r6r,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. 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,)rvurldestr,r,r-is_immutable_rev_checkouts 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. )rs)rr)rr2rsr,r,r-rs zVersionControl.make_rev_optionscCs&tjj|\}}|jtjjp$t|S)zy posix absolute paths start with os.path.sep, win32 ones start with drive (like c:\folder) )rArc splitdriversepbool)rrepodrivetailr,r,r-_is_local_repositorysz#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. N)r)rvrirr,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)). N)NNr,)rnetlocr+r,r,r-get_netloc_and_authsz"VersionControl.get_netloc_and_authc Cstj|\}}}}}d|kr*tdj||jddd}|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=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 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)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_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. N)r)rvrrrr,r,r- fetch_newIs zVersionControl.fetch_newcCstdS)z} Switch the repo at ``dest`` to point to ``URL``. Args: rev_options: a RevOptions object. N)r)rvrrrr,r,r-switchUszVersionControl.switchcCstdS)z Update an already-existing repo to the given ``rev_options``. Args: rev_options: a RevOptions object. N)r)rvrrrr,r,r-rD_szVersionControl.updatecCstdS)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}nt jd ||j|j d}t jd |j|tdj|d|d}|dkr&tjd|d krZt jdt|t||j|||dS|d krt|}t jdt||tj|||j|||dS|dkrt 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.obtaincCs&tjj|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)rArcrdrr)rvrirr,r,r-unpacks zVersionControl.unpackcCstdS)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_urlcCstdS)zR Return the current commit id of the files at the given location. N)r)rrir,r,r-rszVersionControl.get_revisionTcCslt|jf|}yt|||||dStk rf}z(|jtjkrTtdjftnWYdd}~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-rsz&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)NN)NNNT)%rorprqr*rerr unset_environry classmethodrrrr staticmethodr{rrrrrrrrrrrrrDrrrrrrrrr,r,r,r-rtsJ           ^   r)N)NNNT)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       4     QI^