comparison env/lib/python3.9/site-packages/pip/_internal/vcs/bazaar.py @ 0:4f3585e2f14b draft default tip

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