python3.pkgs.scipy: 1.10.1 -> 1.11.1

Diff: https://github.com/scipy/scipy/compare/v1.10.1...v1.11.1

Significant changes to expression:

- Use `pypaBuildHook` to build it.
- Use `fetchFromGitHub` instead of `fetchPypi`.
- Support cross compilation using `pypaBuildHook` and `$mesonFlags`.
- Add a `passthru.updateScript` that downloads and updates hashes for datasets
  needed for tests.
- Cleanup:
  * Remove unneeded anymore `setupPyBuildFlags`.
  * Remove unnecessary `sed` command from preConfigure that fixed a Numpy
    issue in `setup.py`
  * Use `blas` and `lapack` directly, relying on them being overriden by
    the user in all of Python's packages' set - see commit 213d0845b5c .
This commit is contained in:
Doron Behar
2023-07-28 12:13:26 +02:00
committed by Martin Weinelt
parent 68efe0a5a7
commit 8f4914fae6
3 changed files with 120 additions and 28 deletions
@@ -1,9 +1,15 @@
{ lib
, stdenv
, fetchPypi
, fetchFromGitHub
, fetchpatch
, fetchurl
, buildPackages
, writeText
, python
, pythonOlder
, buildPythonPackage
, pypaBuildHook
, pipInstallHook
, cython
, gfortran
, meson-python
@@ -17,31 +23,71 @@
, pybind11
, pooch
, libxcrypt
, xsimd
, blas
, lapack
}:
buildPythonPackage rec {
let
pname = "scipy";
version = "1.10.1";
format = "pyproject";
src = fetchPypi {
inherit pname version;
hash = "sha256-LPnfuAp7RYm6TEDOdYiYbW1c68VFfK0sKID2vC1C86U=";
# DON'T UPDATE THESE ATTRIBUTES MANUALLY - USE:
#
# nix-shell maintainers/scripts/update.nix --argstr package python3.pkgs.scipy
#
# Even if you do update these hashes manually, don't change their base
# (base16 or base64), because the update script uses sed regexes to replace
# them with the updated hashes.
version = "1.11.1";
srcHash = "sha256-bgnYXe3EhzL7+Gfriz1cXCl2eYQJ8zF+rcIwHyZR8bQ=";
datasetsHashes = {
ascent = "1qjp35ncrniq9rhzb14icwwykqg2208hcssznn3hz27w39615kh3";
ecg = "1bwbjp43b7znnwha5hv6wiz3g0bhwrpqpi75s12zidxrbwvd62pj";
face = "11i8x29h80y7hhyqhil1fg8mxag5f827g33lhnsf44qk116hp2wx";
};
datasets = lib.mapAttrs (
d: hash: fetchurl {
url = "https://raw.githubusercontent.com/scipy/dataset-${d}/main/${d}.dat";
sha256 = hash;
}
) datasetsHashes;
# Additional cross compilation related properties that scipy reads in scipy/meson.build
crossFileScipy = writeText "cross-file-scipy.conf" ''
[properties]
numpy-include-dir = '${numpy}/${python.sitePackages}/numpy/core/include'
pythran-include-dir = '${pythran}/${python.sitePackages}/pythran'
host-python-path = '${python.interpreter}'
host-python-version = '${python.pythonVersion}'
'';
in buildPythonPackage {
inherit pname version;
format = "other";
src = fetchFromGitHub {
owner = "scipy";
repo = pname;
rev = "v${version}";
hash = srcHash;
fetchSubmodules = true;
};
patches = [
# These tests require internet connection, currently impossible to disable
# them otherwise, see:
# https://github.com/scipy/scipy/pull/17965
./disable-datasets-tests.patch
# Helps with cross compilation, see https://github.com/scipy/scipy/pull/18167
(fetchpatch {
url = "https://github.com/scipy/scipy/commit/dd50ac9d98dbb70625333a23e3a90e493228e3be.patch";
hash = "sha256-Vf6/hhwu6X5s8KWhq8bUZKtSkdVu/GtEpGtj8Olxe7s=";
excludes = [
"doc/source/dev/contributor/meson_advanced.rst"
];
})
];
nativeBuildInputs = [ cython gfortran meson-python pythran pkg-config wheel ];
nativeBuildInputs = [ pypaBuildHook pipInstallHook cython gfortran meson-python pythran pkg-config wheel ];
buildInputs = [
numpy.blas
blas
lapack
pybind11
pooch
xsimd
] ++ lib.optionals (pythonOlder "3.9") [
libxcrypt
];
@@ -53,9 +99,29 @@ buildPythonPackage rec {
doCheck = !(stdenv.isx86_64 && stdenv.isDarwin);
preConfigure = ''
sed -i '0,/from numpy.distutils.core/s//import setuptools;from numpy.distutils.core/' setup.py
# Relax deps a bit
substituteInPlace pyproject.toml \
--replace 'numpy==' 'numpy>='
# Helps parallelization a bit
export NPY_NUM_BUILD_JOBS=$NIX_BUILD_CORES
'';
# We download manually the datasets and this variable tells the pooch
# library where these files are cached. See also:
# https://github.com/scipy/scipy/pull/18518#issuecomment-1562350648 And at:
# https://github.com/scipy/scipy/pull/17965#issuecomment-1560759962
export XDG_CACHE_HOME=$PWD; mkdir scipy-data
'' + (lib.concatStringsSep "\n" (lib.mapAttrsToList (d: dpath:
# Actually copy the datasets
"cp ${dpath} scipy-data/${d}.dat"
) datasets));
mesonFlags = [
"-Dblas=${blas.pname}"
"-Dlapack=${lapack.pname}"
# We always run what's necessary for cross compilation, which is passing to
# meson the proper cross compilation related arguments. See also:
# https://docs.scipy.org/doc/scipy/building/cross_compilation.html
"--cross-file=${crossFileScipy}"
];
# disable stackprotector on aarch64-darwin for now
#
@@ -79,11 +145,17 @@ buildPythonPackage rec {
requiredSystemFeatures = [ "big-parallel" ]; # the tests need lots of CPU time
passthru = {
blas = numpy.blas;
inherit blas;
updateScript = [
./update.sh
# Pass it this file name as argument
(builtins.unsafeGetAttrPos "pname" python.pkgs.scipy).file
]
# Pass it the names of the datasets to update their hashes
++ (builtins.attrNames datasetsHashes)
;
};
setupPyBuildFlags = [ "--fcompiler='gnu95'" ];
SCIPY_USE_G77_ABI_WRAPPER = 1;
meta = with lib; {
@@ -1,9 +0,0 @@
diff --git i/scipy/datasets/meson.build w/scipy/datasets/meson.build
index 101377253..eec2feea4 100644
--- i/scipy/datasets/meson.build
+++ w/scipy/datasets/meson.build
@@ -11,4 +11,3 @@ py3.install_sources(
subdir: 'scipy/datasets'
)
-subdir('tests')
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p jq nix-prefetch-github
set -euo pipefail
echoerr() { echo "$@" 1>&2; }
fname="$1"
echoerr got fname $fname
shift
datasets="$@"
echoerr datasets are: "$@"
latest_release=$(curl --silent https://api.github.com/repos/scipy/scipy/releases/latest)
version=$(jq -r '.tag_name' <<<"$latest_release" | cut -c2-)
# Update version, if needed
if grep -q 'version = "'$version $fname; then
echo "Current version $version is the latest available, will update only datasets' hashes (don't take long)"
else
echoerr got version $version
sed -i -E 's/(version = ).*=/\1'$version'/g' $fname
# Update srcHash
srcHash='"sha256-'$(nix-prefetch-github scipy scipy --rev v${version} --fetch-submodules | jq --raw-output .sha256)'"'
sed -i 's/srcHash = .*=";/srcHash = '$srcHash';/g' $fname
fi
for d in $datasets; do
datasetHash=$(nix-prefetch-url "https://raw.githubusercontent.com/scipy/dataset-${d}/main/${d}.dat")
sed -i 's/'$d' = "[0-9a-z]\+/'$d' = "'$datasetHash'/g' $fname
echoerr updated hash for dataset "'$d'"
done