update
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user