# 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="Language and compiler for custom GPU kernels with AMD and NVIDIA backends"
HOMEPAGE="https://triton-lang.org/ https://github.com/triton-lang/triton/"
MY_WHEEL="${P}-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl"
SRC_URI="https://download.pytorch.org/whl/${MY_WHEEL}"
S=${WORKDIR}

LICENSE="MIT Apache-2.0-with-LLVM-exceptions NVIDIA-CUDA"
SLOT="0"
KEYWORDS="~amd64"
IUSE="+rocm"
RESTRICT="bindist mirror strip"

BDEPEND="app-arch/unzip"
RDEPEND="
	rocm? ( >=dev-util/hip-7.2 )
	sys-devel/gcc:*
	virtual/zlib
"

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

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

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