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