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