summaryrefslogtreecommitdiff
path: root/dev-python
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2025-06-09 06:27:20 +0200
committerMichał Górny <mgorny@gentoo.org>2025-06-09 06:28:13 +0200
commit21575e36ddbf2f73227373ad7bdc35753405be5a (patch)
treed097e473240260a5a76a554ffdab8f2bad25297c /dev-python
parenta0d9287008bc20663a80a19a168dd4554298b362 (diff)
downloadgentoo-21575e36ddbf2f73227373ad7bdc35753405be5a.tar.gz
gentoo-21575e36ddbf2f73227373ad7bdc35753405be5a.tar.bz2
gentoo-21575e36ddbf2f73227373ad7bdc35753405be5a.zip
dev-python/mpmath: Backport upstream fix for gmpy2 test failures
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'dev-python')
-rw-r--r--dev-python/mpmath/files/mpmath-1.4.0_alpha5-valueerror.patch50
-rw-r--r--dev-python/mpmath/mpmath-1.4.0_alpha5-r1.ebuild64
2 files changed, 114 insertions, 0 deletions
diff --git a/dev-python/mpmath/files/mpmath-1.4.0_alpha5-valueerror.patch b/dev-python/mpmath/files/mpmath-1.4.0_alpha5-valueerror.patch
new file mode 100644
index 000000000000..fc3ebefb7680
--- /dev/null
+++ b/dev-python/mpmath/files/mpmath-1.4.0_alpha5-valueerror.patch
@@ -0,0 +1,50 @@
+From 9ad6a13925922711ca004686194daf8f110feaea Mon Sep 17 00:00:00 2001
+From: Sergey B Kirpichev <skirpichev@gmail.com>
+Date: Mon, 9 Jun 2025 05:07:00 +0300
+Subject: [PATCH] Fix from_man_exp to correctly reject non-integral mantissa
+
+This partially reverts 25506567
+---
+ mpmath/ctx_mp_python.py | 2 +-
+ mpmath/libmp/libmpf.py | 7 +++++--
+ mpmath/tests/test_basic_ops.py | 5 +++++
+ 3 files changed, 11 insertions(+), 3 deletions(-)
+
+diff --git a/mpmath/ctx_mp_python.py b/mpmath/ctx_mp_python.py
+index d9e9f64f..72b81278 100644
+--- a/mpmath/ctx_mp_python.py
++++ b/mpmath/ctx_mp_python.py
+@@ -64,7 +64,7 @@ def __new__(cls, val=fzero, **kwargs):
+ if len(val) == 4:
+ val = val[0], MPZ(val[1]), *val[2:]
+ elif len(val) == 2:
+- v._mpf_ = from_man_exp(MPZ(val[0]), val[1], prec, rounding)
++ v._mpf_ = from_man_exp(val[0], val[1], prec, rounding)
+ return v
+ else:
+ raise ValueError
+diff --git a/mpmath/libmp/libmpf.py b/mpmath/libmp/libmpf.py
+index af61879e..266ee394 100644
+--- a/mpmath/libmp/libmpf.py
++++ b/mpmath/libmp/libmpf.py
+@@ -8,7 +8,7 @@
+ import sys
+ import warnings
+
+-from .backend import BACKEND, MPZ, MPZ_FIVE, MPZ_ONE, MPZ_ZERO, gmpy
++from .backend import BACKEND, MPZ, MPZ_FIVE, MPZ_ONE, MPZ_ZERO, gmpy, int_types
+ from .libintmath import (bctable, bin_to_radix, isqrt, numeral, sqrtrem,
+ stddigits, trailtable)
+
+@@ -204,7 +204,10 @@ def normalize(sign, man, exp, bc, prec, rnd):
+ def from_man_exp(man, exp, prec=0, rnd=round_fast):
+ """Create raw mpf from (man, exp) pair. The mantissa may be signed.
+ If no precision is specified, the mantissa is stored exactly."""
+- man = MPZ(man)
++ if isinstance(man, int_types):
++ man = MPZ(man)
++ else:
++ raise TypeError("man expected to be an integer")
+ sign = 0
+ if man < 0:
+ sign = 1
diff --git a/dev-python/mpmath/mpmath-1.4.0_alpha5-r1.ebuild b/dev-python/mpmath/mpmath-1.4.0_alpha5-r1.ebuild
new file mode 100644
index 000000000000..370afd841770
--- /dev/null
+++ b/dev-python/mpmath/mpmath-1.4.0_alpha5-r1.ebuild
@@ -0,0 +1,64 @@
+# Copyright 1999-2025 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+DISTUTILS_USE_PEP517=setuptools
+PYTHON_COMPAT=( pypy3 pypy3_11 python3_{10..13} )
+
+inherit distutils-r1 optfeature pypi
+
+DESCRIPTION="Python library for arbitrary-precision floating-point arithmetic"
+HOMEPAGE="
+ https://mpmath.org/
+ https://github.com/mpmath/mpmath/
+ https://pypi.org/project/mpmath/
+"
+
+LICENSE="BSD"
+SLOT="0"
+KEYWORDS="~amd64 ~arm ~arm64 ~hppa ~loong ~mips ~ppc ~ppc64 ~riscv ~sparc ~x86 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos"
+IUSE="test-full"
+
+BDEPEND="
+ dev-python/setuptools-scm[${PYTHON_USEDEP}]
+ test? (
+ dev-python/hypothesis[${PYTHON_USEDEP}]
+ dev-python/numpy[${PYTHON_USEDEP}]
+ dev-python/packaging[${PYTHON_USEDEP}]
+ dev-python/pexpect[${PYTHON_USEDEP}]
+ dev-python/pytest-rerunfailures[${PYTHON_USEDEP}]
+ dev-python/pytest-timeout[${PYTHON_USEDEP}]
+ $(python_gen_cond_dep '
+ dev-python/gmpy2[${PYTHON_USEDEP}]
+ ' 'python3*')
+ test-full? (
+ dev-python/matplotlib[${PYTHON_USEDEP}]
+ )
+ )
+"
+
+EPYTEST_XDIST=1
+distutils_enable_tests pytest
+
+PATCHES=(
+ # https://github.com/aleaxit/gmpy/pull/566
+ # https://github.com/mpmath/mpmath/pull/969/commits/9ad6a13925922711ca004686194daf8f110feaea
+ "${FILESDIR}/${P}-valueerror.patch"
+)
+
+python_test() {
+ local EPYTEST_DESELECT=()
+
+ # CLI crashes otherwise, sigh (not a regression)
+ # https://github.com/mpmath/mpmath/issues/907
+ > "${HOME}/.python_history" || die
+
+ local -x PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
+ epytest -p rerunfailures --reruns=5 -p timeout
+}
+
+pkg_postinst() {
+ optfeature "gmp support" dev-python/gmpy2
+ optfeature "matplotlib support" dev-python/matplotlib
+}