dev-python/pytables: make cpuinfo optional

py-cpuinfo needs explicit porting to a platform and it's only lightly used
in pytables. Apply a patch which I've sent upstream to make it optional and
restore keywords accordingly.

We add a USE=cpudetection for arches where pytables is known to work.

Closes: https://bugs.gentoo.org/894078
Signed-off-by: Sam James <sam@gentoo.org>
This commit is contained in:
Sam James
2023-04-03 02:27:48 +01:00
parent ba83a922b4
commit 17b7393607
5 changed files with 160 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
https://github.com/PyTables/PyTables/pull/1013
From 557f8c22b772506bfbb9e7eb4d60c0cf2125998b Mon Sep 17 00:00:00 2001
From: Sam James <sam@gentoo.org>
Date: Mon, 3 Apr 2023 02:07:47 +0100
Subject: [PATCH] Handle py-cpuinfo not being installed
Fallback gracefully if py-cpuinfo isn't installed. We already handle this in
setup.py but we need to avoid calling it in leaf.py too.
py-cpuinfo isn't available on all platforms and PyTables is needed to run
the test suite for some software, so we need to be able to run PyTables
in places where py-cpuinfo isn't yet ported.
Signed-off-by: Sam James <sam@gentoo.org>
--- a/tables/leaf.py
+++ b/tables/leaf.py
@@ -4,7 +4,10 @@
import math
import numpy as np
-import cpuinfo
+try:
+ import cpuinfo
+except ImportError:
+ missing_cpuinfo = True
from .flavor import (check_flavor, internal_flavor, toarray,
alias_map as flavor_alias_map)
@@ -336,20 +339,21 @@ def _calc_chunkshape(self, expectedrows, rowsize, itemsize):
# Use a decent default value for chunksize
chunksize *= 16
# Now, go explore the L3 size and try to find a smarter chunksize
- cpu_info = cpuinfo.get_cpu_info()
- if 'l3_cache_size' in cpu_info:
- # In general, is a good idea to set the chunksize equal to L3
- l3_cache_size = cpu_info['l3_cache_size']
- # cpuinfo sometimes returns cache sizes as strings (like,
- # "4096 KB"), so refuse the temptation to guess and use the
- # value only when it is an actual int.
- # Also, sometimes cpuinfo does not return a correct L3 size;
- # so in general, enforcing L3 > L2 is a good sanity check.
- l2_cache_size = cpu_info.get('l2_cache_size', "Not found")
- if (type(l3_cache_size) is int and
- type(l2_cache_size) is int and
- l3_cache_size > l2_cache_size):
- chunksize = l3_cache_size
+ if not missing_cpuinfo:
+ cpu_info = cpuinfo.get_cpu_info()
+ if 'l3_cache_size' in cpu_info:
+ # In general, is a good idea to set the chunksize equal to L3
+ l3_cache_size = cpu_info['l3_cache_size']
+ # cpuinfo sometimes returns cache sizes as strings (like,
+ # "4096 KB"), so refuse the temptation to guess and use the
+ # value only when it is an actual int.
+ # Also, sometimes cpuinfo does not return a correct L3 size;
+ # so in general, enforcing L3 > L2 is a good sanity check.
+ l2_cache_size = cpu_info.get('l2_cache_size', "Not found")
+ if (type(l3_cache_size) is int and
+ type(l2_cache_size) is int and
+ l3_cache_size > l2_cache_size):
+ chunksize = l3_cache_size
# In Blosc2, the chunksize cannot be larger than 2 GB - BLOSC2_MAX_BUFFERSIZE
if chunksize > 2**31 - 32:
chunksize = 2**31 - 32

View File

@@ -17,6 +17,9 @@
from Pyrex sources, makes it a fast, yet extremely easy to use tool
for interactively save and retrieve large amounts of data.
</longdescription>
<use>
<flag name="cpudetection">Enables runtime CPU detection (useful for bindist, compatibility on other CPUs)</flag>
</use>
<upstream>
<remote-id type="github">PyTables/PyTables</remote-id>
<remote-id type="pypi">tables</remote-id>

View File

@@ -0,0 +1,82 @@
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
PYTHON_COMPAT=( python3_{9..11} )
PYPI_PN="tables"
PYTHON_REQ_USE="threads(+)"
inherit distutils-r1 prefix pypi
DESCRIPTION="Hierarchical datasets for Python"
HOMEPAGE="
https://www.pytables.org/
https://github.com/PyTables/PyTables/
https://pypi.org/project/tables/
"
LICENSE="BSD"
SLOT="0"
KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~ia64 ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux"
IUSE="+cpudetection examples test"
RESTRICT="!test? ( test )"
DEPEND="
app-arch/bzip2:0=
app-arch/lz4:0=
>=app-arch/zstd-1.0.0:=
>=dev-libs/c-blosc-1.11.1:0=
dev-libs/c-blosc2:=
dev-libs/lzo:2=
>=dev-python/numpy-1.19[${PYTHON_USEDEP}]
>=sci-libs/hdf5-1.8.4:=
"
RDEPEND="
${DEPEND}
>=dev-python/numexpr-2.6.2[${PYTHON_USEDEP}]
dev-python/packaging[${PYTHON_USEDEP}]
cpudetection? ( dev-python/py-cpuinfo[${PYTHON_USEDEP}] )
"
BDEPEND="
>=dev-python/cython-0.21[${PYTHON_USEDEP}]
virtual/pkgconfig
cpudetection? ( dev-python/py-cpuinfo[${PYTHON_USEDEP}] )
test? (
${RDEPEND}
)
"
python_prepare_all() {
local PATCHES=(
"${FILESDIR}"/${P}-blosc2.patch
"${FILESDIR}"/${P}-optional-cpuinfo.patch
)
export PYTABLES_NO_EMBEDDED_LIBS=1
export USE_PKGCONFIG=TRUE
rm -r c-blosc/{blosc,internal-complibs} || die
rm tables/libblosc2.so || die
sed -i -e '/blosc2/d' requirements.txt || die
hprefixify -w '/prefixes =/' setup.py
distutils-r1_python_prepare_all
}
python_compile() {
distutils-r1_python_compile -j1
}
python_test() {
cd "${BUILD_DIR}"/lib* || die
"${EPYTHON}" tables/tests/test_all.py -v || die
}
python_install_all() {
distutils-r1_python_install_all
if use examples; then
dodoc -r contrib examples
docompress -x /usr/share/doc/${PF}/{contrib,examples}
fi
}

View File

@@ -17,6 +17,10 @@
#--- END OF EXAMPLES ---
# Sam James <sam@gentoo.org> (2023-04-03)
# pytables is available here.
dev-python/pytables -cpudetection
# Yiyang Wu <xgreenlandforwyy@gmail.com> (2023-01-27)
# AMDGPU enablement depends on dev-libs/rocr-runtime, ~amd64 only
# See also: https://bugs.gentoo.org/891499

View File

@@ -1,6 +1,11 @@
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# Sam James <sam@gentoo.org> (2023-04-03)
# Needs dev-python/py-cpuinfo which is not ported to all of our platforms
# See bug #894078.
dev-python/pytables cpudetection
# Michał Górny <mgorny@gentoo.org> (2023-01-24)
# libomptarget is only supported on 64-bit architectures.
>=sys-libs/libomp-16.0.0_pre20230124 offload