Skip to content

Commit e301969

Browse files
committed
dep: update UseDepKind handling for pkgcraft changes
1 parent 522579a commit e301969

4 files changed

Lines changed: 29 additions & 27 deletions

File tree

src/pkgcraft/C.pxd

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,8 @@ cdef extern from "pkgcraft.h":
9797

9898
# Package USE dependency default when missing.
9999
cdef enum UseDepDefault:
100-
USE_DEP_DEFAULT_ENABLED,
101100
USE_DEP_DEFAULT_DISABLED,
102-
103-
# Package USE dependency type.
104-
cdef enum UseDepKind:
105-
USE_DEP_KIND_ENABLED,
106-
USE_DEP_KIND_DISABLED,
107-
USE_DEP_KIND_EQUAL,
108-
USE_DEP_KIND_NOT_EQUAL,
109-
USE_DEP_KIND_ENABLED_CONDITIONAL,
110-
USE_DEP_KIND_DISABLED_CONDITIONAL,
101+
USE_DEP_DEFAULT_ENABLED,
111102

112103
# System config
113104
cdef struct Config:
@@ -207,6 +198,18 @@ cdef extern from "pkgcraft.h":
207198
cdef struct Version:
208199
pass
209200

201+
# Package USE dependency type.
202+
cdef enum UseDepKind_Tag:
203+
USE_DEP_KIND_ENABLED,
204+
USE_DEP_KIND_EQUAL,
205+
USE_DEP_KIND_CONDITIONAL,
206+
207+
cdef struct UseDepKind:
208+
UseDepKind_Tag tag
209+
bool enabled
210+
bool equal
211+
bool conditional
212+
210213
# C-compatible wrapper for pkgcraft::dep::UseDep.
211214
cdef struct UseDep:
212215
UseDepKind kind

src/pkgcraft/dep/use_dep.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from .. cimport C
44
cdef class UseDep:
55
cdef C.UseDep *ptr
66
cdef readonly object kind
7+
cdef readonly bint enabled
78
cdef readonly str flag
89
cdef object default_
910
# cached fields

src/pkgcraft/dep/use_dep.pyx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ from ..error import PkgcraftError
88

99
class UseDepKind(IntEnum):
1010
Enabled = C.USE_DEP_KIND_ENABLED
11-
Disabled = C.USE_DEP_KIND_DISABLED
1211
Equal = C.USE_DEP_KIND_EQUAL
13-
NotEqual = C.USE_DEP_KIND_NOT_EQUAL
14-
EnabledConditional = C.USE_DEP_KIND_ENABLED_CONDITIONAL
15-
DisabledConditional = C.USE_DEP_KIND_DISABLED_CONDITIONAL
12+
Conditional = C.USE_DEP_KIND_CONDITIONAL
1613

1714

1815
class UseDepDefault(IntEnum):
19-
Enabled = C.USE_DEP_DEFAULT_ENABLED
2016
Disabled = C.USE_DEP_DEFAULT_DISABLED
17+
Enabled = C.USE_DEP_DEFAULT_ENABLED
2118

2219

2320
cdef class UseDep:
@@ -41,7 +38,7 @@ cdef class UseDep:
4138
>>> u = UseDep('!use?')
4239
>>> u.flag
4340
'use'
44-
>>> u.kind == UseDepKind.DisabledConditional
41+
>>> u.kind == UseDepKind.Conditional
4542
True
4643
>>> u.default is None
4744
True
@@ -77,7 +74,8 @@ cdef class UseDep:
7774
if inst is None:
7875
inst = <UseDep>UseDep.__new__(UseDep)
7976
inst.ptr = <C.UseDep *>ptr
80-
inst.kind = UseDepKind(ptr.kind)
77+
inst.kind = UseDepKind(ptr.kind.tag)
78+
inst.enabled = ptr.kind.enabled
8179
inst.flag = ptr.flag.decode()
8280
if ptr.default_ is NULL:
8381
inst.default_ = None
@@ -132,8 +130,7 @@ cdef class UseDep:
132130
def __repr__(self):
133131
addr = <size_t>&self.ptr
134132
name = self.__class__.__name__
135-
kind = self.kind.name
136-
return f"<{name} {kind} '{self}' at 0x{addr:0x}>"
133+
return f"<{name} '{self}' at 0x{addr:0x}>"
137134

138135
def __dealloc__(self):
139136
C.pkgcraft_use_dep_free(self.ptr)

tests/dep/test_use_dep.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ def test_creation(self):
1414
("(+)", UseDepDefault.Enabled),
1515
("(-)", UseDepDefault.Disabled),
1616
):
17-
for s, kind in (
18-
(f"u{d}", UseDepKind.Enabled),
19-
(f"-u{d}", UseDepKind.Disabled),
20-
(f"u{d}=", UseDepKind.Equal),
21-
(f"!u{d}=", UseDepKind.NotEqual),
22-
(f"u{d}?", UseDepKind.EnabledConditional),
23-
(f"!u{d}?", UseDepKind.DisabledConditional),
17+
for s, kind, enabled in (
18+
(f"u{d}", UseDepKind.Enabled, True),
19+
(f"-u{d}", UseDepKind.Enabled, False),
20+
(f"u{d}=", UseDepKind.Equal, True),
21+
(f"!u{d}=", UseDepKind.Equal, False),
22+
(f"u{d}?", UseDepKind.Conditional, True),
23+
(f"!u{d}?", UseDepKind.Conditional, False),
2424
):
2525
use = UseDep(s)
2626
assert use.kind == kind
27+
assert use.enabled == enabled
2728
assert use.flag == "u"
2829
assert use.default == default
2930
# verify the internal field is hidden from native python
@@ -37,7 +38,7 @@ def test_creation(self):
3738
UseDep(s)
3839

3940
def test_cmp(self):
40-
for s1, s2 in (("a", "b"), ("u", "-u"), ("u(+)", "u(-)"), ("u?", "!u?")):
41+
for s1, s2 in (("a", "b"), ("-u", "u"), ("u(-)", "u(+)"), ("!u?", "u?")):
4142
use1 = UseDep(s1)
4243
use2 = UseDep(s2)
4344
obj = object()

0 commit comments

Comments
 (0)