|
| 1 | +# Copyright 1999-2024 Gentoo Authors |
| 2 | +# Distributed under the terms of the GNU General Public License v2 |
| 3 | + |
| 4 | +EAPI=8 |
| 5 | + |
| 6 | +DISTUTILS_EXT=1 |
| 7 | +DISTUTILS_USE_PEP517=setuptools |
| 8 | +PYTHON_COMPAT=( python3_{11..13} ) |
| 9 | +MY_PV=${PV/_alpha/a} |
| 10 | +inherit distutils-r1 pypi multiprocessing |
| 11 | +DESCRIPTION="Optional static typing for Python" |
| 12 | +HOMEPAGE=" |
| 13 | + https://www.mypy-lang.org/ |
| 14 | + https://github.com/python/mypy/ |
| 15 | + https://pypi.org/project/mypy/ |
| 16 | + https://github.com/cdce8p/mypy-dev https://pypi.org/project/mypy-dev/ |
| 17 | +" |
| 18 | +SRC_URI="$(pypi_sdist_url "${PN}" "${MY_PV}")" |
| 19 | + |
| 20 | +LICENSE="MIT" |
| 21 | +SLOT="0" |
| 22 | +KEYWORDS="amd64 arm arm64 x86" |
| 23 | +IUSE="+native-extensions test" |
| 24 | +RESTRICT="!test? ( test )" |
| 25 | +DOCS="README.md" |
| 26 | + |
| 27 | +# stubgen collides with this package: https://bugs.gentoo.org/585594 |
| 28 | +RDEPEND=" |
| 29 | + !dev-util/stubgen |
| 30 | + >=dev-python/psutil-4[${PYTHON_USEDEP}] |
| 31 | + >=dev-python/typing-extensions-4.1.0[${PYTHON_USEDEP}] |
| 32 | + >=dev-python/mypy_extensions-1.0.0[${PYTHON_USEDEP}] |
| 33 | + $(python_gen_cond_dep ' |
| 34 | + dev-python/tomli[${PYTHON_USEDEP}] |
| 35 | + ' 3.10) |
| 36 | +" |
| 37 | +BDEPEND=" |
| 38 | + native-extensions? ( |
| 39 | + ${RDEPEND} |
| 40 | + dev-python/types-psutil[${PYTHON_USEDEP}] |
| 41 | + dev-python/types-setuptools[${PYTHON_USEDEP}] |
| 42 | + ) |
| 43 | + test? ( |
| 44 | + >=dev-python/attrs-18.0[${PYTHON_USEDEP}] |
| 45 | + >=dev-python/filelock-3.3.0[${PYTHON_USEDEP}] |
| 46 | + >=dev-python/lxml-4.9.1[${PYTHON_USEDEP}] |
| 47 | + ) |
| 48 | +" |
| 49 | + |
| 50 | +EPYTEST_XDIST=1 |
| 51 | +distutils_enable_tests pytest |
| 52 | + |
| 53 | +# frustratingly, mypyc produces non-deterministic output. If ccache is enabled it will be a waste of time, |
| 54 | +# but simultaneously it might trash your system and fill up the cache with a giant wave of non-reproducible |
| 55 | +# test files (https://github.com/mypyc/mypyc/issues/1014) |
| 56 | +export CCACHE_DISABLE=1 |
| 57 | + |
| 58 | +src_compile() { |
| 59 | + local -x MYPY_USE_MYPYC=$(usex native-extensions 1 0) |
| 60 | + distutils-r1_src_compile |
| 61 | +} |
| 62 | + |
| 63 | +python_test() { |
| 64 | + local EPYTEST_DESELECT=( |
| 65 | + # the majority of them require Internet (via pip) |
| 66 | + mypy/test/testpep561.py |
| 67 | + # known broken with assertions enabled |
| 68 | + # https://github.com/python/mypy/issues/16043 |
| 69 | + mypyc/test/test_run.py::TestRun::run-i64.test::testI64GlueMethodsAndInheritance |
| 70 | + mypyc/test/test_run.py::TestRun::run-floats.test::testFloatOps |
| 71 | + # these assume that types-docutils are not installed |
| 72 | + mypy/test/testpythoneval.py::PythonEvaluationSuite::pythoneval.test::testIgnoreImportIfNoPython3StubAvailable |
| 73 | + mypy/test/testpythoneval.py::PythonEvaluationSuite::pythoneval.test::testNoPython3StubAvailable |
| 74 | + # TODO |
| 75 | + mypy/test/meta/test_parse_data.py |
| 76 | + mypy/test/meta/test_update_data.py |
| 77 | + mypy/test/teststubtest.py::StubtestUnit::test_runtime_typing_objects |
| 78 | + ) |
| 79 | + case ${EPYTHON} in |
| 80 | + python3.12) |
| 81 | + EPYTEST_DESELECT+=( |
| 82 | + # more assertions, sigh |
| 83 | + mypyc/test/test_run.py::TestRun::run-bools.test::testBoolOps |
| 84 | + mypyc/test/test_run.py::TestRun::run-i64.test::testI64BasicOps |
| 85 | + mypyc/test/test_run.py::TestRun::run-i64.test::testI64DefaultArgValues |
| 86 | + mypyc/test/test_run.py::TestRun::run-i64.test::testI64ErrorValuesAndUndefined |
| 87 | + ) |
| 88 | + ;; |
| 89 | + esac |
| 90 | + |
| 91 | + # Some mypy/test/testcmdline.py::PythonCmdlineSuite tests |
| 92 | + # fail with high COLUMNS values |
| 93 | + local -x COLUMNS=80 |
| 94 | + |
| 95 | + # The tests depend on having in-source compiled extensions if you want to |
| 96 | + # test those compiled extensions. Various crucial test dependencies aren't |
| 97 | + # installed. Even pyproject.toml is needed because that's where pytest args |
| 98 | + # are in. Hack them into the build directory and delete them afterwards. |
| 99 | + # See: https://github.com/python/mypy/issues/16143 |
| 100 | + local -x MYPY_TEST_PREFIX="${S}" |
| 101 | + cd "${BUILD_DIR}/install$(python_get_sitedir)" || die |
| 102 | + cp -r "${S}"/{conftest.py,pyproject.toml} . || die |
| 103 | + |
| 104 | + local failed= |
| 105 | + local -x PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 |
| 106 | + nonfatal epytest -n "$(makeopts_jobs)" --dist=worksteal || failed=1 |
| 107 | + |
| 108 | + rm conftest.py pyproject.toml || die |
| 109 | + |
| 110 | + [[ ${failed} ]] && die "epytest failed with ${EPYTHON}" |
| 111 | +} |
0 commit comments