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