Воркед

This commit is contained in:
kromskii2 committed 2025-03-15 09:36:28 +07:00
1 parent ac32c55ab9
commit ee94d8e529
1138 files changed
+55771 -77901

No files matched your search

@@ -44,24 +44,35 @@ class Bazaar(VersionControl):
display_path(dest),
)
if verbosity <= 0:
flag = "--quiet"
flags = ["--quiet"]
elif verbosity == 1:
flag = ""
flags = []
else:
flag = f"-{'v'*verbosity}"
cmd_args = make_command("branch", flag, rev_options.to_args(), url, dest)
flags = [f"-{'v'*verbosity}"]
cmd_args = make_command(
"checkout", "--lightweight", *flags, rev_options.to_args(), url, dest
)
self.run_command(cmd_args)
def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
self.run_command(make_command("switch", url), cwd=dest)
def update(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
cmd_args = make_command("pull", "-q", rev_options.to_args())
output = self.run_command(
make_command("info"), show_stdout=False, stdout_only=True, cwd=dest
)
if output.startswith("Standalone "):
# Older versions of pip used to create standalone branches.
# Convert the standalone branch to a checkout by calling "bzr bind".
cmd_args = make_command("bind", "-q", url)
self.run_command(cmd_args, cwd=dest)
cmd_args = make_command("update", "-q", rev_options.to_args())
self.run_command(cmd_args, cwd=dest)
@classmethod
def get_url_rev_and_auth(cls, url: str) -> Tuple[str, Optional[str], AuthInfo]:
# hotfix the URL scheme after removing bzr+ from bzr+ssh:// readd it
# hotfix the URL scheme after removing bzr+ from bzr+ssh:// re-add it
url, rev, user_pass = super().get_url_rev_and_auth(url)
if url.startswith("ssh://"):
url = "bzr+" + url
@@ -4,6 +4,7 @@ import pathlib
import re
import urllib.parse
import urllib.request
from dataclasses import replace
from typing import List, Optional, Tuple
from pip._internal.exceptions import BadCommand, InstallationError
@@ -101,7 +102,7 @@ class Git(VersionControl):
if not match:
logger.warning("Can't parse git version: %s", version)
return ()
return tuple(int(c) for c in match.groups())
return (int(match.group(1)), int(match.group(2)))
@classmethod
def get_current_branch(cls, location: str) -> Optional[str]:
@@ -217,7 +218,7 @@ class Git(VersionControl):
if sha is not None:
rev_options = rev_options.make_new(sha)
rev_options.branch_name = rev if is_branch else None
rev_options = replace(rev_options, branch_name=(rev if is_branch else None))
return rev_options
@@ -31,7 +31,7 @@ class Mercurial(VersionControl):
@staticmethod
def get_base_rev_args(rev: str) -> List[str]:
return [rev]
return [f"--rev={rev}"]
def fetch_new(
self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int
@@ -87,7 +87,7 @@ class Subversion(VersionControl):
@classmethod
def get_url_rev_and_auth(cls, url: str) -> Tuple[str, Optional[str], AuthInfo]:
# hotfix the URL scheme after removing svn+ from svn+ssh:// readd it
# hotfix the URL scheme after removing svn+ from svn+ssh:// re-add it
url, rev, user_pass = super().get_url_rev_and_auth(url)
if url.startswith("ssh://"):
url = "svn+" + url
@@ -184,7 +184,7 @@ class Subversion(VersionControl):
"""Always assume the versions don't match"""
return False
def __init__(self, use_interactive: bool = None) -> None:
def __init__(self, use_interactive: Optional[bool] = None) -> None:
if use_interactive is None:
use_interactive = is_console_interactive()
self.use_interactive = use_interactive
@@ -288,12 +288,12 @@ class Subversion(VersionControl):
display_path(dest),
)
if verbosity <= 0:
flag = "--quiet"
flags = ["--quiet"]
else:
flag = ""
flags = []
cmd_args = make_command(
"checkout",
flag,
*flags,
self.get_remote_call_options(),
rev_options.to_args(),
url,
@@ -5,13 +5,14 @@ import os
import shutil
import sys
import urllib.parse
from dataclasses import dataclass, field
from typing import (
TYPE_CHECKING,
Any,
Dict,
Iterable,
Iterator,
List,
Literal,
Mapping,
Optional,
Tuple,
@@ -37,14 +38,6 @@ from pip._internal.utils.subprocess import (
format_command_args,
make_command,
)
from pip._internal.utils.urls import get_url_scheme
if TYPE_CHECKING:
# Literal was introduced in Python 3.8.
#
# TODO: Remove `if TYPE_CHECKING` when dropping support for Python 3.7.
from typing import Literal
__all__ = ["vcs"]
@@ -58,8 +51,8 @@ def is_url(name: str) -> bool:
"""
Return true if the name looks like a URL.
"""
scheme = get_url_scheme(name)
if scheme is None:
scheme = urllib.parse.urlsplit(name).scheme
if not scheme:
return False
return scheme in ["http", "https", "file", "ftp"] + vcs.all_schemes
@@ -121,34 +114,22 @@ class RemoteNotValidError(Exception):
self.url = url
@dataclass(frozen=True)
class RevOptions:
"""
Encapsulates a VCS-specific revision to install, along with any VCS
install options.
Instances of this class should be treated as if immutable.
Args:
vc_class: a VersionControl subclass.
rev: the name of the revision to install.
extra_args: a list of extra options.
"""
def __init__(
self,
vc_class: Type["VersionControl"],
rev: Optional[str] = None,
extra_args: Optional[CommandArgs] = None,
) -> None:
"""
Args:
vc_class: a VersionControl subclass.
rev: the name of the revision to install.
extra_args: a list of extra options.
"""
if extra_args is None:
extra_args = []
self.extra_args = extra_args
self.rev = rev
self.vc_class = vc_class
self.branch_name: Optional[str] = None
vc_class: Type["VersionControl"]
rev: Optional[str] = None
extra_args: CommandArgs = field(default_factory=list)
branch_name: Optional[str] = None
def __repr__(self) -> str:
return f"<RevOptions {self.vc_class.name}: rev={self.rev!r}>"
@@ -362,7 +343,7 @@ class VersionControl:
rev: the name of a revision to install.
extra_args: a list of extra options.
"""
return RevOptions(cls, rev, extra_args=extra_args)
return RevOptions(cls, rev, extra_args=extra_args or [])
@classmethod
def _is_local_repository(cls, repo: str) -> bool:
@@ -405,9 +386,9 @@ class VersionControl:
scheme, netloc, path, query, frag = urllib.parse.urlsplit(url)
if "+" not in scheme:
raise ValueError(
"Sorry, {!r} is a malformed VCS url. "
f"Sorry, {url!r} is a malformed VCS url. "
"The format is <vcs>+<protocol>://<url>, "
"e.g. svn+http://myrepo/svn/MyApp#egg=MyApp".format(url)
"e.g. svn+http://myrepo/svn/MyApp#egg=MyApp"
)
# Remove the vcs prefix.
scheme = scheme.split("+", 1)[1]
@@ -417,9 +398,9 @@ class VersionControl:
path, rev = path.rsplit("@", 1)
if not rev:
raise InstallationError(
"The URL {!r} has an empty revision (after @) "
f"The URL {url!r} has an empty revision (after @) "
"which is not supported. Include a revision after @ "
"or remove @ from the URL.".format(url)
"or remove @ from the URL."
)
url = urllib.parse.urlunsplit((scheme, netloc, path, query, ""))
return url, rev, user_pass
@@ -566,7 +547,7 @@ class VersionControl:
self.name,
url,
)
response = ask_path_exists("What to do? {}".format(prompt[0]), prompt[1])
response = ask_path_exists(f"What to do? {prompt[0]}", prompt[1])
if response == "a":
sys.exit(-1)
@@ -660,6 +641,8 @@ class VersionControl:
log_failed_cmd=log_failed_cmd,
stdout_only=stdout_only,
)
except NotADirectoryError:
raise BadCommand(f"Cannot find command {cls.name!r} - invalid PATH")
except FileNotFoundError:
# errno.ENOENT = no such file or directory
# In other words, the VCS executable isn't available