Gentoo Archives: gentoo-portage-dev

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

Replies