Skip to content

Commit 035675c

Browse files
committed
repo.ebuild: export eapi property
1 parent 47475ed commit 035675c

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/pkgcraft/pkgcraft_c.pxd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,12 @@ cdef extern from "pkgcraft.h":
861861
# The argument must be a non-null Repo pointer.
862862
bool pkgcraft_repo_contains_path(Repo *r, const char *path);
863863

864+
# Return an ebuild repo's EAPI.
865+
#
866+
# # Safety
867+
# The argument must be a non-null Repo pointer.
868+
const Eapi *pkgcraft_repo_ebuild_eapi(Repo *r);
869+
864870
# Return an ebuild repo's masters.
865871
#
866872
# # Safety

src/pkgcraft/repo/ebuild.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .. cimport pkgcraft_c as C
2+
from ..eapi cimport Eapi
23
from . cimport Repo
34

45

src/pkgcraft/repo/ebuild.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ cdef class EbuildRepo(Repo):
1515
repos = C.pkgcraft_repo_ebuild_masters(self.ptr, &length)
1616
self._masters = tuple(EbuildRepo.from_ptr(repos[i], False) for i in range(length))
1717
return self._masters
18+
19+
@property
20+
def eapi(self):
21+
"""Get an ebuild repo's EAPI."""
22+
return Eapi.from_ptr(C.pkgcraft_repo_ebuild_eapi(self.ptr))

tests/repo/test_ebuild.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44

5+
from pkgcraft.eapi import EAPI0, EAPI_LATEST
56
from pkgcraft.error import InvalidRepo
67
from pkgcraft.repo import EbuildRepo, Repo
78

@@ -73,6 +74,27 @@ def test_contains_path(self, make_ebuild_repo):
7374
assert pkg1.path not in r2
7475
assert pkg2.path in r2
7576

77+
def test_eapi(self, make_raw_ebuild_repo):
78+
# non-present defaults to EAPI 0
79+
repo = make_raw_ebuild_repo(eapi=None)
80+
r = EbuildRepo(repo.path)
81+
assert r.eapi is EAPI0
82+
83+
# invalid EAPI
84+
repo = make_raw_ebuild_repo(eapi="unknown")
85+
with pytest.raises(InvalidRepo, match="invalid repo eapi"):
86+
EbuildRepo(repo.path)
87+
88+
# defaults to latest EAPI
89+
repo = make_raw_ebuild_repo()
90+
r = EbuildRepo(repo.path)
91+
assert r.eapi is EAPI_LATEST
92+
93+
# explicitly force latest EAPI
94+
repo = make_raw_ebuild_repo(eapi=EAPI_LATEST)
95+
r = EbuildRepo(repo.path)
96+
assert r.eapi is EAPI_LATEST
97+
7698
def test_masters(self, config, make_raw_ebuild_repo):
7799
# empty masters
78100
repo = make_raw_ebuild_repo()

0 commit comments

Comments
 (0)