Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/dbapi/
Date: Mon, 24 Sep 2018 07:30:21
Message-Id: 1537771532.ebd2c386f5ae2aced4c3ea05dacffdb99bd0bf5b.zmedico@gentoo
1 commit: ebd2c386f5ae2aced4c3ea05dacffdb99bd0bf5b
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Mon Sep 24 03:04:13 2018 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Mon Sep 24 06:45:32 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=ebd2c386
7
8 portdbapi: add async_xmatch method (bug 666940)
9
10 Add an async_xmatch method, and use it to implement the synchronous
11 xmatch method. Deprecate unused xmatch method parameters. Use the
12 compat_coroutine decorator for backward compatibility with python2.7
13 (via PEP 342 enhanced generators).
14
15 Bug: https://bugs.gentoo.org/666940
16 Suggested-by: Daniel Robbins <drobbins <AT> funtoo.org>
17 Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
18
19 lib/portage/dbapi/porttree.py | 60 +++++++++++++++++++++++++++++++++++--------
20 1 file changed, 49 insertions(+), 11 deletions(-)
21
22 diff --git a/lib/portage/dbapi/porttree.py b/lib/portage/dbapi/porttree.py
23 index 56955ec34..76b7967f7 100644
24 --- a/lib/portage/dbapi/porttree.py
25 +++ b/lib/portage/dbapi/porttree.py
26 @@ -37,6 +37,7 @@ from portage import _unicode_encode
27 from portage import OrderedDict
28 from portage.util._eventloop.EventLoop import EventLoop
29 from portage.util.futures import asyncio
30 +from portage.util.futures.compat_coroutine import coroutine, coroutine_return
31 from portage.util.futures.iter_completed import iter_gather
32 from _emerge.EbuildMetadataPhase import EbuildMetadataPhase
33
34 @@ -1055,8 +1056,20 @@ class portdbapi(dbapi):
35 self._better_cache = None
36 self.frozen = 0
37
38 - def xmatch(self,level,origdep,mydep=None,mykey=None,mylist=None):
39 - "caching match function; very trick stuff"
40 + def xmatch(self, level, origdep, mydep=DeprecationWarning,
41 + mykey=DeprecationWarning, mylist=DeprecationWarning):
42 + """
43 + Caching match function.
44 +
45 + @param level: xmatch level (bestmatch-visible, match-all-cpv-only
46 + match-allmatch-visible, minimum-all, minimum-all-ignore-profile,
47 + or minimum-visible)
48 + @type level: str
49 + @param origdep: dependency to match (may omit category)
50 + @type origdep: portage.dep.Atom or str
51 + @return: match result(s)
52 + @rtype: _pkg_str or list of _pkg_str (depends on level)
53 + """
54 if level == "list-visible":
55 level = "match-visible"
56 warnings.warn("The 'list-visible' mode of "
57 @@ -1064,21 +1077,46 @@ class portdbapi(dbapi):
58 "has been renamed to match-visible",
59 DeprecationWarning, stacklevel=2)
60
61 - if mydep is None:
62 - #this stuff only runs on first call of xmatch()
63 - #create mydep, mykey from origdep
64 - mydep = dep_expand(origdep, mydb=self, settings=self.settings)
65 - mykey = mydep.cp
66 + if mydep is not DeprecationWarning:
67 + warnings.warn("The 'mydep' parameter of "
68 + "portage.dbapi.porttree.portdbapi.xmatch"
69 + " is deprecated and ignored",
70 + DeprecationWarning, stacklevel=2)
71 +
72 + loop = self._event_loop
73 + return loop.run_until_complete(
74 + self.async_xmatch(level, origdep, loop=loop))
75 +
76 + @coroutine
77 + def async_xmatch(self, level, origdep, loop=None):
78 + """
79 + Asynchronous form of xmatch.
80 +
81 + @param level: xmatch level (bestmatch-visible, match-all-cpv-only
82 + match-allmatch-visible, minimum-all, minimum-all-ignore-profile,
83 + or minimum-visible)
84 + @type level: str
85 + @param origdep: dependency to match (may omit category)
86 + @type origdep: portage.dep.Atom or str
87 + @param loop: event loop (defaults to global event loop)
88 + @type loop: EventLoop
89 + @return: match result(s)
90 + @rtype: asyncio.Future (or compatible), which results in a _pkg_str
91 + or list of _pkg_str (depends on level)
92 + """
93 + mydep = dep_expand(origdep, mydb=self, settings=self.settings)
94 + mykey = mydep.cp
95
96 #if no updates are being made to the tree, we can consult our xcache...
97 cache_key = None
98 if self.frozen:
99 cache_key = (mydep, mydep.unevaluated_atom)
100 try:
101 - return self.xcache[level][cache_key][:]
102 + coroutine_return(self.xcache[level][cache_key][:])
103 except KeyError:
104 pass
105
106 + loop = asyncio._wrap_loop(loop)
107 myval = None
108 mytree = None
109 if mydep.repo is not None:
110 @@ -1131,8 +1169,8 @@ class portdbapi(dbapi):
111
112 for cpv in iterfunc(mylist):
113 try:
114 - metadata = dict(zip(aux_keys,
115 - self.aux_get(cpv, aux_keys, myrepo=cpv.repo)))
116 + metadata = dict(zip(aux_keys, (yield self.async_aux_get(cpv,
117 + aux_keys, myrepo=cpv.repo, loop=loop))))
118 except KeyError:
119 # ebuild not in this repo, or masked by corruption
120 continue
121 @@ -1176,7 +1214,7 @@ class portdbapi(dbapi):
122 if not isinstance(myval, _pkg_str):
123 myval = myval[:]
124
125 - return myval
126 + coroutine_return(myval)
127
128 def match(self, mydep, use_cache=1):
129 return self.xmatch("match-visible", mydep)