Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 142 lines 3.2 kB view raw
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 ] 61 ++ lib.optionals (pythonOlder "3.11") [ tomli ]; 62 63 dependencies = [ 64 mypy-extensions 65 typing-extensions 66 ] 67 ++ lib.optionals (pythonOlder "3.11") [ tomli ]; 68 69 optional-dependencies = { 70 dmypy = [ psutil ]; 71 reports = [ lxml ]; 72 }; 73 74 # Compile mypy with mypyc, which makes mypy about 4 times faster. The compiled 75 # version is also the default in the wheels on Pypi that include binaries. 76 # is64bit: unfortunately the build would exhaust all possible memory on i686-linux. 77 env.MYPY_USE_MYPYC = stdenv.buildPlatform.is64bit; 78 79 # when testing reduce optimisation level to reduce build time by 20% 80 env.MYPYC_OPT_LEVEL = 1; 81 82 pythonImportsCheck = [ 83 "mypy" 84 "mypy.api" 85 "mypy.fastparse" 86 "mypy.types" 87 "mypyc" 88 "mypyc.analysis" 89 ] 90 ++ lib.optionals (!stdenv.hostPlatform.isi686) [ 91 # ImportError: cannot import name 'map_instance_to_supertype' from partially initialized module 'mypy.maptype' (most likely due to a circular import) 92 "mypy.report" 93 ]; 94 95 nativeCheckInputs = [ 96 attrs 97 filelock 98 pytest-xdist 99 pytestCheckHook 100 setuptools 101 tomli 102 ] 103 ++ lib.flatten (lib.attrValues optional-dependencies); 104 105 disabledTests = [ 106 # fails with typing-extensions>=4.10 107 # https://github.com/python/mypy/issues/17005 108 "test_runtime_typing_objects" 109 ] 110 ++ lib.optionals (pythonAtLeast "3.12") [ 111 # requires distutils 112 "test_c_unit_test" 113 ]; 114 115 disabledTestPaths = [ 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}