Skip to content

Commit

Permalink
dep: merge Dependency and DependencySet __init__() and from_ptr()
Browse files Browse the repository at this point in the history
  • Loading branch information
radhermit committed Jun 18, 2024
1 parent 2a0397f commit 84e22d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/pkgcraft/dep/base.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ cdef class Dependency:
cdef readonly object set

@staticmethod
cdef Dependency from_ptr(C.Dependency *)
cdef Dependency from_ptr(C.Dependency *, Dependency inst=*)


cdef class DependencySet:
cdef C.DependencySet *ptr
cdef readonly object set

@staticmethod
cdef DependencySet from_ptr(C.DependencySet *)
cdef DependencySet from_ptr(C.DependencySet *, DependencySet inst=*)

cdef clone(self)
cdef create(self, C.DependencySet *)
Expand All @@ -27,4 +27,4 @@ cdef class DependencySet:
cdef class MutableDependencySet(DependencySet):

@staticmethod
cdef MutableDependencySet from_ptr(C.DependencySet *)
cdef DependencySet from_ptr(C.DependencySet *, DependencySet inst=*)
26 changes: 12 additions & 14 deletions src/pkgcraft/dep/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ cdef class Dependency:
if ptr is NULL:
raise PkgcraftError

self.set = DependencySetKind(ptr.set)
self.kind = DependencyKind(ptr.kind)
self.ptr = ptr
Dependency.from_ptr(ptr, self)

@classmethod
def package(cls, s: str = None, eapi: Eapi | str = None):
Expand Down Expand Up @@ -99,9 +97,10 @@ cdef class Dependency:
return cls(s, set=DependencySetKind.SrcUri)

@staticmethod
cdef Dependency from_ptr(C.Dependency *ptr):
cdef Dependency from_ptr(C.Dependency *ptr, Dependency inst = None):
"""Create a Dependency from a pointer and type."""
inst = <Dependency>Dependency.__new__(Dependency)
if inst is None:
inst = <Dependency>Dependency.__new__(Dependency)
inst.set = DependencySetKind(ptr.set)
inst.kind = DependencyKind(ptr.kind)
inst.ptr = ptr
Expand Down Expand Up @@ -229,8 +228,7 @@ cdef class DependencySet:
if ptr is NULL:
raise PkgcraftError

self.set = DependencySetKind(ptr.set)
self.ptr = ptr
DependencySet.from_ptr(ptr, self)

@classmethod
def package(cls, s: str = None, eapi: Eapi | str = None):
Expand Down Expand Up @@ -263,9 +261,10 @@ cdef class DependencySet:
return cls(s, set=DependencySetKind.SrcUri)

@staticmethod
cdef DependencySet from_ptr(C.DependencySet *ptr):
cdef DependencySet from_ptr(C.DependencySet *ptr, DependencySet inst = None):
"""Create a DependencySet from a pointer."""
inst = <DependencySet>DependencySet.__new__(DependencySet)
if inst is None:
inst = <DependencySet>DependencySet.__new__(DependencySet)
inst.set = DependencySetKind(ptr.set)
inst.ptr = ptr
return inst
Expand Down Expand Up @@ -527,12 +526,11 @@ cdef class MutableDependencySet(DependencySet):
"""Mutable set of dependency objects."""

@staticmethod
cdef MutableDependencySet from_ptr(C.DependencySet *ptr):
cdef MutableDependencySet from_ptr(C.DependencySet *ptr, DependencySet inst = None):
"""Create a MutableDependencySet from a pointer."""
inst = <MutableDependencySet>MutableDependencySet.__new__(MutableDependencySet)
inst.set = DependencySetKind(ptr.set)
inst.ptr = ptr
return inst
if inst is None:
inst = <MutableDependencySet>MutableDependencySet.__new__(MutableDependencySet)
return DependencySet.from_ptr(ptr, inst)

def sort(self):
"""Recursively sort a DependencySet.
Expand Down

0 comments on commit 84e22d2

Please sign in to comment.