# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DISTUTILS_USE_PEP517=setuptools
PYTHON_COMPAT=( python3_{12..14} )

inherit distutils-r1 flag-o-matic

DESCRIPTION="Toolkit for setting up free energy (mutation) calculations in GROMACS"
HOMEPAGE="https://github.com/deGrootLab/pmx"
SRC_URI="https://github.com/deGrootLab/${PN}/archive/refs/tags/${PV}.tar.gz -> ${P}.tar.gz"

LICENSE="LGPL-3"
SLOT="0"
KEYWORDS="~amd64"
IUSE="test"
RESTRICT="!test? ( test )"

# 'future' is listed in install_requires but never imported (py2 leftover)
RDEPEND="
	dev-python/matplotlib[${PYTHON_USEDEP}]
	dev-python/numpy[${PYTHON_USEDEP}]
	dev-python/scipy[${PYTHON_USEDEP}]
	sci-chemistry/gromacs
"
BDEPEND="
	test? ( dev-python/pytest[${PYTHON_USEDEP}] )
"

PATCHES=(
	"${FILESDIR}/${P}-numpy2-bar-scalar.patch"
)

src_prepare() {
	default

	# setup_requires pins setuptools to ~=46.0 (2020), which makes the build
	# fetch it via easy_install instead of using the tree's setuptools; the
	# package builds fine against current setuptools.
	sed -i -e '/setup_requires=/d' -e "s/, 'future'//" setup.py || die
}

src_compile() {
	# pmx.h carries 'typedef int bool' (and friends), which is invalid with
	# the C23 default of GCC 15+; the code targets pre-C23 semantics where
	# bool is an int, so compile the extensions with C17 instead of trying
	# to retarget them at native _Bool.
	filter-flags '-std=*'
	append-flags -std=gnu17
	distutils-r1_src_compile
}

python_test() {
	epytest
}