commit:     88375f2b92ba6c710b1d3eef9210ef21f83ccd66
Author:     Eli Schwartz <eschwartz93 <AT> gmail <DOT> com>
AuthorDate: Mon Sep  4 03:51:17 2023 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Tue Oct 10 20:47:18 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=88375f2b

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 <AT> gmail.com>
Closes: https://github.com/gentoo/gentoo/pull/32598
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 dev-python/mypy/metadata.xml      |  7 +++++++
 dev-python/mypy/mypy-1.6.0.ebuild | 41 ++++++++++++++++++++++++++++++++++++---
 2 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/dev-python/mypy/metadata.xml b/dev-python/mypy/metadata.xml
index 01c4182eef50..4d450db3cd4d 100644
--- a/dev-python/mypy/metadata.xml
+++ b/dev-python/mypy/metadata.xml
@@ -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>

diff --git a/dev-python/mypy/mypy-1.6.0.ebuild 
b/dev-python/mypy/mypy-1.6.0.ebuild
index de2eae6aae16..7259aa487598 100644
--- a/dev-python/mypy/mypy-1.6.0.ebuild
+++ b/dev-python/mypy/mypy-1.6.0.ebuild
@@ -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}"
 }

Reply via email to