Skip to content

Commit 56e86ae

Browse files
committed
eapi: simplify Eapi.from_ptr() creating new instances for every call
1 parent fcaccf4 commit 56e86ae

5 files changed

Lines changed: 12 additions & 19 deletions

File tree

src/pkgcraft/eapi.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ cdef class Eapi(Indirect):
1414
cdef int _hash
1515

1616
@staticmethod
17-
cdef Eapi from_ptr(const C.Eapi *, bint init=*)
17+
cdef Eapi from_ptr(const C.Eapi *)
1818

1919
@staticmethod
2020
cdef Eapi _from_obj(object)

src/pkgcraft/eapi.pyx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cdef get_official_eapis():
1717
"""Get the mapping of all official EAPIs."""
1818
cdef size_t length
1919
c_eapis = C.pkgcraft_eapis_official(&length)
20-
eapis = [Eapi.from_ptr(c_eapis[i], init=True) for i in range(length)]
20+
eapis = [Eapi.from_ptr(c_eapis[i]) for i in range(length)]
2121
d = {str(eapi): eapi for eapi in eapis}
2222
C.pkgcraft_array_free(<void **>c_eapis, length)
2323

@@ -34,7 +34,7 @@ cdef get_eapis():
3434
cdef size_t length
3535
d = EAPIS_OFFICIAL.copy()
3636
c_eapis = C.pkgcraft_eapis(&length)
37-
eapis = [Eapi.from_ptr(c_eapis[i], init=True) for i in range(len(d), length)]
37+
eapis = [Eapi.from_ptr(c_eapis[i]) for i in range(len(d), length)]
3838
globals()['EAPI_LATEST'] = eapis[-1]
3939
d.update((str(eapi), eapi) for eapi in eapis)
4040
C.pkgcraft_array_free(<void **>c_eapis, length)
@@ -80,18 +80,11 @@ cpdef OrderedFrozenSet eapi_range(s: str):
8080
cdef class Eapi(Indirect):
8181

8282
@staticmethod
83-
cdef Eapi from_ptr(const C.Eapi *ptr, bint init=False):
83+
cdef Eapi from_ptr(const C.Eapi *ptr):
8484
"""Create an Eapi object from a pointer."""
85-
cdef Eapi eapi
86-
87-
if init:
88-
eapi = <Eapi>Eapi.__new__(Eapi)
89-
eapi.ptr = ptr
90-
else:
91-
id = cstring_to_str(C.pkgcraft_eapi_as_str(ptr))
92-
eapi = EAPIS[id]
93-
94-
return eapi
85+
inst = <Eapi>Eapi.__new__(Eapi)
86+
inst.ptr = ptr
87+
return inst
9588

9689
@staticmethod
9790
cdef Eapi _from_obj(object obj):

tests/pkg/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_cpv_base(self, repo):
1919
assert pkg.cpv == Cpv("cat/pkg-1-r2")
2020

2121
def test_eapi_base(self, pkg):
22-
assert pkg.eapi is EAPI_LATEST_OFFICIAL
22+
assert pkg.eapi == EAPI_LATEST_OFFICIAL
2323

2424
def test_repo(self, pkg, repo):
2525
assert pkg.repo == repo

tests/pkg/test_ebuild.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class TestEbuildPkg(BasePkgTests):
3131
def test_eapi(self, ebuild_repo):
3232
EAPI_PREV_OFFICIAL = list(EAPIS_OFFICIAL.values())[-2]
3333
pkg = ebuild_repo.create_pkg("cat/pkg-1", eapi=EAPI_PREV_OFFICIAL)
34-
assert pkg.eapi is EAPI_PREV_OFFICIAL
34+
assert pkg.eapi == EAPI_PREV_OFFICIAL
3535
pkg = ebuild_repo.create_pkg("cat/pkg-1", eapi=EAPI_LATEST_OFFICIAL)
36-
assert pkg.eapi is EAPI_LATEST_OFFICIAL
36+
assert pkg.eapi == EAPI_LATEST_OFFICIAL
3737

3838
def test_intersects(self, make_ebuild_repo):
3939
repo = make_ebuild_repo(id="test")

tests/repo/test_ebuild.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ def test_eapi(self, make_raw_ebuild_repo):
9090
# defaults to latest EAPI
9191
repo = make_raw_ebuild_repo()
9292
r = EbuildRepo(repo.path)
93-
assert r.eapi is EAPI_LATEST_OFFICIAL
93+
assert r.eapi == EAPI_LATEST_OFFICIAL
9494

9595
# explicitly force latest EAPI
9696
repo = make_raw_ebuild_repo(eapi=EAPI_LATEST_OFFICIAL)
9797
r = EbuildRepo(repo.path)
98-
assert r.eapi is EAPI_LATEST_OFFICIAL
98+
assert r.eapi == EAPI_LATEST_OFFICIAL
9999

100100
def test_masters(self):
101101
primary = TEST_DATA.repos["primary"]

0 commit comments

Comments
 (0)