This commit is contained in:
ton
2024-10-07 10:13:40 +07:00
parent aa1631742f
commit 3a7d696db6
9729 changed files with 1832837 additions and 161742 deletions

View File

@@ -44,13 +44,13 @@ class Bazaar(VersionControl):
display_path(dest),
)
if verbosity <= 0:
flag = "--quiet"
flags = ["--quiet"]
elif verbosity == 1:
flag = ""
flags = []
else:
flag = f"-{'v'*verbosity}"
flags = [f"-{'v'*verbosity}"]
cmd_args = make_command(
"checkout", "--lightweight", flag, rev_options.to_args(), url, dest
"checkout", "--lightweight", *flags, rev_options.to_args(), url, dest
)
self.run_command(cmd_args)

View File

@@ -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

View File

@@ -31,7 +31,7 @@ class Mercurial(VersionControl):
@staticmethod
def get_base_rev_args(rev: str) -> List[str]:
return ["-r", rev]
return [f"--rev={rev}"]
def fetch_new(
self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int

View File

@@ -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,

View File

@@ -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