1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 nix-update-script,
6 pythonAtLeast,
7 pythonOlder,
8 stdenv,
9
10 # build-system
11 setuptools,
12 types-psutil,
13 types-setuptools,
14
15 # propagates
16 basedtyping,
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}:
31
32buildPythonPackage rec {
33 pname = "basedmypy";
34 version = "2.10.0";
35 pyproject = true;
36
37 disabled = pythonOlder "3.8";
38
39 src = fetchFromGitHub {
40 owner = "KotlinIsland";
41 repo = "basedmypy";
42 tag = "v${version}";
43 hash = "sha256-/43wVQoW/BbRD8j8Oypq5yz79ZTyAkLD4T8/aUg/QT8=";
44 };
45
46 postPatch = ''
47 substituteInPlace \
48 pyproject.toml \
49 --replace-warn 'types-setuptools==' 'types-setuptools>='
50 '';
51
52 build-system = [
53 basedtyping
54 mypy-extensions
55 types-psutil
56 types-setuptools
57 typing-extensions
58 ] ++ lib.optionals (pythonOlder "3.11") [ tomli ];
59
60 dependencies = [
61 basedtyping
62 mypy-extensions
63 typing-extensions
64 ] ++ lib.optionals (pythonOlder "3.11") [ tomli ];
65
66 optional-dependencies = {
67 dmypy = [ psutil ];
68 reports = [ lxml ];
69 };
70
71 # Compile mypy with mypyc, which makes mypy about 4 times faster. The compiled
72 # version is also the default in the wheels on Pypi that include binaries.
73 # is64bit: unfortunately the build would exhaust all possible memory on i686-linux.
74 env.MYPY_USE_MYPYC = stdenv.buildPlatform.is64bit;
75
76 # when testing reduce optimisation level to reduce build time by 20%
77 env.MYPYC_OPT_LEVEL = 1;
78
79 pythonImportsCheck =
80 [
81 "mypy"
82 "mypy.api"
83 "mypy.fastparse"
84 "mypy.types"
85 "mypyc"
86 "mypyc.analysis"
87 ]
88 ++ lib.optionals (!stdenv.hostPlatform.isi686) [
89 # ImportError: cannot import name 'map_instance_to_supertype' from partially initialized module 'mypy.maptype' (most likely due to a circular import)
90 "mypy.report"
91 ];
92
93 nativeCheckInputs = [
94 attrs
95 filelock
96 pytest-xdist
97 pytestCheckHook
98 setuptools
99 tomli
100 ] ++ lib.flatten (lib.attrValues optional-dependencies);
101
102 disabledTests = lib.optionals (pythonAtLeast "3.12") [
103 # cannot find distutils, and distutils cannot find types
104 # https://github.com/NixOS/nixpkgs/pull/364818#discussion_r1895715378
105 "test_c_unit_test"
106 ];
107
108 disabledTestPaths =
109 [
110 # fails to find typing_extensions
111 "mypy/test/testcmdline.py"
112 "mypy/test/testdaemon.py"
113 # fails to find setuptools
114 "mypyc/test/test_commandline.py"
115 # fails to find hatchling
116 "mypy/test/testpep561.py"
117 ]
118 ++ lib.optionals stdenv.hostPlatform.isi686 [
119 # https://github.com/python/mypy/issues/15221
120 "mypyc/test/test_run.py"
121 ];
122
123 passthru.updateScript = nix-update-script { };
124
125 meta = {
126 description = "Based Python static type checker with baseline, sane default settings and based typing features";
127 homepage = "https://kotlinisland.github.io/basedmypy/";
128 changelog = "https://github.com/KotlinIsland/basedmypy/blob/${src.tag}/CHANGELOG.md";
129 license = lib.licenses.mit;
130 mainProgram = "mypy";
131 maintainers = with lib.maintainers; [ perchun ];
132 };
133}