commit:     17b7393607ac3b08735d76bce6287d31d4d5f27f
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Mon Apr  3 01:27:48 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Apr  3 01:30:33 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=17b73936

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 <AT> gentoo.org>

 .../files/pytables-3.8.0-optional-cpuinfo.patch    | 66 +++++++++++++++++
 dev-python/pytables/metadata.xml                   |  3 +
 dev-python/pytables/pytables-3.8.0-r2.ebuild       | 82 ++++++++++++++++++++++
 profiles/arch/amd64/package.use.mask               |  4 ++
 profiles/arch/base/package.use.mask                |  5 ++
 5 files changed, 160 insertions(+)

diff --git a/dev-python/pytables/files/pytables-3.8.0-optional-cpuinfo.patch 
b/dev-python/pytables/files/pytables-3.8.0-optional-cpuinfo.patch
new file mode 100644
index 000000000000..f56854b05289
--- /dev/null
+++ b/dev-python/pytables/files/pytables-3.8.0-optional-cpuinfo.patch
@@ -0,0 +1,66 @@
+https://github.com/PyTables/PyTables/pull/1013
+
+From 557f8c22b772506bfbb9e7eb4d60c0cf2125998b Mon Sep 17 00:00:00 2001
+From: Sam James <s...@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 <s...@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
+

diff --git a/dev-python/pytables/metadata.xml b/dev-python/pytables/metadata.xml
index 75a6770d99e4..2fea045e5982 100644
--- a/dev-python/pytables/metadata.xml
+++ b/dev-python/pytables/metadata.xml
@@ -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>

diff --git a/dev-python/pytables/pytables-3.8.0-r2.ebuild 
b/dev-python/pytables/pytables-3.8.0-r2.ebuild
new file mode 100644
index 000000000000..1e479c6bc7d4
--- /dev/null
+++ b/dev-python/pytables/pytables-3.8.0-r2.ebuild
@@ -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
+}

diff --git a/profiles/arch/amd64/package.use.mask 
b/profiles/arch/amd64/package.use.mask
index 634a8a2278c5..0e00baae5e9c 100644
--- a/profiles/arch/amd64/package.use.mask
+++ b/profiles/arch/amd64/package.use.mask
@@ -17,6 +17,10 @@
 
 #--- END OF EXAMPLES ---
 
+# Sam James <s...@gentoo.org> (2023-04-03)
+# pytables is available here.
+dev-python/pytables -cpudetection
+
 # Yiyang Wu <xgreenlandfor...@gmail.com> (2023-01-27)
 # AMDGPU enablement depends on dev-libs/rocr-runtime, ~amd64 only
 # See also: https://bugs.gentoo.org/891499

diff --git a/profiles/arch/base/package.use.mask 
b/profiles/arch/base/package.use.mask
index 228e18bc1d72..9af8d281351a 100644
--- a/profiles/arch/base/package.use.mask
+++ b/profiles/arch/base/package.use.mask
@@ -1,6 +1,11 @@
 # Copyright 1999-2023 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
+# Sam James <s...@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 <mgo...@gentoo.org> (2023-01-24)
 # libomptarget is only supported on 64-bit architectures.
 >=sys-libs/libomp-16.0.0_pre20230124 offload

Reply via email to