Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/13018.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Preserve primary output from display commands when ``--quiet`` is used.
14 changes: 7 additions & 7 deletions src/pip/_internal/commands/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pip._internal.exceptions import CommandError, PipError
from pip._internal.utils import filesystem
from pip._internal.utils.logging import getLogger
from pip._internal.utils.misc import format_size
from pip._internal.utils.misc import format_size, write_output

logger = getLogger(__name__)

Expand Down Expand Up @@ -88,7 +88,7 @@ def get_cache_dir(self, options: Values, args: list[str]) -> None:
if args:
raise CommandError("Too many arguments")

logger.info(options.cache_dir)
write_output(options.cache_dir, show_on_quiet=True)

def get_cache_info(self, options: Values, args: list[str]) -> None:
if args:
Expand Down Expand Up @@ -128,7 +128,7 @@ def get_cache_info(self, options: Values, args: list[str]) -> None:
.strip()
)

logger.info(message)
write_output(message, show_on_quiet=True)

def list_cache_items(self, options: Values, args: list[str]) -> None:
if len(args) > 1:
Expand All @@ -147,20 +147,20 @@ def list_cache_items(self, options: Values, args: list[str]) -> None:

def format_for_human(self, files: list[str]) -> None:
if not files:
logger.info("No locally built wheels cached.")
write_output("No locally built wheels cached.", show_on_quiet=True)
return

results = []
for filename in files:
wheel = os.path.basename(filename)
size = filesystem.format_file_size(filename)
results.append(f" - {wheel} ({size})")
logger.info("Cache contents:\n")
logger.info("\n".join(sorted(results)))
write_output("Cache contents:\n", show_on_quiet=True)
write_output("\n".join(sorted(results)), show_on_quiet=True)

def format_for_abspath(self, files: list[str]) -> None:
if files:
logger.info("\n".join(sorted(files)))
write_output("\n".join(sorted(files)), show_on_quiet=True)

def remove_cache_items(self, options: Values, args: list[str]) -> None:
if len(args) > 1:
Expand Down
5 changes: 4 additions & 1 deletion src/pip/_internal/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def run(self, options: Values, args: list[str]) -> int:
project_name,
version,
dependency[0],
show_on_quiet=True,
)

for project_name in conflicting:
Expand All @@ -52,15 +53,17 @@ def run(self, options: Values, args: list[str]) -> int:
req,
dep_name,
dep_version,
show_on_quiet=True,
)
for package in unsupported:
write_output(
"%s %s is not supported on this platform",
package.raw_name,
package.version,
show_on_quiet=True,
)
if missing or conflicting or parsing_probs or unsupported:
return ERROR
else:
write_output("No broken requirements found.")
write_output("No broken requirements found.", show_on_quiet=True)
return SUCCESS
16 changes: 9 additions & 7 deletions src/pip/_internal/commands/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ def list_values(self, options: Values, args: list[str]) -> None:

for key, value in sorted(self.configuration.items()):
for key, value in sorted(value.items()):
write_output("%s=%r", key, value)
write_output("%s=%r", key, value, show_on_quiet=True)

def get_name(self, options: Values, args: list[str]) -> None:
key = self._get_n_args(args, "get [name]", n=1)
value = self.configuration.get_value(key)

write_output("%s", value)
write_output("%s", value, show_on_quiet=True)

def set_name_value(self, options: Values, args: list[str]) -> None:
key, value = self._get_n_args(args, "set [name] [value]", n=2)
Expand All @@ -207,11 +207,13 @@ def list_config_values(self, options: Values, args: list[str]) -> None:
# Iterate over config files and print if they exist, and the
# key-value pairs present in them if they do
for variant, files in sorted(self.configuration.iter_config_files()):
write_output("%s:", variant)
write_output("%s:", variant, show_on_quiet=True)
for fname in files:
with indent_log():
file_exists = os.path.exists(fname)
write_output("%s, exists: %r", fname, file_exists)
write_output(
"%s, exists: %r", fname, file_exists, show_on_quiet=True
)
if file_exists:
self.print_config_file_values(variant, fname)

Expand All @@ -221,15 +223,15 @@ def print_config_file_values(self, variant: Kind, fname: str) -> None:
with indent_log():
if name == fname:
for confname, confvalue in value.items():
write_output("%s: %s", confname, confvalue)
write_output("%s: %s", confname, confvalue, show_on_quiet=True)

def print_env_var_values(self) -> None:
"""Get key-values pairs present as environment variables"""
write_output("%s:", "env_var")
write_output("%s:", "env_var", show_on_quiet=True)
with indent_log():
for key, value in sorted(self.configuration.get_environ_vars()):
env_var = f"PIP_{key.upper()}"
write_output("%s=%r", env_var, value)
write_output("%s=%r", env_var, value, show_on_quiet=True)

def open_in_editor(self, options: Values, args: list[str]) -> None:
editor = self._determine_editor(options)
Expand Down
18 changes: 10 additions & 8 deletions src/pip/_internal/commands/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
from pip._internal.metadata import get_environment
from pip._internal.utils.compat import get_locale_encoding, open_text_resource
from pip._internal.utils.logging import indent_log
from pip._internal.utils.misc import get_pip_version
from pip._internal.utils.misc import get_pip_version, write_output

logger = logging.getLogger(__name__)


def show_value(name: str, value: Any) -> None:
logger.info("%s: %s", name, value)
write_output("%s: %s", name, value, show_on_quiet=True)


def show_sys_implementation() -> None:
logger.info("sys.implementation:")
write_output("sys.implementation:", show_on_quiet=True)
implementation_name = sys.implementation.name
with indent_log():
show_value("name", implementation_name)
Expand Down Expand Up @@ -91,11 +91,13 @@ def show_actual_vendor_versions(vendor_txt_versions: dict[str, str]) -> None:
" (CONFLICT: vendor.txt suggests version should"
f" be {expected_version})"
)
logger.info("%s==%s%s", module_name, actual_version, extra_message)
write_output(
"%s==%s%s", module_name, actual_version, extra_message, show_on_quiet=True
)


def show_vendor_versions() -> None:
logger.info("vendored library versions:")
write_output("vendored library versions:", show_on_quiet=True)

vendor_txt_versions = create_vendor_txt_map()
with indent_log():
Expand All @@ -115,7 +117,7 @@ def show_tags(options: Values) -> None:
suffix = f" (target: {formatted_target})"

msg = f"Compatible tags: {len(tags)}{suffix}"
logger.info(msg)
write_output(msg, show_on_quiet=True)

if options.verbose < 1 and len(tags) > tag_limit:
tags_limited = True
Expand All @@ -125,11 +127,11 @@ def show_tags(options: Values) -> None:

with indent_log():
for tag in tags:
logger.info(str(tag))
write_output(str(tag), show_on_quiet=True)

if tags_limited:
msg = f"...\n[First {tag_limit} tags shown. Pass --verbose to show all.]"
logger.info(msg)
write_output(msg, show_on_quiet=True)


def ca_bundle_info(config: Configuration) -> str:
Expand Down
6 changes: 5 additions & 1 deletion src/pip/_internal/commands/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def run(self, options: Values, args: list[str]) -> int:
algorithm = options.algorithm
for path in args:
write_output(
"%s:\n--hash=%s:%s", path, algorithm, _hash_of_file(path, algorithm)
"%s:\n--hash=%s:%s",
path,
algorithm,
_hash_of_file(path, algorithm),
show_on_quiet=True,
)
return SUCCESS

Expand Down
6 changes: 5 additions & 1 deletion src/pip/_internal/commands/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ def run(self, options: Values, args: list[str]) -> int:
)

try:
# 'pip help' with no args is handled by pip.__init__.parseopt()
cmd_name = args[0] # the command we need help for
except IndexError:
# 'pip help' with no args is handled by parse_command(), but
# command-level options like 'pip help --quiet' reach this point.
from pip._internal.cli.main_parser import create_main_parser

create_main_parser().print_help()
return SUCCESS

if cmd_name not in commands_dict:
Expand Down
11 changes: 7 additions & 4 deletions src/pip/_internal/commands/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,12 @@ def get_available_package_versions(self, options: Values, args: list[Any]) -> No
if dist is not None:
structured_output["installed_version"] = str(dist.version)

write_output(json.dumps(structured_output))
write_output(json.dumps(structured_output), show_on_quiet=True)

else:
write_output(f"{query} ({latest})")
write_output("Available versions: {}".format(", ".join(formatted_versions)))
print_dist_installation_info(latest, dist)
write_output(f"{query} ({latest})", show_on_quiet=True)
write_output(
"Available versions: {}".format(", ".join(formatted_versions)),
show_on_quiet=True,
)
print_dist_installation_info(latest, dist, show_on_quiet=True)
10 changes: 6 additions & 4 deletions src/pip/_internal/commands/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,13 @@ def output_package_listing(
except InvalidVersion:
req_string = f"{dist.raw_name}==={dist.raw_version}"
if options.verbose >= 1:
write_output("%s (%s)", req_string, dist.location)
write_output(
"%s (%s)", req_string, dist.location, show_on_quiet=True
)
else:
write_output(req_string)
write_output(req_string, show_on_quiet=True)
elif options.list_format == "json":
write_output(format_for_json(packages, options))
write_output(format_for_json(packages, options), show_on_quiet=True)

def output_package_listing_columns(
self, data: list[list[str]], header: list[str]
Expand All @@ -318,7 +320,7 @@ def output_package_listing_columns(
pkg_strings.insert(1, " ".join("-" * x for x in sizes))

for val in pkg_strings:
write_output(val)
write_output(val, show_on_quiet=True)


def format_for_columns(
Expand Down
17 changes: 11 additions & 6 deletions src/pip/_internal/commands/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,26 @@ def transform_hits(hits: list[dict[str, str]]) -> list[TransformedHit]:
return list(packages.values())


def print_dist_installation_info(latest: str, dist: BaseDistribution | None) -> None:
def print_dist_installation_info(
latest: str, dist: BaseDistribution | None, show_on_quiet: bool = False
) -> None:
if dist is not None:
with indent_log():
if dist.version == latest:
write_output("INSTALLED: %s (latest)", dist.version)
write_output(
"INSTALLED: %s (latest)", dist.version, show_on_quiet=show_on_quiet
)
else:
write_output("INSTALLED: %s", dist.version)
write_output("INSTALLED: %s", dist.version, show_on_quiet=show_on_quiet)
if parse_version(latest).pre:
write_output(
"LATEST: %s (pre-release; install"
" with `pip install --pre`)",
latest,
show_on_quiet=show_on_quiet,
)
else:
write_output("LATEST: %s", latest)
write_output("LATEST: %s", latest, show_on_quiet=show_on_quiet)


def get_installed_distribution(name: str) -> BaseDistribution | None:
Expand Down Expand Up @@ -167,9 +172,9 @@ def print_results(
name_latest = f"{name} ({latest})"
line = f"{name_latest:{name_column_width}} - {summary}"
try:
write_output(line)
write_output(line, show_on_quiet=True)
dist = get_installed_distribution(name)
print_dist_installation_info(latest, dist)
print_dist_installation_info(latest, dist, show_on_quiet=True)
except UnicodeEncodeError:
pass

Expand Down
54 changes: 28 additions & 26 deletions src/pip/_internal/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,51 +187,53 @@ def print_results(
Print the information from installed distributions found.
"""
results_printed = False

Comment thread
ychampion marked this conversation as resolved.
Outdated
def output(msg: str, *args: object) -> None:
Comment thread
ychampion marked this conversation as resolved.
Outdated
write_output(msg, *args, show_on_quiet=True)

for i, dist in enumerate(distributions):
results_printed = True
if i > 0:
write_output("---")
output("---")

metadata_version = dist.metadata_version
metadata_version_tuple = (
tuple(map(int, metadata_version.split("."))) if metadata_version else ()
)

write_output("Name: %s", dist.name)
write_output("Version: %s", dist.version)
write_output("Summary: %s", dist.summary)
write_output("Home-page: %s", dist.homepage)
write_output("Author: %s", dist.author)
write_output("Author-email: %s", dist.author_email)
output("Name: %s", dist.name)
output("Version: %s", dist.version)
output("Summary: %s", dist.summary)
output("Home-page: %s", dist.homepage)
output("Author: %s", dist.author)
output("Author-email: %s", dist.author_email)
if metadata_version_tuple >= (2, 4) and dist.license_expression:
write_output("License-Expression: %s", dist.license_expression)
output("License-Expression: %s", dist.license_expression)
else:
write_output("License: %s", dist.license)
write_output("Location: %s", dist.location)
output("License: %s", dist.license)
output("Location: %s", dist.location)
if dist.editable_project_location is not None:
write_output(
"Editable project location: %s", dist.editable_project_location
)
write_output("Requires: %s", ", ".join(dist.requires))
write_output("Required-by: %s", ", ".join(dist.required_by))
output("Editable project location: %s", dist.editable_project_location)
output("Requires: %s", ", ".join(dist.requires))
output("Required-by: %s", ", ".join(dist.required_by))

if verbose:
write_output("Metadata-Version: %s", dist.metadata_version)
write_output("Installer: %s", dist.installer)
write_output("Classifiers:")
output("Metadata-Version: %s", dist.metadata_version)
output("Installer: %s", dist.installer)
output("Classifiers:")
for classifier in dist.classifiers:
write_output(" %s", classifier)
write_output("Entry-points:")
output(" %s", classifier)
output("Entry-points:")
for entry in dist.entry_points:
write_output(" %s", entry.strip())
write_output("Project-URLs:")
output(" %s", entry.strip())
output("Project-URLs:")
for project_url in dist.project_urls:
write_output(" %s", project_url)
output(" %s", project_url)
if list_files:
write_output("Files:")
output("Files:")
if dist.files is None:
write_output("Cannot locate RECORD or installed-files.txt")
output("Cannot locate RECORD or installed-files.txt")
else:
for line in dist.files:
write_output(" %s", line.strip())
output(" %s", line.strip())
return results_printed
Loading
Loading