2018-12-21 14:22:08 +01:00
|
|
|
{ stdenv, fetchFromGitHub, ocamlPackages, writeScript
|
|
|
|
, dune, python3, rsync, buck, watchman }:
|
2018-07-11 01:20:17 +02:00
|
|
|
let
|
|
|
|
# Manually set version - the setup script requires
|
|
|
|
# hg and git + keeping the .git directory around.
|
2019-01-31 16:36:36 +01:00
|
|
|
pyre-version = "0.0.20"; # also change typeshed revision below with $pyre-src/.typeshed-version
|
2018-11-02 12:42:05 +01:00
|
|
|
pyre-src = fetchFromGitHub {
|
|
|
|
owner = "facebook";
|
|
|
|
repo = "pyre-check";
|
|
|
|
rev = "v${pyre-version}";
|
2019-01-31 16:36:36 +01:00
|
|
|
sha256 = "1alkhdhvmigdhxvvarh0lr5s3b1s6q4arykip2dqb62vs8064s17";
|
2018-11-02 12:42:05 +01:00
|
|
|
};
|
2018-07-11 01:20:17 +02:00
|
|
|
versionFile = writeScript "version.ml" ''
|
|
|
|
cat > "./version.ml" <<EOF
|
2018-09-08 22:12:44 +02:00
|
|
|
open Core
|
2018-07-11 01:20:17 +02:00
|
|
|
let build_info () =
|
2018-09-08 22:12:44 +02:00
|
|
|
"pyre-nixpkgs ${pyre-version}"
|
2018-07-11 01:20:17 +02:00
|
|
|
let version () =
|
2018-09-08 22:12:44 +02:00
|
|
|
"${pyre-version}"
|
|
|
|
|
|
|
|
let log_version_banner () =
|
|
|
|
Log.info "Running as pid: %d" (Pid.to_int (Unix.getpid ()));
|
|
|
|
Log.info "Version: %s" (version ());
|
2018-12-03 02:26:22 +01:00
|
|
|
Log.info "Build info: %s" (build_info ())
|
2018-07-11 01:20:17 +02:00
|
|
|
EOF
|
|
|
|
'';
|
2018-09-08 22:12:44 +02:00
|
|
|
pyre-bin = stdenv.mkDerivation {
|
|
|
|
name = "pyre-${pyre-version}";
|
2018-07-11 01:20:17 +02:00
|
|
|
|
2018-11-02 12:42:05 +01:00
|
|
|
src = pyre-src;
|
2018-07-11 01:20:17 +02:00
|
|
|
|
|
|
|
buildInputs = with ocamlPackages; [
|
|
|
|
ocaml
|
|
|
|
findlib
|
|
|
|
menhir
|
|
|
|
yojson
|
|
|
|
core
|
|
|
|
sedlex
|
|
|
|
ppx_deriving_yojson
|
|
|
|
ocamlbuild
|
|
|
|
ppxlib
|
2018-09-05 18:11:47 +02:00
|
|
|
dune
|
2018-09-08 22:12:44 +02:00
|
|
|
ounit
|
2018-07-29 21:29:29 +02:00
|
|
|
# python36Packages.python36Full # TODO
|
2018-07-11 01:20:17 +02:00
|
|
|
];
|
|
|
|
|
2018-12-03 09:19:28 +01:00
|
|
|
preBuild = ''
|
2018-07-11 01:20:17 +02:00
|
|
|
# build requires HOME to be set
|
2018-12-03 09:19:28 +01:00
|
|
|
export HOME=$TMPDIR
|
2018-07-11 01:20:17 +02:00
|
|
|
|
|
|
|
# "external" because https://github.com/facebook/pyre-check/pull/8/files
|
2018-09-08 22:12:44 +02:00
|
|
|
sed "s/%VERSION%/external/" dune.in > dune
|
2018-07-11 01:20:17 +02:00
|
|
|
|
2018-12-03 09:19:28 +01:00
|
|
|
ln -sf ${versionFile} ./scripts/generate-version-number.sh
|
2018-07-11 01:20:17 +02:00
|
|
|
|
|
|
|
mkdir $(pwd)/build
|
|
|
|
export OCAMLFIND_DESTDIR=$(pwd)/build
|
|
|
|
export OCAMLPATH=$OCAMLPATH:$(pwd)/build
|
|
|
|
'';
|
|
|
|
|
2018-12-03 09:19:28 +01:00
|
|
|
buildFlags = [ "release" ];
|
|
|
|
|
|
|
|
doCheck = true;
|
|
|
|
# ./scripts/run-python-tests.sh # TODO: once typeshed and python bits are added
|
2018-07-11 01:20:17 +02:00
|
|
|
|
|
|
|
# Note that we're not installing the typeshed yet.
|
|
|
|
# Improvement for a future version.
|
|
|
|
installPhase = ''
|
2018-12-03 09:19:28 +01:00
|
|
|
install -D ./_build/default/main.exe $out/bin/pyre.bin
|
2018-07-11 01:20:17 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with stdenv.lib; {
|
|
|
|
description = "A performant type-checker for Python 3";
|
|
|
|
homepage = https://pyre-check.org;
|
|
|
|
license = licenses.mit;
|
2018-11-02 04:29:18 +01:00
|
|
|
platforms = ocamlPackages.ocaml.meta.platforms;
|
2018-07-11 01:20:17 +02:00
|
|
|
maintainers = with maintainers; [ teh ];
|
|
|
|
};
|
2018-09-08 22:12:44 +02:00
|
|
|
};
|
|
|
|
typeshed = stdenv.mkDerivation {
|
2018-11-05 00:32:52 +01:00
|
|
|
pname = "typeshed";
|
2018-09-08 22:12:44 +02:00
|
|
|
version = pyre-version;
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "python";
|
|
|
|
repo = "typeshed";
|
2019-01-31 16:36:36 +01:00
|
|
|
rev = "0b49ce75b478fdf283dda5dd1368759ac342dfe2";
|
|
|
|
sha256 = "1w5aqbbcfk5ki8n9fgdikkyadjb318ipqyi517s9xnwlzi1jv0fh";
|
2018-09-08 22:12:44 +02:00
|
|
|
};
|
|
|
|
phases = [ "unpackPhase" "installPhase" ];
|
|
|
|
installPhase = "cp -r $src $out";
|
|
|
|
};
|
|
|
|
in python3.pkgs.buildPythonApplication rec {
|
|
|
|
pname = "pyre-check";
|
|
|
|
version = pyre-version;
|
2018-11-02 12:42:05 +01:00
|
|
|
src = pyre-src;
|
|
|
|
patches = [ ./pyre-bdist-wheel.patch ];
|
2018-09-08 22:12:44 +02:00
|
|
|
|
|
|
|
# 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' \
|
2018-11-02 12:42:05 +01:00
|
|
|
--replace 'BUILD_ROOT="$(mktemp -d)"' "BUILD_ROOT=$PWD/build"
|
2018-12-21 14:22:08 +01:00
|
|
|
for file in client/pyre.py client/commands/initialize.py client/commands/tests/initialize_test.py; do
|
|
|
|
substituteInPlace "$file" \
|
|
|
|
--replace '"watchman"' '"${watchman}/bin/watchman"'
|
|
|
|
done
|
2018-11-02 04:31:11 +01:00
|
|
|
substituteInPlace client/buck.py \
|
|
|
|
--replace '"buck"' '"${buck}/bin/buck"'
|
|
|
|
substituteInPlace client/tests/buck_test.py \
|
|
|
|
--replace '"buck"' '"${buck}/bin/buck"'
|
2018-09-08 22:12:44 +02:00
|
|
|
'';
|
|
|
|
|
2018-11-02 12:42:05 +01:00
|
|
|
buildInputs = [ pyre-bin ];
|
|
|
|
nativeBuildInputs = [ rsync ]; # only required for build-pypi-package.sh
|
2018-09-08 22:12:44 +02:00
|
|
|
propagatedBuildInputs = with python3.pkgs; [ docutils typeshed ];
|
|
|
|
buildPhase = ''
|
|
|
|
bash scripts/build-pypi-package.sh --version ${pyre-version} --bundle-typeshed ${typeshed}
|
|
|
|
cp -r build/dist dist
|
|
|
|
'';
|
2018-11-02 04:31:11 +01:00
|
|
|
checkPhase = ''
|
|
|
|
bash scripts/run-python-tests.sh
|
|
|
|
'';
|
2018-07-11 01:20:17 +02:00
|
|
|
}
|