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

EAPI=8

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

inherit distutils-r1 pypi xdg

DESCRIPTION="Small-angle scattering data analysis application"
HOMEPAGE="
	https://www.sasview.org/
	https://github.com/SasView/sasview
	https://pypi.org/project/sasview/
"

LICENSE="BSD"
SLOT="0"
KEYWORDS="~amd64 ~arm64"
IUSE="opencl"

RDEPEND="
	amd64? ( dev-python/pyausaxs[${PYTHON_USEDEP}] )
	dev-python/bumps[${PYTHON_USEDEP}]
	dev-python/cffi[${PYTHON_USEDEP}]
	dev-python/docutils[${PYTHON_USEDEP}]
	dev-python/dominate[${PYTHON_USEDEP}]
	dev-python/h5py[${PYTHON_USEDEP}]
	dev-python/html2text[${PYTHON_USEDEP}]
	dev-python/html5lib[${PYTHON_USEDEP}]
	dev-python/ipython[${PYTHON_USEDEP}]
	dev-python/jsonschema[${PYTHON_USEDEP}]
	dev-python/lxml[${PYTHON_USEDEP}]
	dev-python/mako[${PYTHON_USEDEP}]
	dev-python/matplotlib[${PYTHON_USEDEP}]
	dev-python/numba[${PYTHON_USEDEP}]
	dev-python/numpy[${PYTHON_USEDEP}]
	dev-python/packaging[${PYTHON_USEDEP}]
	dev-python/periodictable[${PYTHON_USEDEP}]
	dev-python/platformdirs[${PYTHON_USEDEP}]
	dev-python/pybind11[${PYTHON_USEDEP}]
	dev-python/pylint[${PYTHON_USEDEP}]
	dev-python/pyopengl[${PYTHON_USEDEP}]
	dev-python/pyparsing[${PYTHON_USEDEP}]
	dev-python/pyside[${PYTHON_USEDEP},datavis(-),qml,quick,webchannel,webengine]
	dev-python/pytools[${PYTHON_USEDEP}]
	dev-python/qtconsole[${PYTHON_USEDEP}]
	dev-python/requests[${PYTHON_USEDEP}]
	dev-python/sasdata[${PYTHON_USEDEP}]
	dev-python/sasmodels[${PYTHON_USEDEP}]
	dev-python/scipy[${PYTHON_USEDEP}]
	dev-python/setuptools[${PYTHON_USEDEP}]
	dev-python/siphash24[${PYTHON_USEDEP}]
	dev-python/superqt[${PYTHON_USEDEP}]
	dev-python/tccbox[${PYTHON_USEDEP}]
	dev-python/twisted[${PYTHON_USEDEP}]
	dev-python/uncertainties[${PYTHON_USEDEP}]
	dev-python/zope-interface[${PYTHON_USEDEP}]
	opencl? ( dev-python/pyopencl[${PYTHON_USEDEP}] )
"
BDEPEND="
	dev-python/hatch-build-scripts[${PYTHON_USEDEP}]
	dev-python/hatch-requirements-txt[${PYTHON_USEDEP}]
	dev-python/hatch-sphinx[${PYTHON_USEDEP}]
	dev-python/hatch-vcs[${PYTHON_USEDEP}]
	dev-python/pyside[${PYTHON_USEDEP},datavis(-),qml,quick,tools,webchannel,webengine]
"

# Omit soft xhtml2pdf: only PDF export needs its large pyHanko stack.
# pyausaxs accelerates SANS Debye on amd64; its x86-64-only binary leaves other
# architectures on SasView's Python fallback. # verified 2026-07-31

src_prepare() {
	# Normalize CRLF so the following $-anchored table matches work.
	# verified 2026-07-31
	sed -i -e 's/\r$//' pyproject.toml build_tools/requirements.txt || die

	# Stop at the next regular table, preserving consecutive array tables.
	sed -i \
		-e '/^\[\[tool\.hatch\.build\.targets\.wheel\.hooks\.sphinx/,/^\[[^[]/{/^\[[^[]/!d}' \
		pyproject.toml || die

	# Nothing in this build produces the force-included sas/docs tree.
	sed -i \
		-e '/^\[tool\.hatch\.build\.targets\.wheel\.force-include\]$/,/^\[/{/build\/doc\/html/d}' \
		pyproject.toml || die

	# xhtml2pdf and pywin32 intentionally dropped from build_tools/requirements.txt
	sed -i \
		-e '/^xhtml2pdf$/d' \
		-e '/^pywin32;/d' \
		build_tools/requirements.txt || die

	distutils-r1_src_prepare
}