bazaar.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import logging
  2. from typing import List, Optional, Tuple
  3. from pip._internal.utils.misc import HiddenText, display_path
  4. from pip._internal.utils.subprocess import make_command
  5. from pip._internal.utils.urls import path_to_url
  6. from pip._internal.vcs.versioncontrol import (
  7. AuthInfo,
  8. RemoteNotFoundError,
  9. RevOptions,
  10. VersionControl,
  11. vcs,
  12. )
  13. logger = logging.getLogger(__name__)
  14. class Bazaar(VersionControl):
  15. name = "bzr"
  16. dirname = ".bzr"
  17. repo_name = "branch"
  18. schemes = (
  19. "bzr+http",
  20. "bzr+https",
  21. "bzr+ssh",
  22. "bzr+sftp",
  23. "bzr+ftp",
  24. "bzr+lp",
  25. "bzr+file",
  26. )
  27. @staticmethod
  28. def get_base_rev_args(rev: str) -> List[str]:
  29. return ["-r", rev]
  30. def fetch_new(
  31. self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int
  32. ) -> None:
  33. rev_display = rev_options.to_display()
  34. logger.info(
  35. "Checking out %s%s to %s",
  36. url,
  37. rev_display,
  38. display_path(dest),
  39. )
  40. if verbosity <= 0:
  41. flag = "--quiet"
  42. elif verbosity == 1:
  43. flag = ""
  44. else:
  45. flag = f"-{'v'*verbosity}"
  46. cmd_args = make_command("branch", flag, rev_options.to_args(), url, dest)
  47. self.run_command(cmd_args)
  48. def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
  49. self.run_command(make_command("switch", url), cwd=dest)
  50. def update(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
  51. cmd_args = make_command("pull", "-q", rev_options.to_args())
  52. self.run_command(cmd_args, cwd=dest)
  53. @classmethod
  54. def get_url_rev_and_auth(cls, url: str) -> Tuple[str, Optional[str], AuthInfo]:
  55. # hotfix the URL scheme after removing bzr+ from bzr+ssh:// readd it
  56. url, rev, user_pass = super().get_url_rev_and_auth(url)
  57. if url.startswith("ssh://"):
  58. url = "bzr+" + url
  59. return url, rev, user_pass
  60. @classmethod
  61. def get_remote_url(cls, location: str) -> str:
  62. urls = cls.run_command(
  63. ["info"], show_stdout=False, stdout_only=True, cwd=location
  64. )
  65. for line in urls.splitlines():
  66. line = line.strip()
  67. for x in ("checkout of branch: ", "parent branch: "):
  68. if line.startswith(x):
  69. repo = line.split(x)[1]
  70. if cls._is_local_repository(repo):
  71. return path_to_url(repo)
  72. return repo
  73. raise RemoteNotFoundError
  74. @classmethod
  75. def get_revision(cls, location: str) -> str:
  76. revision = cls.run_command(
  77. ["revno"],
  78. show_stdout=False,
  79. stdout_only=True,
  80. cwd=location,
  81. )
  82. return revision.splitlines()[-1]
  83. @classmethod
  84. def is_commit_id_equal(cls, dest: str, name: Optional[str]) -> bool:
  85. """Always assume the versions don't match"""
  86. return False
  87. vcs.register(Bazaar)