From 27c2591cd0b433e4b94575175dc7b9404e66747d Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 31 May 2013 17:16:34 -0700 Subject: [PATCH] depgraph.display(): handle reverse for --tree This factors --tree logic out of the calling code, and allows optimization of _show_merge_list to use reference comparison instead of == comparison. Also, deprecate the unused depgraph.altlist() "reversed" parameter, due to builtin name collision. --- pym/_emerge/Scheduler.py | 6 +---- pym/_emerge/actions.py | 8 +++---- pym/_emerge/depgraph.py | 26 ++++++++++++--------- pym/_emerge/resolver/circular_dependency.py | 3 +-- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/pym/_emerge/Scheduler.py b/pym/_emerge/Scheduler.py index 4e8b223fb..94d3d3f52 100644 --- a/pym/_emerge/Scheduler.py +++ b/pym/_emerge/Scheduler.py @@ -1827,11 +1827,7 @@ class Scheduler(PollScheduler): return False if success and self._show_list(): - mylist = mydepgraph.altlist() - if mylist: - if "--tree" in self.myopts: - mylist = tuple(reversed(mylist)) - mydepgraph.display(mylist, favorites=self._favorites) + mydepgraph.display(mydepgraph.altlist(), favorites=self._favorites) if not success: self._post_mod_echo_msgs.append(mydepgraph.display_problems) diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index 7b2cf54a5..d6e810084 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -336,7 +336,7 @@ def action_build(settings, trees, mtimedb, return os.EX_OK favorites = mtimedb["resume"]["favorites"] retval = mydepgraph.display( - mydepgraph.altlist(reversed=tree), + mydepgraph.altlist(), favorites=favorites) mydepgraph.display_problems() mergelist_shown = True @@ -345,7 +345,7 @@ def action_build(settings, trees, mtimedb, prompt="Would you like to resume merging these packages?" else: retval = mydepgraph.display( - mydepgraph.altlist(reversed=("--tree" in myopts)), + mydepgraph.altlist(), favorites=favorites) mydepgraph.display_problems() mergelist_shown = True @@ -404,7 +404,7 @@ def action_build(settings, trees, mtimedb, return os.EX_OK favorites = mtimedb["resume"]["favorites"] retval = mydepgraph.display( - mydepgraph.altlist(reversed=tree), + mydepgraph.altlist(), favorites=favorites) mydepgraph.display_problems() mergelist_shown = True @@ -412,7 +412,7 @@ def action_build(settings, trees, mtimedb, return retval else: retval = mydepgraph.display( - mydepgraph.altlist(reversed=("--tree" in myopts)), + mydepgraph.altlist(), favorites=favorites) mydepgraph.display_problems() mergelist_shown = True diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index 9c0a966c5..3e29508c7 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -9,6 +9,7 @@ import logging import stat import sys import textwrap +import warnings from collections import deque from itertools import chain @@ -5694,7 +5695,12 @@ class depgraph(object): mygraph.order.sort(key=cmp_sort_key(cmp_merge_preference)) - def altlist(self, reversed=False): + def altlist(self, reversed=DeprecationWarning): + + if reversed is not DeprecationWarning: + warnings.warn("The reversed parameter of " + "_emerge.depgraph.depgraph.altlist() is deprecated", + DeprecationWarning, stacklevel=2) while self._dynamic_config._serialized_tasks_cache is None: self._resolve_conflicts() @@ -5705,8 +5711,8 @@ class depgraph(object): pass retlist = self._dynamic_config._serialized_tasks_cache - if reversed: - # TODO: deprecate the "reversed" parameter (builtin name collision) + if reversed is not DeprecationWarning and reversed: + # TODO: remove the "reversed" parameter (builtin name collision) retlist = list(retlist) retlist.reverse() retlist = tuple(retlist) @@ -6647,14 +6653,8 @@ class depgraph(object): def _show_merge_list(self): if self._dynamic_config._serialized_tasks_cache is not None and \ not (self._dynamic_config._displayed_list is not None and \ - (self._dynamic_config._displayed_list is self._dynamic_config._serialized_tasks_cache or \ - self._dynamic_config._displayed_list == self._dynamic_config._serialized_tasks_cache or \ - self._dynamic_config._displayed_list == \ - list(reversed(self._dynamic_config._serialized_tasks_cache)))): - display_list = self._dynamic_config._serialized_tasks_cache - if "--tree" in self._frozen_config.myopts: - display_list = tuple(reversed(display_list)) - self.display(display_list) + self._dynamic_config._displayed_list is self._dynamic_config._serialized_tasks_cache): + self.display(self._dynamic_config._serialized_tasks_cache) def _show_unsatisfied_blockers(self, blockers): self._show_merge_list() @@ -6749,6 +6749,10 @@ class depgraph(object): # redundantly displaying this exact same merge list # again via _show_merge_list(). self._dynamic_config._displayed_list = mylist + + if "--tree" in self._frozen_config.myopts: + mylist = tuple(reversed(mylist)) + display = Display() return display(self, mylist, favorites, verbosity) diff --git a/pym/_emerge/resolver/circular_dependency.py b/pym/_emerge/resolver/circular_dependency.py index 6380b22c7..b7106714a 100644 --- a/pym/_emerge/resolver/circular_dependency.py +++ b/pym/_emerge/resolver/circular_dependency.py @@ -62,8 +62,7 @@ class circular_dependency_handler(object): node = nodes[0] display_order.append(node) tempgraph.remove(node) - display_order.reverse() - return display_order + return tuple(display_order) def _prepare_circular_dep_message(self): """ -- 2.26.2