comparison planemo/lib/python3.7/site-packages/pip/_internal/vcs/bazaar.py @ 1:56ad4e20f292 draft

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