1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-25 03:17:13 +00:00
nixpkgs/pkgs/development/tools/pyre/default.nix

134 lines
3.7 KiB
Nix
Raw Normal View History

2018-09-08 21:12:44 +01:00
{ stdenv, fetchFromGitHub, ocamlPackages, makeWrapper, writeScript
2018-09-05 17:11:47 +01:00
, dune, python3, rsync, fetchpatch }:
2018-07-11 00:20:17 +01:00
let
# Manually set version - the setup script requires
# hg and git + keeping the .git directory around.
2018-09-21 13:37:39 +01:00
pyre-version = "0.0.14";
2018-07-11 00:20:17 +01:00
versionFile = writeScript "version.ml" ''
cat > "./version.ml" <<EOF
2018-09-08 21:12:44 +01:00
open Core
2018-07-11 00:20:17 +01:00
let build_info () =
2018-09-08 21:12:44 +01:00
"pyre-nixpkgs ${pyre-version}"
2018-07-11 00:20:17 +01:00
let version () =
2018-09-08 21:12:44 +01:00
"${pyre-version}"
let log_version_banner () =
Log.info "Running as pid: %d" (Pid.to_int (Unix.getpid ()));
Log.info "Version: %s" (version ());
2018-07-11 00:20:17 +01:00
EOF
'';
2018-09-08 21:12:44 +01:00
pyre-bin = stdenv.mkDerivation {
name = "pyre-${pyre-version}";
2018-07-11 00:20:17 +01:00
src = fetchFromGitHub {
owner = "facebook";
repo = "pyre-check";
2018-09-08 21:12:44 +01:00
rev = "v${pyre-version}";
2018-09-21 13:37:39 +01:00
sha256 = "0c8xzaa3ljqb6llr041sydw0l4xqn7x21nw9vaymdxh35nx9bp2v";
2018-07-11 00:20:17 +01:00
};
nativeBuildInputs = [ makeWrapper ];
buildInputs = with ocamlPackages; [
ocaml
findlib
menhir
yojson
core
sedlex
ppx_deriving_yojson
ocamlbuild
ppxlib
2018-09-05 17:11:47 +01:00
dune
2018-09-08 21:12:44 +01:00
ounit
# python36Packages.python36Full # TODO
2018-07-11 00:20:17 +01:00
];
buildPhase = ''
# build requires HOME to be set
export HOME=.
# "external" because https://github.com/facebook/pyre-check/pull/8/files
cp Makefile.template Makefile
2018-09-08 21:12:44 +01:00
sed "s/%VERSION%/external/" dune.in > dune
2018-07-11 00:20:17 +01:00
cp ${versionFile} ./scripts/generate-version-number.sh
mkdir $(pwd)/build
export OCAMLFIND_DESTDIR=$(pwd)/build
export OCAMLPATH=$OCAMLPATH:$(pwd)/build
2018-09-08 21:12:44 +01:00
2018-07-11 00:20:17 +01:00
make release
'';
checkPhase = ''
make test
# ./scripts/run-python-tests.sh # TODO: once typeshed and python bits are added
2018-07-11 00:20:17 +01:00
'';
# Note that we're not installing the typeshed yet.
# Improvement for a future version.
installPhase = ''
mkdir -p $out/bin
2018-09-08 21:12:44 +01:00
cp ./_build/default/main.exe $out/bin/pyre.bin
2018-07-11 00:20:17 +01:00
'';
meta = with stdenv.lib; {
description = "A performant type-checker for Python 3";
homepage = https://pyre-check.org;
license = licenses.mit;
2018-11-02 03:29:18 +00:00
platforms = ocamlPackages.ocaml.meta.platforms;
2018-07-11 00:20:17 +01:00
maintainers = with maintainers; [ teh ];
};
2018-09-08 21:12:44 +01:00
};
typeshed = stdenv.mkDerivation {
name = "typeshed";
# typeshed doesn't have versions, it seems to be synchronized with
# mypy relases. I'm assigning a random version here (same as pyre).
version = pyre-version;
src = fetchFromGitHub {
owner = "python";
repo = "typeshed";
rev = "a08c6ea";
sha256 = "0wy8yh43vhyyc4g7iqnmlj66kz5in02y5qc0c4jdckhpa3mchaqk";
};
phases = [ "unpackPhase" "installPhase" ];
installPhase = "cp -r $src $out";
};
in python3.pkgs.buildPythonApplication rec {
pname = "pyre-check";
version = pyre-version;
src = fetchFromGitHub {
owner = "facebook";
repo = "pyre-check";
rev = "v${pyre-version}";
sha256 = "0ig7bx2kfn2kbxw74wysh5365yp5gyby42l9l29iclrzdghgk32l";
};
patches = [
(fetchpatch {
url = "https://github.com/facebook/pyre-check/commit/b473d2ed9fc11e7c1cd0c7b8c42f521e5cdc2003.patch";
sha256 = "05xvyp7j4n6z92bxf64rxfq5pvaadxgx1c8c5qziy75vdz72lkcy";
})
./pyre-bdist-wheel.patch
];
# The build-pypi-package script does some funky stuff with build
# directories - easier to patch it a bit than to replace it
# completely though:
postPatch = ''
mkdir ./build
substituteInPlace scripts/build-pypi-package.sh \
--replace 'NIX_BINARY_FILE' '${pyre-bin}/bin/pyre.bin' \
--replace 'BUILD_ROOT="$(mktemp -d)"' "BUILD_ROOT=$(pwd)/build"
'';
buildInputs = [ pyre-bin rsync ];
propagatedBuildInputs = with python3.pkgs; [ docutils typeshed ];
buildPhase = ''
bash scripts/build-pypi-package.sh --version ${pyre-version} --bundle-typeshed ${typeshed}
cp -r build/dist dist
'';
doCheck = false; # can't open file 'nix_run_setup':
2018-07-11 00:20:17 +01:00
}