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