You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bazaar.py 3.8KB

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