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

EAPI=8

PYTHON_COMPAT=( python3_{12..14} )

inherit python-r1

DESCRIPTION="Python wrapper around the AUSAXS C++ SAXS library"
HOMEPAGE="
	https://github.com/AUSAXS/pyAUSAXS
	https://pypi.org/project/pyausaxs/
"
# Upstream publishes only wheels; install the manylinux one verbatim,
# including the bundled prebuilt libausaxs.so it ships in
# pyausaxs/resources/. See the RDEPEND blocker below for background.
SRC_URI="
	https://files.pythonhosted.org/packages/38/ea/c23c8062785752521061b40ca0c51229d4e73f36c6c81e69d28b6567bf43/${P}-py3-none-manylinux2014_x86_64.whl
"
S="${WORKDIR}"

LICENSE="LGPL-3+"
SLOT="0"
# x86 not supported; wheel is manylinux2014_x86_64.
KEYWORDS="~amd64"

REQUIRED_USE="${PYTHON_REQUIRED_USE}"

# Blocker on sci-libs/ausaxs:
#
# pyausaxs bundles a prebuilt libausaxs.so inside the wheel. In 1.0.4
# that library exposed test_integration, evaluate_sans_debye,
# fit_saxs, iterative_fit_start/step/finish as extern "C" symbols,
# while AUSAXS v1.2.1's public source tree exposed only test_integration
# and debye_no_ff — so a from-source libausaxs.so built from
# sci-libs/ausaxs could not satisfy pyausaxs's ctypes lookups and
# the init failed, dropping SasView onto its pure-Python fallback.
#
# 1.1.3 has not been re-verified against the current sci-libs/ausaxs
# symbol set (2026-04-24). Keep the mutual-exclusion blocker as a
# conservative default; drop it only after confirming that the
# bundled libausaxs.so symbols are a subset of what sci-libs/ausaxs
# provides.
RDEPEND="
	${PYTHON_DEPS}
	!sci-libs/ausaxs
	dev-python/py-cpuinfo[${PYTHON_USEDEP}]
	dev-python/numpy[${PYTHON_USEDEP}]
"
BDEPEND="app-arch/unzip"

src_unpack() {
	unzip -q "${DISTDIR}/${P}-py3-none-manylinux2014_x86_64.whl" -d "${S}" || die
}

_install_one() {
	python_domodule pyausaxs

	# Ship the .dist-info so importlib.metadata.version("pyausaxs")
	# and pip's view of the installed packages match upstream.
	local distinfo="${P/-/_}.dist-info"
	if [[ -d ${distinfo} ]]; then
		local sitedir
		sitedir=$(python_get_sitedir)
		mkdir -p "${D}${sitedir}" || die
		cp -r "${distinfo}" "${D}${sitedir}/" || die
	fi
}

src_install() {
	python_foreach_impl _install_one
}