Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o, Alec Warner <antarus@g.o>
Cc: "Michał Górny" <mgorny@g.o>
Subject: Re: [gentoo-portage-dev] [PATCH 8/8] eshowkw: Always group Prefix keywords last
Date: Fri, 26 Jan 2018 05:45:30
Message-Id: 6c14acd5-9d89-73cd-6696-00453b972eaa@gentoo.org
In Reply to: Re: [gentoo-portage-dev] [PATCH 8/8] eshowkw: Always group Prefix keywords last by Alec Warner
1 On 01/23/2018 03:25 PM, Alec Warner wrote:
2 >
3 >
4 > On Tue, Jan 23, 2018 at 4:48 PM, Michał Górny <mgorny@g.o
5 > <mailto:mgorny@g.o>> wrote:
6 >
7 > Always group all Prefix keywords after other types of keywords. This
8 > not only ensures that fbsd sorts first but more importantly stabilizes
9 > the LHS output between regular and -P variant -- that is, -P always adds
10 > additional keywords at the end.
11 > ---
12 >  pym/gentoolkit/eshowkw/keywords_header.py | 16 ++++++++++------
13 >  1 file changed, 10 insertions(+), 6 deletions(-)
14 >
15 > diff --git a/pym/gentoolkit/eshowkw/keywords_header.py
16 > b/pym/gentoolkit/eshowkw/keywords_header.py
17 > index 41b8ba4..1b64bfd 100644
18 > --- a/pym/gentoolkit/eshowkw/keywords_header.py
19 > +++ b/pym/gentoolkit/eshowkw/keywords_header.py
20 > @@ -142,12 +142,16 @@ class keywords_header:
21 >                                         break
22 >
23 >                 # sort by, in order (to match Bugzilla):
24 > -               # 1. arch, then ~arch
25 > -               # 2. profile stability
26 > -               # 3. short keywords, then long (prefix, fbsd)
27 > -               # 4. keyword name in reverse component order
28 > -               normal.sort(key=lambda kw: (kw in
29 > self.__TESTING_KW_ARCHS,
30 > -                       levels.get(kw, 99), kw.count('-'),
31 > list(reversed(kw.split('-')))))
32 > +               # 1. non-prefix, then prefix (stable output between
33 > -P and not)
34 > +               # 2. arch, then ~arch
35 > +               # 3. profile stability
36 > +               # 4. short keywords, then long (prefix, fbsd)
37 > +               # 5. keyword name in reverse component order
38 > +               normal.sort(key=lambda kw: (self.__isPrefix(kw),
39 > +                       kw in self.__TESTING_KW_ARCHS,
40 > +                       levels.get(kw, 99),
41 > +                       kw.count('-'),
42 > +                       list(reversed(kw.split('-')))))
43 >
44 >
45 > I'm a bit sad about this lambda because its ended up a bit long.
46 >
47 > What are your thoughts on splitting it out?
48
49 The fact that it's a lambda doesn't bother me so much as the
50 inefficiency of regenerating the key on every call. I've found this cute
51 little memodict decorator that will optimize it nicely:
52
53 http://code.activestate.com/recipes/578231-probably-the-fastest-memoization-decorator-in-the-/
54
55 def memodict(f):
56 class memodict(dict):
57 def __missing__(self, key):
58 ret = self[key] = f(key)
59 return ret
60 return memodict().__getitem__
61
62 --
63 Thanks,
64 Zac

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies