dev-python/protobuf: Enable testing

Signed-off-by: Michał Górny <mgorny@gentoo.org>
This commit is contained in:
Michał Górny 2025-06-01 17:40:37 +02:00
parent d1794094b3
commit caf505a17e
No known key found for this signature in database
GPG Key ID: 639ADAE2329E240E
2 changed files with 146 additions and 0 deletions

View File

@ -1,3 +1,4 @@
DIST protobuf-5.29.4.py.tar.gz 424902 BLAKE2B 54941b008ff5ebd007076448828564128d98e9a6a4613c87057c359124940d341358fe28107b929e3e842ac7e1b34ed54c30219ed95cbb418826592e2458a01f SHA512 634faf103ed8320762593689796d26e6b988e1b40277b12dc7356983c07d5d1da8cac1530e4f16c0a1494abfb885f26bf9884988029e863515cf535c62d96c77
DIST protobuf-5.29.5.py.tar.gz 425226 BLAKE2B 1d7461e94ba8bc097d6f52170678665e3cd97ef44e4757e6c20bcb1bdfbfe673d26cd4a63f8e6972af964e381dfffedeb9a4959ec7a7d5a3a3f87f917c8aa329 SHA512 cbb39efe7f6499362b3e4cc9f073df921c8b83d3aafde245a2ca3432f3e744a428e946799c48b2797e08312342e164eced0bf2b8865b8d042b54913855abb1c8
DIST protobuf-6.30.2.gh.tar.gz 9523913 BLAKE2B d3950abfe8b3b61dc2bb61f683b014de29451252c46b670dee75a81eb0b8ed30a3209227aa9483800244af16058469deb281521609d769a3456a798ca8a9a4a3 SHA512 f2ee857a36b49f87257a306b3f3c361770d74aaf24c4650b9d00994e1e1a0b09079fb0ce5ffb4d5a4a32d8ca46e3247d6db454918fa0b104fc8d58e8a0546a96
DIST protobuf-6.30.2.py.tar.gz 429315 BLAKE2B 6b56e23a8a962ce9da282ec49c4807877f4bfb677ad84bb6930b83cc436e9839f5791cfb19105678881c8361e27d62d3dde51e5e6c42f7a0e146d9e469282780 SHA512 48ddb2b63acc91759ba4243926c50bb0d16601aace9019129975701634b77a59415659751c69b06464afe994a0fbbd8da6640a208b743ba7df8bf6d60c5ec2b9

View File

@ -0,0 +1,145 @@
# Copyright 2008-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
# Default implementation currently is upb, which doesn't match dev-libs/protobuf
# https://github.com/protocolbuffers/protobuf/blob/main/python/README.md#implementation-backends
DISTUTILS_EXT=1
DISTUTILS_USE_PEP517=setuptools
PYTHON_COMPAT=( python3_{11..13} )
inherit distutils-r1 pypi
DESCRIPTION="Google's Protocol Buffers - Python bindings"
HOMEPAGE="
https://protobuf.dev/
https://pypi.org/project/protobuf/
"
# Rename sdist to avoid conflicts with dev-libs/protobuf
SRC_URI="
$(pypi_sdist_url) -> ${P}.py.tar.gz
test? (
https://github.com/protocolbuffers/protobuf/archive/v${PV}.tar.gz
-> ${P}.gh.tar.gz
)
"
LICENSE="BSD"
SLOT="0/$(ver_cut 1-3)"
KEYWORDS="~amd64 ~arm ~arm64 ~x86"
# need protobuf compiler
BDEPEND="
test? (
dev-libs/protobuf
dev-python/absl-py[${PYTHON_USEDEP}]
dev-python/numpy[${PYTHON_USEDEP}]
)
"
distutils_enable_tests pytest
src_unpack() {
unpack "${P}.py.tar.gz"
if use test; then
mkdir "${WORKDIR}/test" || die
cd "${WORKDIR}/test" || die
unpack "${P}.gh.tar.gz"
fi
}
src_prepare() {
distutils-r1_src_prepare
# strip old-style namespace
rm google/__init__.py || die
}
python_test() {
local EPYTEST_IGNORE=(
# TODO: figure out how to build the pybind11 test extension
google/protobuf/internal/recursive_message_pybind11_test.py
)
case ${EPYTHON} in
python3.11)
EPYTEST_IGNORE+=(
# syntax error...
google/protobuf/internal/json_format_test.py
)
;;
python3.13)
# TODO: segfaults on exit
return
;;
esac
cp -r "${BUILD_DIR}"/{install,test} || die
local -x PATH="${BUILD_DIR}/test${EPREFIX}/usr/bin:${PATH}"
cd "${BUILD_DIR}/test$(python_get_sitedir)" || die
# copy test files from the source tree
cp -r "${WORKDIR}/test/${P}/python/google/protobuf/internal/." \
google/protobuf/internal/ || die
# link the test data for text_format_test.py
# (it traverses directories upwards until to finds src/google...)
ln -s "${WORKDIR}/test/${P}/src" ../src || die
# compile test-related protobufs
local test_protos=(
# from src
any_test.proto
map_proto2_unittest.proto
map_unittest.proto
unittest.proto
unittest_custom_options.proto
unittest_delimited.proto
unittest_delimited_import.proto
unittest_features.proto
unittest_import.proto
unittest_import_public.proto
unittest_legacy_features.proto
unittest_mset.proto
unittest_mset_wire_format.proto
unittest_no_field_presence.proto
unittest_no_generic_services.proto
unittest_proto3.proto
unittest_proto3_arena.proto
unittest_proto3_extensions.proto
unittest_retention.proto
util/json_format.proto
util/json_format_proto3.proto
# from python
internal/descriptor_pool_test1.proto
internal/descriptor_pool_test2.proto
internal/factory_test1.proto
internal/factory_test2.proto
internal/file_options_test.proto
internal/import_test_package/import_public.proto
internal/import_test_package/import_public_nested.proto
internal/import_test_package/inner.proto
internal/import_test_package/outer.proto
internal/message_set_extensions.proto
internal/missing_enum_values.proto
internal/more_extensions.proto
internal/more_messages.proto
internal/no_package.proto
internal/packed_field_test.proto
internal/self_recursive.proto
internal/test_bad_identifiers.proto
internal/test_proto2.proto
internal/test_proto3_optional.proto
internal/well_known_types_test.proto
)
local proto
for proto in "${test_protos[@]}"; do
protoc --python_out=. -I"${WORKDIR}/test/${P}/src" -I. \
"google/protobuf/${proto}" || die
done
local -x PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
epytest -s
}