From 03f0068e52c3d32a25348dccacba797301610106 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 8 May 2012 11:59:08 +0100 Subject: [PATCH] Better message when forcing a version means not using that interface at all --- tests/Source.xml | 1 + tests/testsolver.py | 2 +- zeroinstall/injector/solver.py | 25 +++++++++++++++---------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/tests/Source.xml b/tests/Source.xml index 13b7076..e21b1a4 100644 --- a/tests/Source.xml +++ b/tests/Source.xml @@ -22,6 +22,7 @@ + diff --git a/tests/testsolver.py b/tests/testsolver.py index 0f7a17b..81c9657 100755 --- a/tests/testsolver.py +++ b/tests/testsolver.py @@ -106,7 +106,7 @@ class TestSolver(BaseTest): justify(foo_binary_uri, foo_src_impls["impossible"], '''There is no possible selection using Binary 3.\nCan't find all required implementations:\n- -> impossible\n- -> None''') justify(compiler.uri, compiler_impls["sha1=999"], - '''Compiler 5 is selectable, but using it would produce a less optimal solution overall.\n\nSelecting Compiler 5 would cause these changes:\n\nhttp://foo/Binary.xml: 1.0 -> 0.1''') + '''Compiler 5 is selectable, but using it would produce a less optimal solution overall.\n\nThe changes would be:\n\nhttp://foo/Binary.xml: 1.0 to 0.1''') def testRecursive(self): iface_cache = self.config.iface_cache diff --git a/zeroinstall/injector/solver.py b/zeroinstall/injector/solver.py index 9a123f5..599140d 100644 --- a/zeroinstall/injector/solver.py +++ b/zeroinstall/injector/solver.py @@ -734,7 +734,7 @@ class SATSolver(Solver): wanted = "{iface} {version}".format(iface = iface.get_name(), version = impl.get_version()) # Could a selection involving impl even be valid? - if not s.ready: + if not s.ready or iface.uri not in s.selections.selections: reasons = s.details.get(iface, []) for (rid, rstr) in reasons: if rid.id == impl.id and rstr is not None: @@ -742,9 +742,10 @@ class SATSolver(Solver): wanted = wanted, reason = rstr) - return _("There is no possible selection using {wanted}.\n{reason}").format( - wanted = wanted, - reason = s.get_failure_reason()) + if not s.ready: + return _("There is no possible selection using {wanted}.\n{reason}").format( + wanted = wanted, + reason = s.get_failure_reason()) actual_selection = self.selections.get(iface, None) if actual_selection is not None: @@ -782,25 +783,29 @@ class SATSolver(Solver): actual = actual_selection.get_version(), why = _ranking_component_reason[i]) + used_impl = iface.uri in s.selections.selections + # Impl is selectable and ranked higher than the selected version. Selecting it would cause # a problem elsewhere. changes = [] for old_iface, old_sel in self.selections.selections.iteritems(): - if old_iface == iface.uri: continue + if old_iface == iface.uri and used_impl: continue new_sel = s.selections.selections.get(old_iface, None) if new_sel is None: changes.append(_("{interface}: no longer used").format(interface = old_iface)) elif old_sel.version != new_sel.version: - changes.append(_("%s: %s -> %s") % (old_iface, old_sel.version, new_sel.version)) + changes.append(_("{interface}: {old} to {new}").format(interface = old_iface, old = old_sel.version, new = new_sel.version)) elif old_sel.id != new_sel.id: - changes.append(_("%s: %s -> %s") % (old_iface, old_sel.id, new_sel.id)) + changes.append(_("{interface}: {old} to {new}").format(interface = old_iface, old = old_sel.id, new = new_sel.id)) if changes: - changes_text = '\n\n' + _('Selecting {wanted} would cause these changes:').format( - wanted = wanted) + '\n\n' + '\n'.join(changes) + changes_text = '\n\n' + _('The changes would be:') + '\n\n' + '\n'.join(changes) else: changes_text = '' - return _("{wanted} is selectable, but using it would produce a less optimal solution overall.").format(wanted = wanted) + changes_text + if used_impl: + return _("{wanted} is selectable, but using it would produce a less optimal solution overall.").format(wanted = wanted) + changes_text + else: + return _("If {wanted} were the only option, the best available solution wouldn't use it.").format(wanted = wanted) + changes_text DefaultSolver = SATSolver -- 2.11.4.GIT