[bitbake-devel,V2,1/1] utils.py: Add option for explode_dep_versions2 to return unsorted

Submitted by Stephano Cetola on Feb. 19, 2018, 6:15 p.m. | Patch ID: 148166

Details

Message ID 20180219181551.87750-2-stephano.cetola@linux.intel.com
State New
Headers show

Commit Message

Stephano Cetola Feb. 19, 2018, 6:15 p.m.
From: Amanda Brindle <amanda.r.brindle@intel.com>

Before, explode_dep_versions2 would sort the OrderedDict before
returning. This function will still sort the OrderedDict by default, but
will now have the option to return the OrderedDict unsorted. This option will
allow us to check if the order of the package list has changed.

Signed-off-by: Amanda Brindle <amanda.r.brindle@intel.com>
Acked-by: Stephano Cetola <stephano.cetola@linux.intel.com>
---
 lib/bb/utils.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index c540b49c..7adb4690 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -187,7 +187,7 @@  def explode_deps(s):
             #r[-1] += ' ' + ' '.join(j)
     return r
 
-def explode_dep_versions2(s):
+def explode_dep_versions2(s, unsorted=False):
     """
     Take an RDEPENDS style string of format:
     "DEPEND1 (optional version) DEPEND2 (optional version) ..."
@@ -250,7 +250,8 @@  def explode_dep_versions2(s):
         if not (i in r and r[i]):
             r[lastdep] = []
 
-    r = collections.OrderedDict(sorted(r.items(), key=lambda x: x[0]))
+    if not unsorted:
+        r = collections.OrderedDict(sorted(r.items(), key=lambda x: x[0]))
     return r
 
 def explode_dep_versions(s):

Comments

Richard Purdie Feb. 20, 2018, 12:08 p.m.
On Mon, 2018-02-19 at 10:15 -0800, Stephano Cetola wrote:
> From: Amanda Brindle <amanda.r.brindle@intel.com>
> 
> Before, explode_dep_versions2 would sort the OrderedDict before
> returning. This function will still sort the OrderedDict by default,
> but
> will now have the option to return the OrderedDict unsorted. This
> option will
> allow us to check if the order of the package list has changed.
> 
> Signed-off-by: Amanda Brindle <amanda.r.brindle@intel.com>
> Acked-by: Stephano Cetola <stephano.cetola@linux.intel.com>
> ---
>  lib/bb/utils.py | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/bb/utils.py b/lib/bb/utils.py
> index c540b49c..7adb4690 100644
> --- a/lib/bb/utils.py
> +++ b/lib/bb/utils.py
> @@ -187,7 +187,7 @@ def explode_deps(s):
>              #r[-1] += ' ' + ' '.join(j)
>      return r
>  
> -def explode_dep_versions2(s):
> +def explode_dep_versions2(s, unsorted=False):
>      """

Would:

def explode_dep_versions2(s, sorted=True):

make things easier to read/understand?

The 'double' logic there currently confuses me a bit.

Cheers,

Richard
Christopher Larson Feb. 20, 2018, 3:14 p.m.
On Tue, Feb 20, 2018 at 5:08 AM, Richard Purdie <
richard.purdie@linuxfoundation.org> wrote:

> On Mon, 2018-02-19 at 10:15 -0800, Stephano Cetola wrote:
> > From: Amanda Brindle <amanda.r.brindle@intel.com>
> >
> > Before, explode_dep_versions2 would sort the OrderedDict before
> > returning. This function will still sort the OrderedDict by default,
> > but
> > will now have the option to return the OrderedDict unsorted. This
> > option will
> > allow us to check if the order of the package list has changed.
> >
> > Signed-off-by: Amanda Brindle <amanda.r.brindle@intel.com>
> > Acked-by: Stephano Cetola <stephano.cetola@linux.intel.com>
> > ---
> >  lib/bb/utils.py | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/lib/bb/utils.py b/lib/bb/utils.py
> > index c540b49c..7adb4690 100644
> > --- a/lib/bb/utils.py
> > +++ b/lib/bb/utils.py
> > @@ -187,7 +187,7 @@ def explode_deps(s):
> >              #r[-1] += ' ' + ' '.join(j)
> >      return r
> >
> > -def explode_dep_versions2(s):
> > +def explode_dep_versions2(s, unsorted=False):
> >      """
>
> Would:
>
> def explode_dep_versions2(s, sorted=True):
>
> make things easier to read/understand?
>
> The 'double' logic there currently confuses me a bit.


sorted=True seems clearer to me as well. I’d also recommend thinking about
making this a keyword-only argument, for readability’s sake.

explode_dep_versions2(s, False) reads pretty unclear, since it loses the
info about the meaning of False. Making it keyword only would ensure we’re
forced to called it as sorted=False instead.