관리-도구
편집 파일: versioncontrol.cpython-39.pyc
a ����[��f�W����������������������@���s���d�Z�ddlZddlZddlZddlZddlZddlmZm Z m Z mZmZm Z mZmZmZmZmZ�ddlmZ�ddlmZmZ�ddlmZmZmZmZmZmZmZm Z �ddl!m"Z"m#Z#m$Z$�ddl%m&Z&�er�dd lm'Z'�d gZ(e�)e*�Z+eee,�ee,�f�Z-e,e.d�dd �Z/de,e,e,ee,�e,d�dd�Z0e,e,ee,�d�dd�Z1G�dd��de2�Z3G�dd��de2�Z4G�dd��d�Z5G�dd��d�Z6e6��Z7G�dd��d�Z8dS�)z)Handles all VCS (version control) support�����N)� TYPE_CHECKING�Any�Dict�Iterable�Iterator�List�Mapping�Optional�Tuple�Type�Union)�SpinnerInterface)� BadCommand�InstallationError)� HiddenText�ask_path_exists� backup_dir�display_path�hide_url� hide_value�is_installable_dir�rmtree)�CommandArgs�call_subprocess�make_command)�get_url_scheme)�Literal�vcs��name�returnc�����������������C���s&���t�|��}|du�rdS�|g�d�tj�v�S�)z3 Return true if the name looks like a URL. NF)�http�https�file�ftp)r���r����all_schemes)r����scheme��r'����D/usr/lib/python3.9/site-packages/pip/_internal/vcs/versioncontrol.py�is_url4���s����r)���)�repo_url�rev�project_name�subdirr ���c�����������������C���s6���|��dd�}|���d|��d|���}|r2|d|���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=)�replace)r*���r+���r,���r-���Zegg_project_name�reqr'���r'���r(����make_vcs_requirement_url>���s ���� r3���)�location� repo_rootr ���c�����������������C���sV���|�}t�|��s6|�}tj�|��}�|�|krt�d|��dS�qtj�||��rHdS�tj�|�|�S�)z� Find the the Python project's root by searching up the filesystem from `location`. Return the path to project root relative to `repo_root`. Return None if the project root is `repo_root`, or cannot be found. zOCould not find a Python project for directory %s (tried all parent directories)N)r����os�path�dirname�logger�warning�samefile�relpath)r4���r5���Z orig_locationZ last_locationr'���r'���r(����(find_path_to_project_root_from_repo_rootP���s���� �r=���c�������������������@���s���e�Zd�ZdS�)�RemoteNotFoundErrorN)�__name__� __module__�__qualname__r'���r'���r'���r(���r>���m���s���r>���c�����������������������s"���e�Zd�Zed���fdd�Z���ZS�)�RemoteNotValidError��urlc��������������������s���t����|��||�_d�S��N)�super�__init__rD���)�selfrD����� __class__r'���r(���rG���r���s����zRemoteNotValidError.__init__)r?���r@���rA����strrG���� __classcell__r'���r'���rI���r(���rB���q���s���rB���c�������������������@���s����e�Zd�ZdZded�ee�ee�dd�dd�Zed�dd �Z e ee�d�d d��Zed�dd �Zed�dd�Z ed�d�dd�ZdS�)� RevOptionsz� Encapsulates a VCS-specific revision to install, along with any VCS install options. Instances of this class should be treated as if immutable. N�VersionControl)�vc_classr+���� extra_argsr ���c�����������������C���s(���|du�rg�}||�_�||�_||�_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)rP���r+���rO���Zbranch_name)rH���rO���r+���rP���r'���r'���r(���rG�������s����zRevOptions.__init__�r ���c�����������������C���s���d|�j�j��d|�j�d�S�)Nz<RevOptions z: rev=�>)rO���r���r+����rH���r'���r'���r(����__repr__����s����zRevOptions.__repr__c�����������������C���s���|�j�d�u�r|�jjS�|�j�S�rE���)r+���rO����default_arg_revrS���r'���r'���r(����arg_rev����s���� zRevOptions.arg_revc�����������������C���s0���g�}|�j�}|dur"||�j�|�7�}||�j7�}|S�)z< Return the VCS-specific command arguments. N)rV���rO����get_base_rev_argsrP���)rH����argsr+���r'���r'���r(����to_args����s���� zRevOptions.to_argsc�����������������C���s���|�j�s dS�d|�j���d�S�)N��z (to revision �)�r+���rS���r'���r'���r(���� to_display����s����zRevOptions.to_display�r+���r ���c�����������������C���s���|�j�j||�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. �rP���)rO����make_rev_optionsrP���)rH���r+���r'���r'���r(����make_new����s����zRevOptions.make_new)NN)r?���r@���rA����__doc__r���r ���rK���r���rG���rT����propertyrV���rY���r]���ra���r'���r'���r'���r(���rM���w���s��� ����rM���c�����������������������s����e�Zd�ZU�i�Zeedf�ed<�g�d�Zdd���fdd�Ze e�d�dd �Z eed�d�d d��Z eee�d�dd ��Zeee�d�dd��Zed�dd�dd�Zedd�dd�Zeed�d�dd�Zeed�d�dd�Zeed�d�dd�Z���ZS�)� VcsSupportrN���� _registry)Zssh�gitZhgZbzr�sftp�svnNrQ���c��������������������s���t�jj�|�j��t������d�S�rE���)�urllib�parse�uses_netloc�extend�schemesrF���rG���rS���rI���r'���r(���rG�������s����zVcsSupport.__init__c�����������������C���s ���|�j����S�rE���)re����__iter__rS���r'���r'���r(���rn�������s����zVcsSupport.__iter__c�����������������C���s���t�|�j����S�rE���)�listre����valuesrS���r'���r'���r(����backends����s����zVcsSupport.backendsc�����������������C���s���dd��|�j�D��S�)Nc�����������������S���s���g�|�] }|j��qS�r'���)r8���)�.0�backendr'���r'���r(���� <listcomp>���������z'VcsSupport.dirnames.<locals>.<listcomp>)rq���rS���r'���r'���r(����dirnames����s����zVcsSupport.dirnamesc�����������������C���s ���g�}|�j�D�]}|�|j��q |S�rE���)rq���rl���rm���)rH���rm���rs���r'���r'���r(���r%�������s���� zVcsSupport.all_schemes)�clsr ���c�����������������C���sH���t�|d�st�d|j��d�S�|j|�jvrD|��|�j|j<�t�d|j��d�S�)Nr���zCannot register VCS %szRegistered VCS backend: %s)�hasattrr9���r:���r?���r���re����debug)rH���rw���r'���r'���r(����register����s���� zVcsSupport.registerr���c�����������������C���s���||�j�v�r|�j�|=�d�S�rE���)re����rH���r���r'���r'���r(���� unregister����s���� zVcsSupport.unregister�r4���r ���c�����������������C���sX���i�}|�j����D�],}|�|�}|s"qt�d||j��|||<�q|sDdS�t|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)re���rp����get_repository_rootr9���ry���r����max�len)rH���r4���Zvcs_backends�vcs_backendZ repo_pathZinner_most_repo_pathr'���r'���r(����get_backend_for_dir����s���� zVcsSupport.get_backend_for_dir)r&���r ���c�����������������C���s&���|�j����D�]}||jv�r |��S�q dS�)�9 Return a VersionControl object or None. N)re���rp���rm���)rH���r&���r����r'���r'���r(����get_backend_for_scheme����s���� z!VcsSupport.get_backend_for_schemec�����������������C���s���|����}|�j�|�S�)r����)�lowerre����getr{���r'���r'���r(����get_backend��s����zVcsSupport.get_backend)r?���r@���rA���re���r���rK����__annotations__rm���rG���r���rn���rc���r���rq���rv���r%���r���rz���r|���r ���r����r����r����rL���r'���r'���rI���r(���rd�������s��� rd���c�������������������@���s���e�Zd�ZU�dZdZdZdZeedf�e d<�dZ eedf�e d<�dZee�e d<�e eed�d d ��Ze eee�d�dd ��Ze eed�dd��Ze eeed�dd��Zeeee�d�dd��Zeeed�dd�Ze dPee�ee�ed�dd��Ze eed�dd��Ze eeeeeee�ee�f�f�d �d!d"��Ze eeeee�ef�d#�d$d%��Zeee�ee�ed&�d'd(��Zeeeef�d#�d)d*�Z eeed#�d+d,��Z!e eeed-�d.d/��Z"eeedd0�d1d2�Z#eeedd0�d3d4�Z$eeedd0�d5d6�Z%e eee�ed7�d8d9��Z&eedd:�d;d<�Z'eedd=�d>d?�Z(e eed�d@dA��Z)e eed�dBdC��Z*e dQe+ee�ef�eee�dGee,e-��ee�ee.ee/f��ee0�eeedH�dIdJ��Z1e eedK�dLdM��Z2e eee�d�dNdO��Z3dS�)RrN���rZ���r'���.rm���� unset_environNrU���)� remote_urlr ���c�����������������C���s���|�����|�j��d���S�)z� Return whether the vcs prefix (e.g. "git+") should be added to a repository's remote url when used in a requirement. �:)r����� startswithr���)rw���r����r'���r'���r(����should_add_vcs_url_prefix��s����z(VersionControl.should_add_vcs_url_prefixr}���c�����������������C���s���dS�)z� Return the path to Python project root, relative to the repo root. Return None if the project root is in the repo root. Nr'����rw���r4���r'���r'���r(����get_subdirectory��s����zVersionControl.get_subdirectory)�repo_dirr ���c�����������������C���s ���|���|�S�)zR Return the revision string that should be used in a requirement. )�get_revision)rw���r����r'���r'���r(����get_requirement_revision'��s����z'VersionControl.get_requirement_revision)r����r,���r ���c�����������������C���sL���|���|�}|��|�r$|�j��d|���}|��|�}|��|�}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} �+)r-���)�get_remote_urlr����r���r����r����r3���)rw���r����r,���r*���Zrevisionr-���r2���r'���r'���r(����get_src_requirement.��s���� z"VersionControl.get_src_requirementr^���c�����������������C���s���t��dS�)z� Return the base revision arguments for a vcs command. Args: rev: the name of a revision to install. Cannot be None. N��NotImplementedErrorr\���r'���r'���r(���rW���F��s����z VersionControl.get_base_rev_args)rD����destr ���c�����������������C���s���dS�)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'���)rH���rD���r����r'���r'���r(����is_immutable_rev_checkoutP��s����z(VersionControl.is_immutable_rev_checkout)r+���rP���r ���c�����������������C���s���t�|�||d�S�)z� Return a RevOptions object. Args: rev: the name of a revision to install. extra_args: a list of extra options. r_���)rM���)rw���r+���rP���r'���r'���r(���r`���]��s����zVersionControl.make_rev_options)�repor ���c�����������������C���s&���t�j�|�\}}|�t�jj�p$t|�S�)zs posix absolute paths start with os.path.sep, win32 ones start with drive (like c:\folder) )r6���r7���� splitdriver�����sep�bool)rw���r�����drive�tailr'���r'���r(����_is_local_repositoryj��s����z#VersionControl._is_local_repository)�netlocr&���r ���c�����������������C���s���|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'���)rw���r����r&���r'���r'���r(����get_netloc_and_auths��s����z"VersionControl.get_netloc_and_auth)rD���r ���c����������� ������C���s����t�j�|�\}}}}}d|vr,td�|���|�dd�d�}|��||�\}}d}d|v�rz|�dd�\}}|sztd�|���t�j� ||||df�}|||fS�)z� Parse the repository URL to use, and return the URL, revision, and auth info to use. Returns: (url, rev, (username, password)). r����zvSorry, {!r} is a malformed VCS url. The format is <vcs>+<protocol>://<url>, e.g. svn+http://myrepo/svn/MyApp#egg=MyApp����Nr0���zyThe URL {!r} has an empty revision (after @) which is not supported. Include a revision after @ or remove @ from the URL.rZ���) ri���rj����urlsplit� ValueError�format�splitr�����rsplitr���� urlunsplit) rw���rD���r&���r����r7����query�frag� user_passr+���r'���r'���r(����get_url_rev_and_auth���s(��������z#VersionControl.get_url_rev_and_auth)�username�passwordr ���c�����������������C���s���g�S�)zM Return the RevOptions "extra arguments" to use in obtain(). r'���)r����r����r'���r'���r(���� make_rev_args���s����zVersionControl.make_rev_argsc����������� ������C���sT���|���|j�\}}}|\}}d}|dur.t|�}|��||�}|�j||d�} t|�| fS�)zq Return the URL and RevOptions object to use in obtain(), as a tuple (url, rev_options). Nr_���)r�����secretr���r����r`���r���) rH���rD���Z secret_urlr+���r����r����Zsecret_passwordr����rP����rev_optionsr'���r'���r(����get_url_rev_options���s����z"VersionControl.get_url_rev_optionsc�����������������C���s���t�j�|���d�S�)zi Normalize a URL for comparison by unquoting it and removing any trailing slash. �/)ri���rj����unquote�rstriprC���r'���r'���r(���� normalize_url���s����zVersionControl.normalize_url)�url1�url2r ���c�����������������C���s���|���|�|���|�kS�)zV Compare two repo URLs for identity, ignoring incidental differences. )r����)rw���r����r����r'���r'���r(����compare_urls���s����zVersionControl.compare_urls)r����rD���r����r ���c�����������������C���s���t��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. Nr�����rH���r����rD���r����r'���r'���r(���� fetch_new���s���� zVersionControl.fetch_newc�����������������C���s���t��dS�)z} Switch the repo at ``dest`` to point to ``URL``. Args: rev_options: a RevOptions object. Nr����r����r'���r'���r(����switch���s����zVersionControl.switchc�����������������C���s���t��dS�)z� Update an already-existing repo to the given ``rev_options``. Args: rev_options: a RevOptions object. Nr����r����r'���r'���r(����update���s����zVersionControl.update)r����r���r ���c�����������������C���s���t��dS�)z� Return whether the id of the current commit equals the given name. Args: dest: the repository directory. name: a string name. Nr����)rw���r����r���r'���r'���r(����is_commit_id_equal���s���� z!VersionControl.is_commit_id_equal)r����rD���r ���c����������� ������C���s���|���|�\}}tj�|�s,|��|||��dS�|���}|��|�r�|��|�}|��||j �r�t �d|�j� ��t|�|��|��||j�s�t �dt|�|�j|��|��|||��n t �d��dS�t �d|�j|�jt|�|��d}nt �d||�j|�j��d}t �d |�j|��td �|d��|d��}|d k�r&t�d��|dk�rZt �dt|���t|��|��|||��dS�|dk�r�t|�}t �dt|�|��t�||��|��|||��dS�|dk�r�t �d|�jt|�||��|��|||��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 )�s�i�w�bz0Directory %s already exists, and is not a %s %s.)z(i)gnore, (w)ipe, (b)ackup )r����r����r����z+The plan is to install the %s repository %szWhat to do? {}r���r�����a���r����zDeleting %sr����zBacking up %s to %sr����zSwitching %s %s to %s%s)r����r6���r7����existsr����r]����is_repository_directoryr����r����r����r9���ry���� repo_name�titler���r����r+����infor����r:���r���r���r�����sys�exitr���r����shutil�mover����) rH���r����rD���r����Zrev_displayZexisting_url�promptZresponseZdest_dirr'���r'���r(����obtain���s����� �� ��� �zVersionControl.obtain)r4���rD���r ���c�����������������C���s&���t�j�|�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. rC���N)r6���r7���r����r���r����)rH���r4���rD���r'���r'���r(����unpackM��s����zVersionControl.unpackc�����������������C���s���t��dS�)z� Return the url used at location Raises RemoteNotFoundError if the repository does not have a remote url configured. Nr����r����r'���r'���r(���r����X��s����zVersionControl.get_remote_urlc�����������������C���s���t��dS�)zR Return the current commit id of the files at the given location. Nr����r����r'���r'���r(���r����b��s����zVersionControl.get_revisionT�raiseFz"Literal["raise", "warn", "ignore"])�cmd�show_stdout�cwd� on_returncode�extra_ok_returncodes�command_desc� extra_environ�spinner�log_failed_cmd�stdout_onlyr ���c�������������� ���C���s����t�|�jg|�R���}z"t||||||||�j|| | d�W�S��ty`���td|�j�d|�j�d���Y�n$�ty����td|�j�d���Y�n0�dS�)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 )r����r����r����r����r����r����r����r����zCannot find command z - do you have z installed and in your PATH?zNo permission to execute z� - install it locally, globally (ask admin), or check your PATH. See possible solutions at https://pip.pypa.io/en/latest/reference/pip_freeze/#fixing-permission-denied.N)r���r���r���r�����FileNotFoundErrorr����PermissionError)rw���r����r����r����r����r����r����r����r����r����r����r'���r'���r(����run_commandi��s2����� ���zVersionControl.run_command)r7���r ���c�����������������C���s,���t��d||�j|�j��tj�tj�||�j��S�)zL Return whether a directory path is a repository directory. zChecking in %s for %s (%s)...)r9���ry���r8���r���r6���r7���r�����join)rw���r7���r'���r'���r(���r�������s����z&VersionControl.is_repository_directoryc�����������������C���s���|���|�r|S�dS�)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����r'���r'���r(���r������s���� z"VersionControl.get_repository_root)NN) TNr����NNNNTF)4r?���r@���rA���r���r8���r����rm���r ���rK���r����r����rU���r ����classmethodr����r����r����r����r�����staticmethodr���rW���r����r���rM���r`���r����r�����AuthInfor����r���r����r����r����r����r����r����r����r����r����r����r����r����r���r����intr���r���r ���r����r����r���r'���r'���r'���r(���rN��� ��s���� ���� � X ���������� �5rN���)N)9rb���Zloggingr6���r����r�����urllib.parseri����typingr���r���r���r���r���r���r���r ���r ���r���r���Zpip._internal.cli.spinnersr ���Zpip._internal.exceptionsr���r���Zpip._internal.utils.miscr���r���r���r���r���r���r���r���Zpip._internal.utils.subprocessr���r���r���Zpip._internal.utils.urlsr���r����__all__Z getLoggerr?���r9���rK���r����r����r)���r3���r=���� Exceptionr>���rB���rM���rd���r���rN���r'���r'���r'���r(����<module>���s>���4( ����CP