From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id BE880138200 for ; Tue, 20 Aug 2013 21:46:29 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id EC4B3E0C80; Tue, 20 Aug 2013 21:46:26 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 1F3B2E0C27 for ; Tue, 20 Aug 2013 21:46:25 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E45FA33EB9C for ; Tue, 20 Aug 2013 21:46:24 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 7409DE5463 for ; Tue, 20 Aug 2013 21:46:23 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1377016349.0cd0e9e1f3aa993f9cc583007cb8d3de46e30d1c.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/interface/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/interface/depres.py X-VCS-Directories: roverlay/interface/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 0cd0e9e1f3aa993f9cc583007cb8d3de46e30d1c X-VCS-Branch: master Date: Tue, 20 Aug 2013 21:46:23 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: bc0b977d-fd43-4917-97c3-b8ee4a9a5509 X-Archives-Hash: 96665a32114c1f351a1c05f10d289a86 commit: 0cd0e9e1f3aa993f9cc583007cb8d3de46e30d1c Author: André Erdmann mailerd de> AuthorDate: Tue Aug 20 16:32:29 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Tue Aug 20 16:32:29 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=0cd0e9e1 depres interface: optionally use non-greedy channels --- roverlay/interface/depres.py | 75 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 9 deletions(-) diff --git a/roverlay/interface/depres.py b/roverlay/interface/depres.py index e6885fc..c7ba95c 100644 --- a/roverlay/interface/depres.py +++ b/roverlay/interface/depres.py @@ -41,12 +41,22 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ): CONFIG_KEY_DEPRULES = 'DEPRES.simple_rules.files' - def __init__ ( self, parent_interface ): + GREEDY_DEPRES_CHANNEL = roverlay.depres.channels.EbuildJobChannel + NONGREEDY_DEPRES_CHANNEL = roverlay.depres.channels.NonGreedyDepresChannel + + def __init__ ( self, parent_interface, greedy=None, want_tuple=False ): """Initializes the depdency resolution interface. arguments: * parent_interface -- parent interface that provides shared functionality like logging and config + * greedy -- whether to use greedy depres channels by default + or not. See get_channel() for details. + Defaults to None (=greedy if dep resolver uses + threads, else not greedy). + * want_tuple -- when do_resolve() with preserve_order=True: + return resolved deps as tuples not list + Defaults to False. """ super ( DepresInterface, self ).__init__ ( parent_interface=parent_interface @@ -56,6 +66,9 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ): self._resolver = roverlay.depres.depresolver.DependencyResolver ( err_queue=self.err_queue ) + self.set_greedy ( greedy ) + self.want_tuple = bool ( want_tuple ) + ## log everything self._resolver.set_logmask ( -1 ) ## disable passing events to listeners @@ -89,6 +102,18 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ): """Index of the topmost rule pool (-1 if no rule pool active)""" return self._pool_id + def set_greedy ( self, greedy ): + if greedy is None: + self.default_depres_channel = ( + self.GREEDY_DEPRES_CHANNEL if self._resolver.get_threadcount() + else self.NONGREEDY_DEPRES_CHANNEL + ) + elif greedy: + self.default_depres_channel = self.GREEDY_DEPRES_CHANNEL + else: + self.default_depres_channel = self.NONGREEDY_DEPRES_CHANNEL + # --- end of set_greedy (...) --- + def _update_resolver ( self ): """Updates the resolver. @@ -431,7 +456,7 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ): ) # --- end of visualize_pools (...) --- - def get_channel ( self, channel_name="channel" ): + def get_channel ( self, channel_name="channel", greedy=None ): """Creates, registers and returns an EbuildJobChannel suitable for dependency resolution. @@ -440,15 +465,25 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ): arguments: * channel_name -- name of the channel (defaults to "channel") + * greedy -- whether to return a greedy or non-greedy depres + channel. The greedy one stops if a mandatory dep + cannot be resolved, whereas the non-greedy one keeps + going until all deps have been processed. + Defaults to None (=use default channel). """ - channel = roverlay.depres.channels.EbuildJobChannel ( - err_queue=self.err_queue, name=channel_name - ) + if greedy is None: + channel_cls = self.default_depres_channel + elif greedy: + channel_cls = self.GREEDY_DEPRES_CHANNEL + else: + channel_cls = self.NONGREEDY_DEPRES_CHANNEL + + channel = channel_cls ( err_queue=self.err_queue, name=channel_name ) self._resolver.register_channel ( channel ) return channel # --- end of get_channel (...) --- - def do_resolve ( self, deps, with_deptype=DEFAULT_DEPTYPE ): + def do_resolve ( self, deps, with_deptype=DEFAULT_DEPTYPE, greedy=None ): """Performs dependency resolution for the given dependency list and returns the result, which is None (=not resolved) or a 2-tuple (, ). @@ -459,6 +494,8 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ): arguments: * deps -- dependency string list * with_deptype -- dependency type (optional, defaults to DEFAULT_DEPTYPE) + * greedy -- whether to use a greedy depres channel or not + Defaults to None. """ channel = self.get_channel() # FIXME/COULDFIX: once again, hardcoded deptype @@ -467,7 +504,8 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ): channel_result = channel.satisfy_request ( close_if_unresolvable=False, - preserve_order=True + preserve_order=True, + want_tuple=self.want_tuple, ) finally: channel.close() @@ -475,6 +513,23 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ): return channel_result # --- end of do_resolve (...) --- + def _do_resolve_weak_greedy ( self, deps, kw, greedy=True ): + """Calls do_resolve ( deps, **kw ) with the given greedy mode unless + greedy is in kw. + + Passes do_resolve()'s return value. + + arguments: + * deps -- + * kw -- + * greedy -- defaults to True + """ + if 'greedy' in kw: + return self.do_resolve ( deps, **kw ) + else: + return self.do_resolve ( deps, greedy=greedy, **kw ) + # --- end of _do_resolve_weak_greedy (...) --- + def resolve ( self, *deps, **kw ): """Like do_resolve(), but accepts the dependency string list in var-args form and returns None (=not resolved) or a list of resolved dependencies. @@ -499,7 +554,9 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ): * *deps -- * **kw -- """ - return self.do_resolve ( deps, **kw ) is not None + return ( + self._do_resolve_weak_greedy ( deps, kw, greedy=True ) is not None + ) # --- end of can_resolve (...) --- def cannot_resolve ( self, *deps, **kw ): @@ -510,7 +567,7 @@ class DepresInterface ( roverlay.interface.generic.RoverlaySubInterface ): * *deps -- * **kw -- """ - return self.do_resolve ( deps, **kw ) is None + return self._do_resolve_weak_greedy ( deps, kw, greedy=True ) is None # --- end of cannot_resolve (...) --- # --- end of DepresInterface ---