更改enroll命名,添加了注释,向get_error_msg中添加了一些错误代码
This commit is contained in:
@@ -33,9 +33,7 @@ class Bazaar(VersionControl):
|
||||
def get_base_rev_args(rev: str) -> List[str]:
|
||||
return ["-r", rev]
|
||||
|
||||
def fetch_new(
|
||||
self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int
|
||||
) -> None:
|
||||
def fetch_new(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
||||
rev_display = rev_options.to_display()
|
||||
logger.info(
|
||||
"Checking out %s%s to %s",
|
||||
@@ -43,13 +41,7 @@ class Bazaar(VersionControl):
|
||||
rev_display,
|
||||
display_path(dest),
|
||||
)
|
||||
if verbosity <= 0:
|
||||
flag = "--quiet"
|
||||
elif verbosity == 1:
|
||||
flag = ""
|
||||
else:
|
||||
flag = f"-{'v'*verbosity}"
|
||||
cmd_args = make_command("branch", flag, rev_options.to_args(), url, dest)
|
||||
cmd_args = make_command("branch", "-q", rev_options.to_args(), url, dest)
|
||||
self.run_command(cmd_args)
|
||||
|
||||
def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
||||
|
||||
@@ -91,12 +91,7 @@ class Git(VersionControl):
|
||||
return not is_tag_or_branch
|
||||
|
||||
def get_git_version(self) -> Tuple[int, ...]:
|
||||
version = self.run_command(
|
||||
["version"],
|
||||
command_desc="git version",
|
||||
show_stdout=False,
|
||||
stdout_only=True,
|
||||
)
|
||||
version = self.run_command(["version"], show_stdout=False, stdout_only=True)
|
||||
match = GIT_VERSION_REGEX.match(version)
|
||||
if not match:
|
||||
logger.warning("Can't parse git version: %s", version)
|
||||
@@ -258,17 +253,9 @@ class Git(VersionControl):
|
||||
|
||||
return cls.get_revision(dest) == name
|
||||
|
||||
def fetch_new(
|
||||
self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int
|
||||
) -> None:
|
||||
def fetch_new(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
||||
rev_display = rev_options.to_display()
|
||||
logger.info("Cloning %s%s to %s", url, rev_display, display_path(dest))
|
||||
if verbosity <= 0:
|
||||
flags: Tuple[str, ...] = ("--quiet",)
|
||||
elif verbosity == 1:
|
||||
flags = ()
|
||||
else:
|
||||
flags = ("--verbose", "--progress")
|
||||
if self.get_git_version() >= (2, 17):
|
||||
# Git added support for partial clone in 2.17
|
||||
# https://git-scm.com/docs/partial-clone
|
||||
@@ -277,13 +264,13 @@ class Git(VersionControl):
|
||||
make_command(
|
||||
"clone",
|
||||
"--filter=blob:none",
|
||||
*flags,
|
||||
"-q",
|
||||
url,
|
||||
dest,
|
||||
)
|
||||
)
|
||||
else:
|
||||
self.run_command(make_command("clone", *flags, url, dest))
|
||||
self.run_command(make_command("clone", "-q", url, dest))
|
||||
|
||||
if rev_options.rev:
|
||||
# Then a specific revision was requested.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import configparser
|
||||
import logging
|
||||
import os
|
||||
from typing import List, Optional, Tuple
|
||||
from typing import List, Optional
|
||||
|
||||
from pip._internal.exceptions import BadCommand, InstallationError
|
||||
from pip._internal.utils.misc import HiddenText, display_path
|
||||
@@ -33,9 +33,7 @@ class Mercurial(VersionControl):
|
||||
def get_base_rev_args(rev: str) -> List[str]:
|
||||
return [rev]
|
||||
|
||||
def fetch_new(
|
||||
self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int
|
||||
) -> None:
|
||||
def fetch_new(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
||||
rev_display = rev_options.to_display()
|
||||
logger.info(
|
||||
"Cloning hg %s%s to %s",
|
||||
@@ -43,17 +41,9 @@ class Mercurial(VersionControl):
|
||||
rev_display,
|
||||
display_path(dest),
|
||||
)
|
||||
if verbosity <= 0:
|
||||
flags: Tuple[str, ...] = ("--quiet",)
|
||||
elif verbosity == 1:
|
||||
flags = ()
|
||||
elif verbosity == 2:
|
||||
flags = ("--verbose",)
|
||||
else:
|
||||
flags = ("--verbose", "--debug")
|
||||
self.run_command(make_command("clone", "--noupdate", *flags, url, dest))
|
||||
self.run_command(make_command("clone", "--noupdate", "-q", url, dest))
|
||||
self.run_command(
|
||||
make_command("update", *flags, rev_options.to_args()),
|
||||
make_command("update", "-q", rev_options.to_args()),
|
||||
cwd=dest,
|
||||
)
|
||||
|
||||
|
||||
@@ -277,9 +277,7 @@ class Subversion(VersionControl):
|
||||
|
||||
return []
|
||||
|
||||
def fetch_new(
|
||||
self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int
|
||||
) -> None:
|
||||
def fetch_new(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
||||
rev_display = rev_options.to_display()
|
||||
logger.info(
|
||||
"Checking out %s%s to %s",
|
||||
@@ -287,13 +285,9 @@ class Subversion(VersionControl):
|
||||
rev_display,
|
||||
display_path(dest),
|
||||
)
|
||||
if verbosity <= 0:
|
||||
flag = "--quiet"
|
||||
else:
|
||||
flag = ""
|
||||
cmd_args = make_command(
|
||||
"checkout",
|
||||
flag,
|
||||
"-q",
|
||||
self.get_remote_call_options(),
|
||||
rev_options.to_args(),
|
||||
url,
|
||||
|
||||
@@ -31,12 +31,7 @@ from pip._internal.utils.misc import (
|
||||
is_installable_dir,
|
||||
rmtree,
|
||||
)
|
||||
from pip._internal.utils.subprocess import (
|
||||
CommandArgs,
|
||||
call_subprocess,
|
||||
format_command_args,
|
||||
make_command,
|
||||
)
|
||||
from pip._internal.utils.subprocess import CommandArgs, call_subprocess, make_command
|
||||
from pip._internal.utils.urls import get_url_scheme
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -463,9 +458,7 @@ class VersionControl:
|
||||
"""
|
||||
return cls.normalize_url(url1) == cls.normalize_url(url2)
|
||||
|
||||
def fetch_new(
|
||||
self, dest: str, url: HiddenText, rev_options: RevOptions, verbosity: int
|
||||
) -> None:
|
||||
def fetch_new(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
|
||||
"""
|
||||
Fetch a revision from a repository, in the case that this is the
|
||||
first fetch from the repository.
|
||||
@@ -473,7 +466,6 @@ class VersionControl:
|
||||
Args:
|
||||
dest: the directory to fetch the repository to.
|
||||
rev_options: a RevOptions object.
|
||||
verbosity: verbosity level.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -506,19 +498,18 @@ class VersionControl:
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def obtain(self, dest: str, url: HiddenText, verbosity: int) -> None:
|
||||
def obtain(self, dest: str, url: HiddenText) -> None:
|
||||
"""
|
||||
Install or update in editable mode the package represented by this
|
||||
VersionControl object.
|
||||
|
||||
:param dest: the repository directory in which to install or update.
|
||||
:param url: the repository URL starting with a vcs prefix.
|
||||
:param verbosity: verbosity level.
|
||||
"""
|
||||
url, rev_options = self.get_url_rev_options(url)
|
||||
|
||||
if not os.path.exists(dest):
|
||||
self.fetch_new(dest, url, rev_options, verbosity=verbosity)
|
||||
self.fetch_new(dest, url, rev_options)
|
||||
return
|
||||
|
||||
rev_display = rev_options.to_display()
|
||||
@@ -574,14 +565,14 @@ class VersionControl:
|
||||
if response == "w":
|
||||
logger.warning("Deleting %s", display_path(dest))
|
||||
rmtree(dest)
|
||||
self.fetch_new(dest, url, rev_options, verbosity=verbosity)
|
||||
self.fetch_new(dest, url, rev_options)
|
||||
return
|
||||
|
||||
if response == "b":
|
||||
dest_dir = backup_dir(dest)
|
||||
logger.warning("Backing up %s to %s", display_path(dest), dest_dir)
|
||||
shutil.move(dest, dest_dir)
|
||||
self.fetch_new(dest, url, rev_options, verbosity=verbosity)
|
||||
self.fetch_new(dest, url, rev_options)
|
||||
return
|
||||
|
||||
# Do nothing if the response is "i".
|
||||
@@ -595,17 +586,16 @@ class VersionControl:
|
||||
)
|
||||
self.switch(dest, url, rev_options)
|
||||
|
||||
def unpack(self, location: str, url: HiddenText, verbosity: int) -> None:
|
||||
def unpack(self, location: str, url: HiddenText) -> None:
|
||||
"""
|
||||
Clean up current location and download the url repository
|
||||
(and vcs infos) into location
|
||||
|
||||
:param url: the repository URL starting with a vcs prefix.
|
||||
:param verbosity: verbosity level.
|
||||
"""
|
||||
if os.path.exists(location):
|
||||
rmtree(location)
|
||||
self.obtain(location, url=url, verbosity=verbosity)
|
||||
self.obtain(location, url=url)
|
||||
|
||||
@classmethod
|
||||
def get_remote_url(cls, location: str) -> str:
|
||||
@@ -644,8 +634,6 @@ class VersionControl:
|
||||
command name, and checks that the VCS is available
|
||||
"""
|
||||
cmd = make_command(cls.name, *cmd)
|
||||
if command_desc is None:
|
||||
command_desc = format_command_args(cmd)
|
||||
try:
|
||||
return call_subprocess(
|
||||
cmd,
|
||||
|
||||
Reference in New Issue
Block a user