Skip to content

Commit

Permalink
Show used solver in conda info output. (conda#13279)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
jezdez and pre-commit-ci[bot] authored Nov 3, 2023
1 parent 9b1098d commit 16de74f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 13 deletions.
27 changes: 15 additions & 12 deletions conda/base/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,20 @@ def log_level(self) -> int:
else:
return logging.WARNING # 30

def solver_user_agent(self):
user_agent = "solver/%s" % self.solver
try:
solver_backend = self.plugin_manager.get_cached_solver_backend()
# Solver.user_agent has to be a static or class method
user_agent += f" {solver_backend.user_agent()}"
except Exception as exc:
log.debug(
"User agent could not be fetched from solver class '%s'.",
self.solver,
exc_info=exc,
)
return user_agent

@memoizedproperty
def user_agent(self):
builder = [f"conda/{CONDA_VERSION} requests/{self.requests_version}"]
Expand All @@ -1019,18 +1033,7 @@ def user_agent(self):
if self.libc_family_version[0]:
builder.append("%s/%s" % self.libc_family_version)
if self.solver != "classic":
user_agent_str = "solver/%s" % self.solver
try:
solver_backend = self.plugin_manager.get_cached_solver_backend()
# Solver.user_agent has to be a static or class method
user_agent_str += f" {solver_backend.user_agent()}"
except Exception as exc:
log.debug(
"User agent could not be fetched from solver class '%s'.",
self.solver,
exc_info=exc,
)
builder.append(user_agent_str)
builder.append(self.solver_user_agent())
return " ".join(builder)

@contextmanager
Expand Down
19 changes: 18 additions & 1 deletion conda/cli/main_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,13 @@ def print_package_info(packages):
def get_info_dict(system=False):
from .. import CONDA_PACKAGE_ROOT
from .. import __version__ as conda_version
from ..base.context import context, env_name, sys_rc_path, user_rc_path
from ..base.context import (
DEFAULT_SOLVER,
context,
env_name,
sys_rc_path,
user_rc_path,
)
from ..common.compat import on_win
from ..common.url import mask_anaconda_token
from ..core.index import _supplement_index_with_system
Expand Down Expand Up @@ -242,6 +248,12 @@ def get_info_dict(system=False):

active_prefix_name = env_name(context.active_prefix)

solver = {
"name": context.solver,
"user_agent": context.solver_user_agent(),
"default": context.solver == DEFAULT_SOLVER,
}

info_dict = dict(
platform=context.subdir,
conda_version=conda_version,
Expand Down Expand Up @@ -272,6 +284,7 @@ def get_info_dict(system=False):
config_files=context.config_files,
netrc_file=netrc_file,
virtual_pkgs=virtual_pkgs,
solver=solver,
)
if on_win:
from ..common._os.windows import is_admin_on_windows
Expand Down Expand Up @@ -350,6 +363,10 @@ def builder():
yield ("conda version", info_dict["conda_version"])
yield ("conda-build version", info_dict["conda_build_version"])
yield ("python version", info_dict["python_version"])
yield (
"solver",
f"{info_dict['solver']['name']}{' (default)' if info_dict['solver']['default'] else ''}",
)
yield (
"virtual packages",
flatten("=".join(pkg) for pkg in info_dict["virtual_pkgs"]),
Expand Down
19 changes: 19 additions & 0 deletions news/13265-show-solver-conda-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* Show the used solver in `conda info` output to simplify debugging. (#13265)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
2 changes: 2 additions & 0 deletions tests/cli/test_main_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test_info(conda_cli: CondaCLIFixture):
assert "channel URLs" in stdout_basic
assert "config file" in stdout_basic
assert "offline mode" in stdout_basic
assert "solver" in stdout_basic
assert not stderr
assert not err

Expand Down Expand Up @@ -95,6 +96,7 @@ def test_info_json(conda_cli: CondaCLIFixture):
"rc_path",
"root_prefix",
"root_writable",
"solver",
} <= set(parsed)


Expand Down

0 comments on commit 16de74f

Please sign in to comment.