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

Decouple logs output color from the logging level #10763

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
Empty file added news/10519.bugfix.rst
Empty file.
2 changes: 1 addition & 1 deletion src/pip/_internal/resolution/resolvelib/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ def describe_trigger(parent: Candidate) -> str:
+ "the dependency conflict\n"
)

logger.info(msg)
logger.critical(msg, extra={"color": "black"})
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved

return DistributionNotFound(
"ResolutionImpossible: for help visit "
Expand Down
6 changes: 5 additions & 1 deletion src/pip/_internal/utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ def emit(self, record: logging.LogRecord) -> None:
else:
message = self.format(record)
renderable = self.render_message(record, message)
if record.levelno is not None:
# If a custom color is passed use it, otherwise use default colors.
color_attribute = "color"
if hasattr(record, color_attribute):
style = Style(color=getattr(record, color_attribute))
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
elif record.levelno is not None:
if record.levelno >= logging.ERROR:
style = Style(color="red")
elif record.levelno >= logging.WARNING:
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_install_reqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,8 @@ def test_install_distribution_union_with_versions(
)
if resolver_variant == "2020-resolver":
assert "Cannot install localextras[bar]" in result.stderr
assert ("localextras[bar] 0.0.1 depends on localextras 0.0.1") in result.stdout
assert ("localextras[baz] 0.0.2 depends on localextras 0.0.2") in result.stdout
assert ("localextras[bar] 0.0.1 depends on localextras 0.0.1") in result.stderr
assert ("localextras[baz] 0.0.2 depends on localextras 0.0.2") in result.stderr
else:
assert (
"Successfully installed LocalExtras-0.0.1 simple-3.0 singlemodule-0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_new_resolver_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_new_resolver_conflict_constraints_file(
assert "ResolutionImpossible" in result.stderr, str(result)

message = "The user requested (constraint) pkg!=1.0"
assert message in result.stdout, str(result)
assert message in result.stderr, str(result)


def test_new_resolver_requires_python_error(script: PipTestEnvironment) -> None:
Expand Down