dev-python/mypy: add native extensions support

mypy can compile itself via mypyc, which requires that it fully pass
mypy typechecking; this means we need to have type stubs for its runtime
dependencies.

Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
Closes: https://github.com/gentoo/gentoo/pull/32598
Signed-off-by: Michał Górny <mgorny@gentoo.org>
This commit is contained in:
Eli Schwartz
2023-09-03 23:51:17 -04:00
committed by Michał Górny
parent 42c823b79c
commit 88375f2b92
2 changed files with 45 additions and 3 deletions

View File

@@ -12,4 +12,11 @@
<bugs-to>https://github.com/python/mypy/issues</bugs-to>
<doc>https://mypy.readthedocs.io/</doc>
</upstream>
<use>
<flag name="native-extensions">
Compiles native C extensions (speedups, instead of using Python
fallback code).
</flag>
</use>
</pkgmetadata>

View File

@@ -3,6 +3,7 @@
EAPI=8
DISTUTILS_EXT=1
DISTUTILS_USE_PEP517=setuptools
PYTHON_COMPAT=( python3_{10..12} )
@@ -22,6 +23,7 @@ SRC_URI="
LICENSE="MIT"
SLOT="0"
KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86"
IUSE="+native-extensions"
# stubgen collides with this package: https://bugs.gentoo.org/585594
RDEPEND="
@@ -34,19 +36,33 @@ RDEPEND="
' 3.{9..10})
"
BDEPEND="
native-extensions? (
dev-python/types-psutil[${PYTHON_USEDEP}]
dev-python/types-setuptools[${PYTHON_USEDEP}]
)
test? (
>=dev-python/attrs-18.0[${PYTHON_USEDEP}]
>=dev-python/filelock-3.3.0[${PYTHON_USEDEP}]
>=dev-python/lxml-4.4.0[${PYTHON_USEDEP}]
>=dev-python/pytest-7.4.0[${PYTHON_USEDEP}]
>=dev-python/pytest-xdist-1.18[${PYTHON_USEDEP}]
>=dev-python/py-1.5.2[${PYTHON_USEDEP}]
dev-python/six[${PYTHON_USEDEP}]
>=dev-python/virtualenv-16.0.0[${PYTHON_USEDEP}]
)
"
distutils_enable_tests pytest
# this requires packaging a lot of type stubs
export MYPY_USE_MYPYC=0
# frustratingly, mypyc produces non-deterministic output. If ccache is enabled it will be a waste of time,
# but simultaneously it might trash your system and fill up the cache with a giant wave of non-reproducible
# test files
export CCACHE_DISABLE=1
src_compile() {
local -x MYPY_USE_MYPYC=$(usex native-extensions 1 0)
distutils-r1_src_compile
}
python_test() {
local EPYTEST_DESELECT=(
@@ -60,5 +76,24 @@ python_test() {
# Some mypy/test/testcmdline.py::PythonCmdlineSuite tests
# fail with high COLUMNS values
local -x COLUMNS=80
epytest -n "$(makeopts_jobs)" --dist=worksteal
# The tests depend on having in-source compiled extensions if you want to
# test those compiled extensions. Various crucial test dependencies aren't
# installed. Even pyproject.toml is needed because that's where pytest args
# are in. Hack them into the build directory and delete them afterwards.
# See: https://github.com/python/mypy/issues/16143
local -x MYPY_TEST_PREFIX="${S}"
cd "${BUILD_DIR}/install$(python_get_sitedir)" || die
cp -r "${S}"/{conftest.py,pyproject.toml} . || die
local failed=
nonfatal epytest -n "$(makeopts_jobs)" --dist=worksteal || failed=1
rm conftest.py pyproject.toml || die
# leftover test files
rm -r mypyc/lib-rt/build || die
rm mypyc/lib-rt/test_capi*.so || die
rm mypyc/external/googletest/make/*.[ao] || die
[[ ${failed} ]] && die "epytest failed with ${EPYTHON}"
}