]> jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/pip/_internal/vcs/bazaar.py
init: venv aand flask
[dlqueue.git] / venv / lib / python3.11 / site-packages / pip / _internal / vcs / bazaar.py
1 import logging
2 from typing import List, Optional, Tuple
3
4 from pip._internal.utils.misc import HiddenText, display_path
5 from pip._internal.utils.subprocess import make_command
6 from pip._internal.utils.urls import path_to_url
7 from pip._internal.vcs.versioncontrol import (
8 AuthInfo,
9 RemoteNotFoundError,
10 RevOptions,
11 VersionControl,
12 vcs,
13 )
14
15 logger = logging.getLogger(__name__)
16
17
18 class Bazaar(VersionControl):
19 name = "bzr"
20 dirname = ".bzr"
21 repo_name = "branch"
22 schemes = (
23 "bzr+http",
24 "bzr+https",
25 "bzr+ssh",
26 "bzr+sftp",
27 "bzr+ftp",
28 "bzr+lp",
29 "bzr+file",
30 )
31
32 @staticmethod
33 def get_base_rev_args(rev: str) -> List[str]:
34 return ["-r", rev]
35
36 def fetch_new(
37 self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int
38 ) -> None:
39 rev_display = rev_options.to_display()
40 logger.info(
41 "Checking out %s%s to %s",
42 url,
43 rev_display,
44 display_path(dest),
45 )
46 if verbosity <= 0:
47 flag = "--quiet"
48 elif verbosity == 1:
49 flag = ""
50 else:
51 flag = f"-{'v'*verbosity}"
52 cmd_args = make_command(
53 "checkout", "--lightweight", flag, rev_options.to_args(), url, dest
54 )
55 self.run_command(cmd_args)
56
57 def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
58 self.run_command(make_command("switch", url), cwd=dest)
59
60 def update(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
61 output = self.run_command(
62 make_command("info"), show_stdout=False, stdout_only=True, cwd=dest
63 )
64 if output.startswith("Standalone "):
65 # Older versions of pip used to create standalone branches.
66 # Convert the standalone branch to a checkout by calling "bzr bind".
67 cmd_args = make_command("bind", "-q", url)
68 self.run_command(cmd_args, cwd=dest)
69
70 cmd_args = make_command("update", "-q", rev_options.to_args())
71 self.run_command(cmd_args, cwd=dest)
72
73 @classmethod
74 def get_url_rev_and_auth(cls, url: str) -> Tuple[str, Optional[str], AuthInfo]:
75 # hotfix the URL scheme after removing bzr+ from bzr+ssh:// re-add it
76 url, rev, user_pass = super().get_url_rev_and_auth(url)
77 if url.startswith("ssh://"):
78 url = "bzr+" + url
79 return url, rev, user_pass
80
81 @classmethod
82 def get_remote_url(cls, location: str) -> str:
83 urls = cls.run_command(
84 ["info"], show_stdout=False, stdout_only=True, cwd=location
85 )
86 for line in urls.splitlines():
87 line = line.strip()
88 for x in ("checkout of branch: ", "parent branch: "):
89 if line.startswith(x):
90 repo = line.split(x)[1]
91 if cls._is_local_repository(repo):
92 return path_to_url(repo)
93 return repo
94 raise RemoteNotFoundError
95
96 @classmethod
97 def get_revision(cls, location: str) -> str:
98 revision = cls.run_command(
99 ["revno"],
100 show_stdout=False,
101 stdout_only=True,
102 cwd=location,
103 )
104 return revision.splitlines()[-1]
105
106 @classmethod
107 def is_commit_id_equal(cls, dest: str, name: Optional[str]) -> bool:
108 """Always assume the versions don't match"""
109 return False
110
111
112 vcs.register(Bazaar)