Gentoo Archives: gentoo-portage-dev

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

Attachments

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