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

EAPI=8

DISTUTILS_EXT=1
DISTUTILS_USE_PEP517=standalone
PYTHON_COMPAT=( python3_13 )

inherit distutils-r1

DESCRIPTION="Tensors and dynamic neural networks with bundled ROCm 6.4 libraries"
HOMEPAGE="https://pytorch.org/"
MY_WHEEL="torch-${PV}+rocm6.4-cp313-cp313-manylinux_2_28_x86_64.whl"
SRC_URI="https://download.pytorch.org/whl/rocm6.4/${MY_WHEEL/+/%2B} -> ${MY_WHEEL}"
S=${WORKDIR}

LICENSE="Apache-2.0 BSD BSD-2 Boost-1.0 MIT public-domain"
SLOT="0"
KEYWORDS="~amd64"
RESTRICT="strip"

BDEPEND="app-arch/unzip"
DOCS=( licenses )

RDEPEND="
	dev-python/filelock[${PYTHON_USEDEP}]
	dev-python/fsspec[${PYTHON_USEDEP}]
	dev-python/jinja2[${PYTHON_USEDEP}]
	dev-python/networkx[${PYTHON_USEDEP}]
	~dev-python/pytorch-triton-rocm-3.4.0[${PYTHON_USEDEP}]
	dev-python/setuptools[${PYTHON_USEDEP}]
	>=dev-python/sympy-1.13.3[${PYTHON_USEDEP}]
	>=dev-python/typing-extensions-4.10.0[${PYTHON_USEDEP}]
	sys-devel/gcc:*
	virtual/zlib
"

QA_PREBUILT=( "usr/lib/python*/site-packages/*" )

src_unpack() {
	unzip -j "${DISTDIR}/${MY_WHEEL}" '*.dist-info/licenses/*' -d licenses || die
}

python_compile() {
	distutils_wheel_install "${BUILD_DIR}/install" "${DISTDIR}/${MY_WHEEL}"
}