Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change VCS tooling verbosity along with pip's verbosity #9639

Merged
merged 11 commits into from
Jan 25, 2022
1 change: 1 addition & 0 deletions src/pip/_internal/cli/req_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def make_requirement_preparer(
require_hashes=options.require_hashes,
use_user_site=use_user_site,
lazy_wheel=lazy_wheel,
verbose=options.verbose > 2,
in_tree_build=in_tree_build,
)

Expand Down
14 changes: 10 additions & 4 deletions src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def _get_prepared_distribution(
return abstract_dist.get_metadata_distribution()


def unpack_vcs_link(link: Link, location: str) -> None:
def unpack_vcs_link(link: Link, location: str, verbose: bool) -> None:
vcs_backend = vcs.get_backend_for_scheme(link.scheme)
assert vcs_backend is not None
vcs_backend.unpack(location, url=hide_url(link.url))
vcs_backend.unpack(location, url=hide_url(link.url), verbose=verbose)


class File:
Expand Down Expand Up @@ -175,6 +175,7 @@ def unpack_url(
link: Link,
location: str,
download: Downloader,
verbose: bool,
download_dir: Optional[str] = None,
hashes: Optional[Hashes] = None,
) -> Optional[File]:
Expand All @@ -187,7 +188,7 @@ def unpack_url(
"""
# non-editable vcs urls
if link.is_vcs:
unpack_vcs_link(link, location)
unpack_vcs_link(link, location, verbose=verbose)
return None

# Once out-of-tree-builds are no longer supported, could potentially
Expand Down Expand Up @@ -267,6 +268,7 @@ def __init__(
require_hashes: bool,
use_user_site: bool,
lazy_wheel: bool,
verbose: bool,
in_tree_build: bool,
) -> None:
super().__init__()
Expand Down Expand Up @@ -295,6 +297,9 @@ def __init__(
# Should wheels be downloaded lazily?
self.use_lazy_wheel = lazy_wheel

# Should underlying tooling be verbose, or quiet?
self.verbose = verbose

# Should in-tree builds be used for local paths?
self.in_tree_build = in_tree_build

Expand Down Expand Up @@ -524,7 +529,8 @@ def _prepare_linked_requirement(
elif link.url not in self._downloaded:
try:
local_file = unpack_url(
link, req.source_dir, self._download, self.download_dir, hashes
link, req.source_dir, self._download, self.verbose,
self.download_dir, hashes
)
except NetworkConnectionError as exc:
raise InstallationError(
Expand Down
5 changes: 3 additions & 2 deletions src/pip/_internal/vcs/bazaar.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ 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) -> None:
def fetch_new(self, dest: str, url: HiddenText, rev_options: RevOptions, verbose: bool) -> None:
rev_display = rev_options.to_display()
logger.info(
"Checking out %s%s to %s",
url,
rev_display,
display_path(dest),
)
cmd_args = make_command("branch", "-q", rev_options.to_args(), url, dest)
flags = ('--verbose',) if verbose else ('--quiet',)
uranusjr marked this conversation as resolved.
Show resolved Hide resolved
cmd_args = make_command("branch", *flags, rev_options.to_args(), url, dest)
self.run_command(cmd_args)

def switch(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
Expand Down
7 changes: 4 additions & 3 deletions src/pip/_internal/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,10 @@ def is_commit_id_equal(cls, dest: str, name: Optional[str]) -> bool:

return cls.get_revision(dest) == name

def fetch_new(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
def fetch_new(self, dest: str, url: HiddenText, rev_options: RevOptions, verbose: bool) -> None:
rev_display = rev_options.to_display()
logger.info("Cloning %s%s to %s", url, rev_display, display_path(dest))
flags = ('--verbose', '--progress') if verbose else ('--quiet',)
if self.get_git_version() >= (2, 17):
# Git added support for partial clone in 2.17
# https://git-scm.com/docs/partial-clone
Expand All @@ -264,13 +265,13 @@ def fetch_new(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None
make_command(
"clone",
"--filter=blob:none",
"-q",
*flags,
url,
dest,
)
)
else:
self.run_command(make_command("clone", "-q", url, dest))
self.run_command(make_command("clone", *flags, url, dest))

if rev_options.rev:
# Then a specific revision was requested.
Expand Down
7 changes: 4 additions & 3 deletions src/pip/_internal/vcs/mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@ 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) -> None:
def fetch_new(self, dest: str, url: HiddenText, rev_options: RevOptions, verbose: bool) -> None:
rev_display = rev_options.to_display()
logger.info(
"Cloning hg %s%s to %s",
url,
rev_display,
display_path(dest),
)
self.run_command(make_command("clone", "--noupdate", "-q", url, dest))
flags = ('--verbose', ) if verbose else ('--quiet',)
self.run_command(make_command("clone", "--noupdate", *flags, url, dest))
self.run_command(
make_command("update", "-q", rev_options.to_args()),
make_command("update", *flags, rev_options.to_args()),
cwd=dest,
)

Expand Down
5 changes: 3 additions & 2 deletions src/pip/_internal/vcs/subversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,18 @@ def get_remote_call_options(self) -> CommandArgs:

return []

def fetch_new(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
def fetch_new(self, dest: str, url: HiddenText, rev_options: RevOptions, verbose: bool) -> None:
rev_display = rev_options.to_display()
logger.info(
"Checking out %s%s to %s",
url,
rev_display,
display_path(dest),
)
flags = () if verbose else ('--quiet')
cmd_args = make_command(
"checkout",
"-q",
*flags,
self.get_remote_call_options(),
rev_options.to_args(),
url,
Expand Down
17 changes: 10 additions & 7 deletions src/pip/_internal/vcs/versioncontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,14 +458,15 @@ def compare_urls(cls, url1: str, url2: str) -> bool:
"""
return cls.normalize_url(url1) == cls.normalize_url(url2)

def fetch_new(self, dest: str, url: HiddenText, rev_options: RevOptions) -> None:
def fetch_new(self, dest: str, url: HiddenText, rev_options: RevOptions, verbose: bool) -> None:
"""
Fetch a revision from a repository, in the case that this is the
first fetch from the repository.

Args:
dest: the directory to fetch the repository to.
rev_options: a RevOptions object.
verbose: flag for verbose output.
"""
raise NotImplementedError

Expand Down Expand Up @@ -498,18 +499,19 @@ def is_commit_id_equal(cls, dest: str, name: Optional[str]) -> bool:
"""
raise NotImplementedError

def obtain(self, dest: str, url: HiddenText) -> None:
def obtain(self, dest: str, url: HiddenText, verbose: bool) -> 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 verbose: flag for verbose output.
"""
url, rev_options = self.get_url_rev_options(url)

if not os.path.exists(dest):
self.fetch_new(dest, url, rev_options)
self.fetch_new(dest, url, rev_options, verbose=verbose)
return

rev_display = rev_options.to_display()
Expand Down Expand Up @@ -565,14 +567,14 @@ def obtain(self, dest: str, url: HiddenText) -> None:
if response == "w":
logger.warning("Deleting %s", display_path(dest))
rmtree(dest)
self.fetch_new(dest, url, rev_options)
self.fetch_new(dest, url, rev_options, verbose=verbose)
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)
self.fetch_new(dest, url, rev_options, verbose=verbose)
return

# Do nothing if the response is "i".
Expand All @@ -586,16 +588,17 @@ def obtain(self, dest: str, url: HiddenText) -> None:
)
self.switch(dest, url, rev_options)

def unpack(self, location: str, url: HiddenText) -> None:
def unpack(self, location: str, url: HiddenText, verbose: bool) -> 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 verbose: flag for verbose output.
"""
if os.path.exists(location):
rmtree(location)
self.obtain(location, url=url)
self.obtain(location, url=url, verbose=verbose)

@classmethod
def get_remote_url(cls, location: str) -> str:
Expand Down