at master 3.6 kB view raw
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.1"; 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-IzRKOReSgio5S5PG8iD9VQF9R1GEqBAIDeeCtq+ZVXg="; 44 }; 45 46 postPatch = '' 47 substituteInPlace \ 48 pyproject.toml \ 49 --replace-warn 'types-setuptools==' 'types-setuptools>=' 50 '' 51 # __closed__ returns None at runtime (not a bool) 52 + '' 53 substituteInPlace test-data/unit/lib-stub/typing_extensions.pyi \ 54 --replace-fail "__closed__: bool" "__closed__: None" 55 ''; 56 57 build-system = [ 58 basedtyping 59 mypy-extensions 60 types-psutil 61 types-setuptools 62 typing-extensions 63 ] 64 ++ lib.optionals (pythonOlder "3.11") [ tomli ]; 65 66 dependencies = [ 67 basedtyping 68 mypy-extensions 69 typing-extensions 70 ] 71 ++ lib.optionals (pythonOlder "3.11") [ tomli ]; 72 73 optional-dependencies = { 74 dmypy = [ psutil ]; 75 reports = [ lxml ]; 76 }; 77 78 # Compile mypy with mypyc, which makes mypy about 4 times faster. The compiled 79 # version is also the default in the wheels on Pypi that include binaries. 80 # is64bit: unfortunately the build would exhaust all possible memory on i686-linux. 81 env.MYPY_USE_MYPYC = stdenv.buildPlatform.is64bit; 82 83 # when testing reduce optimisation level to reduce build time by 20% 84 env.MYPYC_OPT_LEVEL = 1; 85 86 pythonImportsCheck = [ 87 "mypy" 88 "mypy.api" 89 "mypy.fastparse" 90 "mypy.types" 91 "mypyc" 92 "mypyc.analysis" 93 ] 94 ++ lib.optionals (!stdenv.hostPlatform.isi686) [ 95 # ImportError: cannot import name 'map_instance_to_supertype' from partially initialized module 'mypy.maptype' (most likely due to a circular import) 96 "mypy.report" 97 ]; 98 99 nativeCheckInputs = [ 100 attrs 101 filelock 102 pytest-xdist 103 pytestCheckHook 104 setuptools 105 tomli 106 ] 107 ++ lib.flatten (lib.attrValues optional-dependencies); 108 109 disabledTests = lib.optionals (pythonAtLeast "3.12") [ 110 # cannot find distutils, and distutils cannot find types 111 # https://github.com/NixOS/nixpkgs/pull/364818#discussion_r1895715378 112 "test_c_unit_test" 113 ]; 114 115 disabledTestPaths = [ 116 # fails to find typing_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 lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64 && pythonOlder "3.13") 130 [ 131 # mypy/test/testsolve.py::SolveSuite::test_simple_constraints_with_dynamic_type: [Any | A] != [Any] 132 "mypy/test/testsolve.py" 133 ]; 134 135 passthru.updateScript = nix-update-script { }; 136 137 meta = { 138 description = "Based Python static type checker with baseline, sane default settings and based typing features"; 139 homepage = "https://kotlinisland.github.io/basedmypy/"; 140 changelog = "https://github.com/KotlinIsland/basedmypy/blob/${src.tag}/CHANGELOG.md"; 141 license = lib.licenses.mit; 142 mainProgram = "mypy"; 143 maintainers = with lib.maintainers; [ perchun ]; 144 }; 145}