From f9f459001b6ba59b9dbc11eef0ffc4b3a45ac781 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Wed, 13 Sep 2023 02:01:13 +0200 Subject: [PATCH] experiment! borrow pip's resolvelib debug reporter --- .../galaxy/dependency_resolution/__init__.py | 6 ++- .../galaxy/dependency_resolution/reporters.py | 43 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/ansible/galaxy/dependency_resolution/__init__.py b/lib/ansible/galaxy/dependency_resolution/__init__.py index cfde7df0f98..e90b581e174 100644 --- a/lib/ansible/galaxy/dependency_resolution/__init__.py +++ b/lib/ansible/galaxy/dependency_resolution/__init__.py @@ -21,6 +21,9 @@ if t.TYPE_CHECKING: from ansible.galaxy.collection.galaxy_api_proxy import MultiGalaxyAPIProxy from ansible.galaxy.dependency_resolution.providers import CollectionDependencyProvider from ansible.galaxy.dependency_resolution.reporters import CollectionDependencyReporter +from ansible.galaxy.dependency_resolution.reporters import CollectionDependencyDebuggingReporter +from ansible.galaxy.dependency_resolution.reporters import CollectionDependencyReporter + from ansible.galaxy.dependency_resolution.resolvers import CollectionDependencyResolver @@ -51,5 +54,6 @@ def build_collection_dependency_resolver( upgrade=upgrade, include_signatures=include_signatures, ), - CollectionDependencyReporter(), + CollectionDependencyDebuggingReporter(), + # CollectionDependencyReporter(), ) diff --git a/lib/ansible/galaxy/dependency_resolution/reporters.py b/lib/ansible/galaxy/dependency_resolution/reporters.py index 69908b22435..1bd733dd916 100644 --- a/lib/ansible/galaxy/dependency_resolution/reporters.py +++ b/lib/ansible/galaxy/dependency_resolution/reporters.py @@ -19,3 +19,46 @@ class CollectionDependencyReporter(BaseReporter): This is a proxy class allowing us to abstract away importing resolvelib outside of the `ansible.galaxy.dependency_resolution` Python package. """ + + +from logging import basicConfig, DEBUG, getLogger +from sys import stdout + + +basicConfig(stream=stdout, level=DEBUG) +logger = getLogger(__name__) +logger.info('INFO THING') +logger.debug('DEBUG THING') + +from typing import Any +from .dataclasses import Candidate, Requirement + + +class CollectionDependencyDebuggingReporter(CollectionDependencyReporter): + """A reporter that does an info log for every event it sees.""" + + def starting(self) -> None: + logger.info("Reporter.starting()") + + def starting_round(self, index: int) -> None: + logger.info("Reporter.starting_round(%r)", index) + + def ending_round(self, index: int, state: Any) -> None: + logger.info("Reporter.ending_round(%r, %r)", index, state) + + def ending(self, state: Any) -> None: + logger.info("Reporter.ending(%r)", state) + + def adding_requirement(self, requirement: Requirement, parent: Candidate) -> None: + logger.info("Reporter.adding_requirement(%r, %r)", requirement, parent) + + def rejecting_candidate(self, criterion: Any, candidate: Candidate) -> None: + logger.info("Reporter.rejecting_candidate(%r, %r)", criterion, candidate) + + backtracking = rejecting_candidate # Old pre-v0.9.0 resolvelib hook name + + def pinning(self, candidate: Candidate) -> None: + logger.info("Reporter.pinning(%r)", candidate) + + def pinning(self, candidate: Candidate) -> None: + logger.info("Reporter.pinning(%r)", candidate)