1 |
On 01/20/2018 07:26 PM, Alec Warner wrote: |
2 |
> On Sat, Jan 20, 2018 at 7:41 PM, Zac Medico <zmedico@g.o |
3 |
> <mailto:zmedico@g.o>> wrote: |
4 |
> |
5 |
> On 01/20/2018 04:23 PM, Alec Warner wrote: |
6 |
> > On Sat, Jan 20, 2018 at 7:10 PM, Zac Medico <zmedico@g.o <mailto:zmedico@g.o> |
7 |
> > <mailto:zmedico@g.o <mailto:zmedico@g.o>>> wrote: |
8 |
> > |
9 |
> > diff --git a/pym/portage/dep/dep_check.py |
10 |
> b/pym/portage/dep/dep_check.py |
11 |
> > index 7cf338819..c56f545ec 100644 |
12 |
> > --- a/pym/portage/dep/dep_check.py |
13 |
> > +++ b/pym/portage/dep/dep_check.py |
14 |
> > @@ -499,7 +499,8 @@ def dep_zapdeps(unreduced, reduced, myroot, |
15 |
> > use_binaries=0, trees=None): |
16 |
> > cp_map[avail_pkg.cp] = avail_pkg |
17 |
> > |
18 |
> > new_slot_count = (len(slot_map) if graph_db is |
19 |
> None else |
20 |
> > - sum(not graph_db.match_pkgs(slot_atom) for |
21 |
> > slot_atom in slot_map)) |
22 |
> > + sum(not graph_db.match_pkgs(slot_atom) for |
23 |
> > slot_atom in slot_map |
24 |
> > + if not |
25 |
> slot_atom.cp.startswith("virtual/"))) |
26 |
> > |
27 |
> > |
28 |
> > I see this logic all over dep_zapdeps. But AFAIK its already using |
29 |
> > instances of Atom here. |
30 |
> > Can't we encode the cost inside of Atom, so that we don't need to |
31 |
> carve |
32 |
> > out that virtual atoms are 0 cost? |
33 |
> > |
34 |
> > Then we could write something like: |
35 |
> > |
36 |
> > new_slot_count = len(slot_map) if graph_db is None else |
37 |
> > sum(slot_atom.cost() for slot_atom in slot_map if not |
38 |
> > graph_db.match_pkgs(slot_atom)) |
39 |
> > |
40 |
> > Then virtuals would just have a cost() of 0. And others could have |
41 |
> other |
42 |
> > costs (or just 1.) |
43 |
> |
44 |
> That seems like a very practical approach. However, the cost is actually |
45 |
> a property of the matched package rather than the atom itself. It's only |
46 |
> because of GLEP 37 that we can treat the "virtual" category specially, |
47 |
> but GLEP 37 actually says nothing about the "virtual" category! There's |
48 |
> also a java-virtuals category! |
49 |
> |
50 |
> |
51 |
> This mess was the motivation for my PROPERTIES=virtual suggestion: |
52 |
> |
53 |
> https://archives.gentoo.org/gentoo-dev/message/9d449a18a96a25a547fcfd40544085cf |
54 |
> <https://archives.gentoo.org/gentoo-dev/message/9d449a18a96a25a547fcfd40544085cf> |
55 |
> |
56 |
> If we implement something like PROPERTIES=virtual, then cost becomes a |
57 |
> property of the package instance rather than the atom. |
58 |
> |
59 |
> |
60 |
> So I have two goals with my comments: |
61 |
> |
62 |
> 1) Avoid code repetition. If we are checking "if |
63 |
> foo.startswith('virtual/')" a bunch of places; it might be useful to |
64 |
> factor that out into either a helper: |
65 |
> |
66 |
> def is_virtual(atom): |
67 |
> return atom.startswith('virtual/') |
68 |
> |
69 |
> Or attach this directly to the Atom class so callers can just do |
70 |
> atom.is_virtual() |
71 |
> |
72 |
> I can kind of see why the latter might be icky (because its not |
73 |
> necessarily an intrinsic part of the Atom interface.) |
74 |
> I'm not sure its necessary to wait for PROPERTIES=virtual support to |
75 |
> make this change; its simply refactoring existing logic. |
76 |
|
77 |
Maybe something like this: |
78 |
|
79 |
diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py |
80 |
index 6ff6adcb9..bd18b5ec8 100644 |
81 |
--- a/pym/portage/dep/__init__.py |
82 |
+++ b/pym/portage/dep/__init__.py |
83 |
@@ -1322,6 +1322,8 @@ class Atom(_unicode): |
84 |
self.__dict__['cpv'] = cpv |
85 |
self.__dict__['version'] = extended_version |
86 |
self.__dict__['repo'] = repo |
87 |
+ self.__dict__['category'], self.__dict__['pn'] = catsplit(cp) |
88 |
+ self.__dict__['virtual'] = self.category == 'virtual' |
89 |
if slot is None: |
90 |
self.__dict__['slot'] = None |
91 |
self.__dict__['sub_slot'] = None |
92 |
|
93 |
> 2) Avoid 'needing to know about virtuals'. I concede this is likely |
94 |
> difficult with the current state of things. the dbapi.match calls don't |
95 |
> return Packages; so we can't |
96 |
> rely on packages to communicate state. This ends up with code complexity |
97 |
> at call sites (e.g. if not match(atom) and isVirtual(atom) # action). I |
98 |
> concede this isn't |
99 |
> worth fixing right now. |
100 |
|
101 |
The dep_zapdeps function does deal with Package instances (returned from |
102 |
match_pkgs method) when processing dependencies for the depgraph, but |
103 |
it's also capable of working with a regular dbapi. |
104 |
-- |
105 |
Thanks, |
106 |
Zac |