Files
nixpkgs/pkgs/development/python-modules/mypy/default.nix
Maximilian Bosch 31bb833ca2 python3Packages.mypy: fix build w/ glibc-2.44
Otherwiwse a bunch of tests break with
"warning: ‘_POSIX_C_SOURCE’ redefined".

Apparently this now happens, if software doesn't adhere to the rule of
`Python.h` having to be included first[1]. The applied patch focuses on
Python 3.15 support, but also happens to fix that.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=2416110
2026-09-19 16:43:49 +02:00

170 lines
3.9 KiB
Nix

{
lib,
stdenv,
buildPythonPackage,
fetchFromGitHub,
gitUpdater,
pythonAtLeast,
isPyPy,
fetchpatch,
# build-system
pathspec,
setuptools,
types-psutil,
types-setuptools,
ast-serialize,
# nativeBuildInputs + propagates
librt,
# propagates
mypy-extensions,
tomli,
typing-extensions,
# optionals
lxml,
psutil,
# tests
attrs,
filelock,
pytest-xdist,
pytestCheckHook,
nixosTests,
}:
buildPythonPackage rec {
pname = "mypy";
version = "2.1.0";
pyproject = true;
# relies on several CPython internals
disabled = isPyPy;
src = fetchFromGitHub {
owner = "python";
repo = "mypy";
tag = "v${version}";
hash = "sha256-sm/pxQGxH5XuPH7B8i3fpp30KaFU9aSp6BT67UcDPvU=";
};
patches = [
# fix build w/ glibc-2.44
# If Python.h isn't included first, a const redefinition error now occurs otherwise.
(fetchpatch {
url = "https://github.com/python/mypy/commit/46acbe85c0e1703ebf2e6d4c699772edcdcf4652.patch";
hash = "sha256-KslHiKqinvvXZoxvCnZXOhCm7i8577PbSdNGudCsjZE=";
})
];
passthru.updateScript = gitUpdater {
rev-prefix = "v";
};
nativeBuildInputs = [
librt
];
build-system = [
mypy-extensions
pathspec
setuptools
types-psutil
types-setuptools
typing-extensions
ast-serialize
];
dependencies = [
librt
mypy-extensions
pathspec
typing-extensions
];
optional-dependencies = {
dmypy = [ psutil ];
reports = [ lxml ];
};
# Compile mypy with mypyc, which makes mypy about 4 times faster. The compiled
# version is also the default in the wheels on Pypi that include binaries.
# is64bit: unfortunately the build would exhaust all possible memory on i686-linux.
env.MYPY_USE_MYPYC = stdenv.buildPlatform.is64bit;
# when testing reduce optimisation level to reduce build time by 20%
env.MYPYC_OPT_LEVEL = 1;
pythonImportsCheck = [
"mypy"
"mypy.api"
"mypy.fastparse"
"mypy.types"
"mypyc"
"mypyc.analysis"
]
++ lib.optionals (!stdenv.hostPlatform.isi686) [
# ImportError: cannot import name 'map_instance_to_supertype' from partially initialized module 'mypy.maptype' (most likely due to a circular import)
"mypy.report"
];
nativeCheckInputs = [
attrs
filelock
pytest-xdist
pytestCheckHook
setuptools
tomli
]
++ lib.concatAttrValues optional-dependencies;
disabledTests = [
# A change to the base64 decoder in CPython 3.13.13 and 3.14.4 causes this
# test to fail. At the time of writing, upstream skips the test.
# Upstream issue: https://github.com/python/mypy/issues/21120
# CPython issue: https://github.com/python/cpython/issues/145264
"testAllBase64Features_librt_experimental"
# https://github.com/python/mypy/issues/21120
"testAllBase64Features_librt"
# fails to import librt
"test_diff_cache_produces_valid_json"
]
++ lib.optionals (pythonAtLeast "3.12") [
# requires distutils
"test_c_unit_test"
];
disabledTestPaths = [
# circular dependency on distutils
"mypyc/test/test_external.py"
# fails to find typing_extensions
"mypy/test/testcmdline.py"
"mypy/test/testdaemon.py"
# fails to find setuptools
"mypyc/test/test_commandline.py"
# fails to find hatchling
"mypy/test/testpep561.py"
]
++ lib.optionals stdenv.hostPlatform.isi686 [
# https://github.com/python/mypy/issues/15221
"mypyc/test/test_run.py"
];
passthru.tests = {
# Failing typing checks on the test-driver result in channel blockers.
inherit (nixosTests) nixos-test-driver;
};
meta = {
description = "Optional static typing for Python";
homepage = "https://www.mypy-lang.org";
changelog = "https://github.com/python/mypy/blob/${src.rev}/CHANGELOG.md";
downloadPage = "https://github.com/python/mypy";
license = lib.licenses.mit;
mainProgram = "mypy";
maintainers = [ ];
};
}