nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 gitUpdater,
7 pythonAtLeast,
8 pythonOlder,
9 isPyPy,
10
11 # build-system
12 setuptools,
13 types-psutil,
14 types-setuptools,
15 wheel,
16
17 # propagates
18 mypy-extensions,
19 tomli,
20 typing-extensions,
21
22 # optionals
23 lxml,
24 psutil,
25
26 # tests
27 attrs,
28 filelock,
29 pytest-xdist,
30 pytestCheckHook,
31 nixosTests,
32}:
33
34buildPythonPackage rec {
35 pname = "mypy";
36 version = "1.15.0";
37 pyproject = true;
38
39 # relies on several CPython internals
40 disabled = pythonOlder "3.8" || isPyPy;
41
42 src = fetchFromGitHub {
43 owner = "python";
44 repo = "mypy";
45 tag = "v${version}";
46 hash = "sha256-y67kt5i8mT9TcSbUGwnNuTAeqjy9apvWIbA2QD96LS4=";
47 };
48
49 passthru.updateScript = gitUpdater {
50 rev-prefix = "v";
51 };
52
53 build-system = [
54 mypy-extensions
55 setuptools
56 types-psutil
57 types-setuptools
58 typing-extensions
59 wheel
60 ] ++ lib.optionals (pythonOlder "3.11") [ tomli ];
61
62 dependencies = [
63 mypy-extensions
64 typing-extensions
65 ] ++ lib.optionals (pythonOlder "3.11") [ tomli ];
66
67 optional-dependencies = {
68 dmypy = [ psutil ];
69 reports = [ lxml ];
70 };
71
72 # Compile mypy with mypyc, which makes mypy about 4 times faster. The compiled
73 # version is also the default in the wheels on Pypi that include binaries.
74 # is64bit: unfortunately the build would exhaust all possible memory on i686-linux.
75 env.MYPY_USE_MYPYC = stdenv.buildPlatform.is64bit;
76
77 # when testing reduce optimisation level to reduce build time by 20%
78 env.MYPYC_OPT_LEVEL = 1;
79
80 pythonImportsCheck =
81 [
82 "mypy"
83 "mypy.api"
84 "mypy.fastparse"
85 "mypy.types"
86 "mypyc"
87 "mypyc.analysis"
88 ]
89 ++ lib.optionals (!stdenv.hostPlatform.isi686) [
90 # ImportError: cannot import name 'map_instance_to_supertype' from partially initialized module 'mypy.maptype' (most likely due to a circular import)
91 "mypy.report"
92 ];
93
94 nativeCheckInputs = [
95 attrs
96 filelock
97 pytest-xdist
98 pytestCheckHook
99 setuptools
100 tomli
101 ] ++ lib.flatten (lib.attrValues optional-dependencies);
102
103 disabledTests =
104 [
105 # fails with typing-extensions>=4.10
106 # https://github.com/python/mypy/issues/17005
107 "test_runtime_typing_objects"
108 ]
109 ++ lib.optionals (pythonAtLeast "3.12") [
110 # requires distutils
111 "test_c_unit_test"
112 ];
113
114 disabledTestPaths =
115 [
116 # fails to find tyoing_extensions
117 "mypy/test/testcmdline.py"
118 "mypy/test/testdaemon.py"
119 # fails to find setuptools
120 "mypyc/test/test_commandline.py"
121 # fails to find hatchling
122 "mypy/test/testpep561.py"
123 ]
124 ++ lib.optionals stdenv.hostPlatform.isi686 [
125 # https://github.com/python/mypy/issues/15221
126 "mypyc/test/test_run.py"
127 ];
128
129 passthru.tests = {
130 # Failing typing checks on the test-driver result in channel blockers.
131 inherit (nixosTests) nixos-test-driver;
132 };
133
134 meta = {
135 description = "Optional static typing for Python";
136 homepage = "https://www.mypy-lang.org";
137 changelog = "https://github.com/python/mypy/blob/${src.rev}/CHANGELOG.md";
138 license = lib.licenses.mit;
139 mainProgram = "mypy";
140 maintainers = with lib.maintainers; [ lnl7 ];
141 };
142}