Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/pip/_internal/vcs/bazaar.py @ 0:9e54283cc701 draft
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
| author | guerler |
|---|---|
| date | Mon, 27 Jul 2020 03:47:31 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:9e54283cc701 |
|---|---|
| 1 # The following comment should be removed at some point in the future. | |
| 2 # mypy: disallow-untyped-defs=False | |
| 3 | |
| 4 from __future__ import absolute_import | |
| 5 | |
| 6 import logging | |
| 7 import os | |
| 8 | |
| 9 from pip._vendor.six.moves.urllib import parse as urllib_parse | |
| 10 | |
| 11 from pip._internal.utils.misc import display_path, rmtree | |
| 12 from pip._internal.utils.subprocess import make_command | |
| 13 from pip._internal.utils.typing import MYPY_CHECK_RUNNING | |
| 14 from pip._internal.utils.urls import path_to_url | |
| 15 from pip._internal.vcs.versioncontrol import VersionControl, vcs | |
| 16 | |
| 17 if MYPY_CHECK_RUNNING: | |
| 18 from typing import Optional, Tuple | |
| 19 from pip._internal.utils.misc import HiddenText | |
| 20 from pip._internal.vcs.versioncontrol import AuthInfo, RevOptions | |
| 21 | |
| 22 | |
| 23 logger = logging.getLogger(__name__) | |
| 24 | |
| 25 | |
| 26 class Bazaar(VersionControl): | |
| 27 name = 'bzr' | |
| 28 dirname = '.bzr' | |
| 29 repo_name = 'branch' | |
| 30 schemes = ( | |
| 31 'bzr', 'bzr+http', 'bzr+https', 'bzr+ssh', 'bzr+sftp', 'bzr+ftp', | |
| 32 'bzr+lp', | |
| 33 ) | |
| 34 | |
| 35 def __init__(self, *args, **kwargs): | |
| 36 super(Bazaar, self).__init__(*args, **kwargs) | |
| 37 # This is only needed for python <2.7.5 | |
| 38 # Register lp but do not expose as a scheme to support bzr+lp. | |
| 39 if getattr(urllib_parse, 'uses_fragment', None): | |
| 40 urllib_parse.uses_fragment.extend(['lp']) | |
| 41 | |
| 42 @staticmethod | |
| 43 def get_base_rev_args(rev): | |
| 44 return ['-r', rev] | |
| 45 | |
| 46 def export(self, location, url): | |
| 47 # type: (str, HiddenText) -> None | |
| 48 """ | |
| 49 Export the Bazaar repository at the url to the destination location | |
| 50 """ | |
| 51 # Remove the location to make sure Bazaar can export it correctly | |
| 52 if os.path.exists(location): | |
| 53 rmtree(location) | |
| 54 | |
| 55 url, rev_options = self.get_url_rev_options(url) | |
| 56 self.run_command( | |
| 57 make_command('export', location, url, rev_options.to_args()), | |
| 58 show_stdout=False, | |
| 59 ) | |
| 60 | |
| 61 def fetch_new(self, dest, url, rev_options): | |
| 62 # type: (str, HiddenText, RevOptions) -> None | |
| 63 rev_display = rev_options.to_display() | |
| 64 logger.info( | |
| 65 'Checking out %s%s to %s', | |
| 66 url, | |
| 67 rev_display, | |
| 68 display_path(dest), | |
| 69 ) | |
| 70 cmd_args = ( | |
| 71 make_command('branch', '-q', rev_options.to_args(), url, dest) | |
| 72 ) | |
| 73 self.run_command(cmd_args) | |
| 74 | |
| 75 def switch(self, dest, url, rev_options): | |
| 76 # type: (str, HiddenText, RevOptions) -> None | |
| 77 self.run_command(make_command('switch', url), cwd=dest) | |
| 78 | |
| 79 def update(self, dest, url, rev_options): | |
| 80 # type: (str, HiddenText, RevOptions) -> None | |
| 81 cmd_args = make_command('pull', '-q', rev_options.to_args()) | |
| 82 self.run_command(cmd_args, cwd=dest) | |
| 83 | |
| 84 @classmethod | |
| 85 def get_url_rev_and_auth(cls, url): | |
| 86 # type: (str) -> Tuple[str, Optional[str], AuthInfo] | |
| 87 # hotfix the URL scheme after removing bzr+ from bzr+ssh:// readd it | |
| 88 url, rev, user_pass = super(Bazaar, cls).get_url_rev_and_auth(url) | |
| 89 if url.startswith('ssh://'): | |
| 90 url = 'bzr+' + url | |
| 91 return url, rev, user_pass | |
| 92 | |
| 93 @classmethod | |
| 94 def get_remote_url(cls, location): | |
| 95 urls = cls.run_command(['info'], show_stdout=False, cwd=location) | |
| 96 for line in urls.splitlines(): | |
| 97 line = line.strip() | |
| 98 for x in ('checkout of branch: ', | |
| 99 'parent branch: '): | |
| 100 if line.startswith(x): | |
| 101 repo = line.split(x)[1] | |
| 102 if cls._is_local_repository(repo): | |
| 103 return path_to_url(repo) | |
| 104 return repo | |
| 105 return None | |
| 106 | |
| 107 @classmethod | |
| 108 def get_revision(cls, location): | |
| 109 revision = cls.run_command( | |
| 110 ['revno'], show_stdout=False, cwd=location, | |
| 111 ) | |
| 112 return revision.splitlines()[-1] | |
| 113 | |
| 114 @classmethod | |
| 115 def is_commit_id_equal(cls, dest, name): | |
| 116 """Always assume the versions don't match""" | |
| 117 return False | |
| 118 | |
| 119 | |
| 120 vcs.register(Bazaar) |
