Skip to content

Commit

Permalink
python3Packages.mypy: compile with mypyc
Browse files Browse the repository at this point in the history
Mypy includes mypyc, a compiler that translates annotated Python to C,
which can be compiled into a Python module. When mypy is compiled with
mypyc, it is about 4 times faster than the interpreted mypy, so using
the compiled version is especially useful on large codebases where
typechecking may take a long time.

The wheels distributed on Pypi have included a mypyc-compiled mypy by
default since version 0.700 [1].

[1]: http://mypy-lang.blogspot.com/2019/04/mypy-0700-released-up-to-4x-faster.html
  • Loading branch information
ruuda committed Nov 30, 2020
1 parent b86b6de commit ad26cb9
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions pkgs/development/python-modules/mypy/default.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
{ stdenv, fetchPypi, buildPythonPackage, typed-ast, psutil, isPy3k
{ stdenv, fetchFromGitHub, buildPythonPackage, typed-ast, psutil, isPy3k
, mypy-extensions
, typing-extensions
, fetchpatch
}:

buildPythonPackage rec {
pname = "mypy";
version = "0.790";
disabled = !isPy3k;

src = fetchPypi {
inherit pname version;
sha256 = "sha256-KyG6Ra2e8uLriM5K6t0BEtD1AmQYMkF2/UlKaCS3SXU=";
# Fetch 0.790 from GitHub temporarily because mypyc.analysis is missing from
# the Pip package (see also https://github.com/python/mypy/issues/9584). It
# should be possible to move back to Pypi for the next release.
src = fetchFromGitHub {
owner = "python";
repo = pname;
rev = "v${version}";
sha256 = "0zq3lpdf9hphcklk40wz444h8w3dkhwa12mqba5j9lmg11klnhz7";
fetchSubmodules = true;
};

propagatedBuildInputs = [ typed-ast psutil mypy-extensions typing-extensions ];
Expand All @@ -24,8 +30,31 @@ buildPythonPackage rec {
"mypy.api"
"mypy.fastparse"
"mypy.report"
"mypyc"
"mypyc.analysis"
];

# These three patches are required to make compilation with mypyc work for
# 0.790, see also https://github.com/python/mypy/issues/9584.
patches = [
(fetchpatch {
url = "https://github.com/python/mypy/commit/f6522ae646a8d87ce10549f29fcf961dc014f154.patch";
sha256 = "0d3jp4d0b7vdc0prk07grhajsy7x3wcynn2xysnszawiww93bfrh";
})
(fetchpatch {
url = "https://github.com/python/mypy/commit/acd603496237a78b109ca9d89991539633cbbb99.patch";
sha256 = "0ry1rxpz2ws7zzrmq09pra9dlzxb84zhs8kxwf5xii1k1bgmrljr";
})
(fetchpatch {
url = "https://github.com/python/mypy/commit/81818b23b5d53f31caf3515d6f0b54e3c018d790.patch";
sha256 = "002y24kfscywkw4mz9lndsps543j4xhr2kcnfbrqr4i0yxlvdbca";
})
];

# Compile mypy with mypyc, which makes mypy about 4 times faster. The compiled
# version is also the default in the wheels on Pypi that include binaries.
MYPY_USE_MYPYC = "1";

meta = with stdenv.lib; {
description = "Optional static typing for Python";
homepage = "http://www.mypy-lang.org";
Expand Down

0 comments on commit ad26cb9

Please sign in to comment.