diff --git a/pkgs/development/python-modules/numpy/1.nix b/pkgs/development/python-modules/numpy/1.nix index ca33bdca1994..3e6b5a712564 100644 --- a/pkgs/development/python-modules/numpy/1.nix +++ b/pkgs/development/python-modules/numpy/1.nix @@ -3,7 +3,6 @@ stdenv, fetchPypi, python, - numpy_1, pythonAtLeast, buildPythonPackage, writeTextFile, @@ -33,37 +32,14 @@ assert (!blas.isILP64) && (!lapack.isILP64); -let - cfg = writeTextFile { - name = "site.cfg"; - text = lib.generators.toINI { } { - ${blas.implementation} = { - include_dirs = "${lib.getDev blas}/include:${lib.getDev lapack}/include"; - library_dirs = "${blas}/lib:${lapack}/lib"; - runtime_library_dirs = "${blas}/lib:${lapack}/lib"; - libraries = "lapack,lapacke,blas,cblas"; - }; - lapack = { - include_dirs = "${lib.getDev lapack}/include"; - library_dirs = "${lapack}/lib"; - runtime_library_dirs = "${lapack}/lib"; - }; - blas = { - include_dirs = "${lib.getDev blas}/include"; - library_dirs = "${blas}/lib"; - runtime_library_dirs = "${blas}/lib"; - }; - }; - }; -in -buildPythonPackage rec { +buildPythonPackage (finalAttrs: { pname = "numpy"; version = "1.26.4"; pyproject = true; disabled = pythonAtLeast "3.13"; src = fetchPypi { - inherit pname version; + inherit (finalAttrs) pname version; extension = "tar.gz"; hash = "sha256-KgKrqe0S5KxOs+qUIcQgMBoMZGDZgw10qd+H76SRIBA="; }; @@ -123,7 +99,7 @@ buildPythonPackage rec { ''; preBuild = '' - ln -s ${cfg} site.cfg + ln -s ${finalAttrs.passthru.cfg} site.cfg ''; enableParallelBuilding = true; @@ -180,8 +156,29 @@ buildPythonPackage rec { # just for backwards compatibility blas = blas.provider; blasImplementation = blas.implementation; - inherit cfg; - coreIncludeDir = "${numpy_1}/${python.sitePackages}/numpy/core/include"; + buildConfig = { + ${blas.implementation} = { + include_dirs = "${lib.getDev blas}/include:${lib.getDev lapack}/include"; + library_dirs = "${blas}/lib:${lapack}/lib"; + runtime_library_dirs = "${blas}/lib:${lapack}/lib"; + libraries = "lapack,lapacke,blas,cblas"; + }; + lapack = { + include_dirs = "${lib.getDev lapack}/include"; + library_dirs = "${lapack}/lib"; + runtime_library_dirs = "${lapack}/lib"; + }; + blas = { + include_dirs = "${lib.getDev blas}/include"; + library_dirs = "${blas}/lib"; + runtime_library_dirs = "${blas}/lib"; + }; + }; + cfg = writeTextFile { + name = "site.cfg"; + text = lib.generators.toINI { } finalAttrs.finalPackage.buildConfig; + }; + coreIncludeDir = "${finalAttrs.finalPackage}/${python.sitePackages}/numpy/core/include"; tests = { inherit sage; }; @@ -192,10 +189,10 @@ buildPythonPackage rec { env.NOSE_EXCLUDE = "test_large_file_support"; meta = { - changelog = "https://github.com/numpy/numpy/releases/tag/v${version}"; + changelog = "https://github.com/numpy/numpy/releases/tag/v${finalAttrs.version}"; description = "Scientific tools for Python"; mainProgram = "f2py"; homepage = "https://numpy.org/"; license = lib.licenses.bsd3; }; -} +}) diff --git a/pkgs/development/python-modules/numpy/2.nix b/pkgs/development/python-modules/numpy/2.nix index 778bcdbc6f21..0acf0a4a787b 100644 --- a/pkgs/development/python-modules/numpy/2.nix +++ b/pkgs/development/python-modules/numpy/2.nix @@ -2,9 +2,7 @@ lib, stdenv, fetchFromGitHub, - fetchpatch2, python, - numpy_2, pythonAtLeast, pythonOlder, buildPythonPackage, @@ -36,32 +34,9 @@ assert (!blas.isILP64) && (!lapack.isILP64); -let - cfg = writeTextFile { - name = "site.cfg"; - text = lib.generators.toINI { } { - ${blas.implementation} = { - include_dirs = "${lib.getDev blas}/include:${lib.getDev lapack}/include"; - library_dirs = "${blas}/lib:${lapack}/lib"; - runtime_library_dirs = "${blas}/lib:${lapack}/lib"; - libraries = "lapack,lapacke,blas,cblas"; - }; - lapack = { - include_dirs = "${lib.getDev lapack}/include"; - library_dirs = "${lapack}/lib"; - runtime_library_dirs = "${lapack}/lib"; - }; - blas = { - include_dirs = "${lib.getDev blas}/include"; - library_dirs = "${blas}/lib"; - runtime_library_dirs = "${blas}/lib"; - }; - }; - }; -in -buildPythonPackage rec { +buildPythonPackage (finalAttrs: { pname = "numpy"; - version = "2.3.5"; + version = "2.4.1"; pyproject = true; disabled = pythonOlder "3.11"; @@ -69,30 +44,17 @@ buildPythonPackage rec { src = fetchFromGitHub { owner = "numpy"; repo = "numpy"; - tag = "v${version}"; + tag = "v${finalAttrs.version}"; fetchSubmodules = true; - hash = "sha256-CMgJmsjPLgMCWN2iJk0OzcKIlnRRcayrTAns51S4B6k="; + hash = "sha256-3UjvAQZEvsA/1s2mqFMnvi2E9MBHG27xf91FqiMGHmo="; }; - patches = - lib.optionals python.hasDistutilsCxxPatch [ - # We patch cpython/distutils to fix https://bugs.python.org/issue1222585 - # Patching of numpy.distutils is needed to prevent it from undoing the - # patch to distutils. - ./numpy-distutils-C++.patch - ] - ++ - lib.optionals - (pythonAtLeast "3.14" && stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) - [ - # don't assert RecursionError in monster dtype test - # see https://github.com/numpy/numpy/pull/30375 - (fetchpatch2 { - url = "https://github.com/numpy/numpy/commit/eeaf04662e07cc8e2041f3e25bbd3698949a0c02.patch?full_index=1"; - excludes = [ ".github/workflows/macos.yml" ]; - hash = "sha256-bLPLExlKnX18MXhbZxzCHniaAE0yTSyK9WuQyFyYHOI="; - }) - ]; + patches = lib.optionals python.hasDistutilsCxxPatch [ + # We patch cpython/distutils to fix https://bugs.python.org/issue1222585 + # Patching of numpy.distutils is needed to prevent it from undoing the + # patch to distutils. + ./numpy-distutils-C++.patch + ]; postPatch = '' # remove needless reference to full Python path stored in built wheel @@ -127,7 +89,7 @@ buildPythonPackage rec { ]; preBuild = '' - ln -s ${cfg} site.cfg + ln -s ${finalAttrs.finalPackage.passthru.cfg} site.cfg ''; enableParallelBuilding = true; @@ -193,18 +155,39 @@ buildPythonPackage rec { # just for backwards compatibility blas = blas.provider; blasImplementation = blas.implementation; - inherit cfg; - coreIncludeDir = "${numpy_2}/${python.sitePackages}/numpy/_core/include"; + buildConfig = { + ${blas.implementation} = { + include_dirs = "${lib.getDev blas}/include:${lib.getDev lapack}/include"; + library_dirs = "${blas}/lib:${lapack}/lib"; + runtime_library_dirs = "${blas}/lib:${lapack}/lib"; + libraries = "lapack,lapacke,blas,cblas"; + }; + lapack = { + include_dirs = "${lib.getDev lapack}/include"; + library_dirs = "${lapack}/lib"; + runtime_library_dirs = "${lapack}/lib"; + }; + blas = { + include_dirs = "${lib.getDev blas}/include"; + library_dirs = "${blas}/lib"; + runtime_library_dirs = "${blas}/lib"; + }; + }; + cfg = writeTextFile { + name = "site.cfg"; + text = lib.generators.toINI { } finalAttrs.finalPackage.buildConfig; + }; + coreIncludeDir = "${finalAttrs.finalPackage}/${python.sitePackages}/numpy/_core/include"; tests = { inherit sage; }; }; meta = { - changelog = "https://github.com/numpy/numpy/releases/tag/${src.tag}"; + changelog = "https://github.com/numpy/numpy/releases/tag/${finalAttrs.src.tag}"; description = "Scientific tools for Python"; homepage = "https://numpy.org/"; license = lib.licenses.bsd3; maintainers = with lib.maintainers; [ doronbehar ]; }; -} +}) diff --git a/pkgs/development/python-modules/scipy/default.nix b/pkgs/development/python-modules/scipy/default.nix index c5b1f9d3a3f6..daa6cadf603f 100644 --- a/pkgs/development/python-modules/scipy/default.nix +++ b/pkgs/development/python-modules/scipy/default.nix @@ -2,7 +2,7 @@ lib, stdenv, fetchurl, - writeText, + writeTextFile, python, buildPythonPackage, fetchFromGitHub, @@ -43,45 +43,16 @@ sage, }: -let +buildPythonPackage (finalAttrs: { pname = "scipy"; - # DON'T UPDATE THESE ATTRIBUTES MANUALLY - USE: - # - # nix-shell maintainers/scripts/update.nix --argstr package python3.pkgs.scipy - # - # The update script uses sed regexes to replace them with the updated hashes. - version = "1.16.3"; - srcHash = "sha256-2NVmsJqsUjWSD7oEJhRkRjbKvqwikBJenAhBio/+IuU="; - 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.coreIncludeDir}' - pythran-include-dir = '${pythran}/${python.sitePackages}/pythran' - host-python-path = '${python.interpreter}' - host-python-version = '${python.pythonVersion}' - ''; -in -buildPythonPackage { - inherit pname version; + version = "1.17.0"; pyproject = true; src = fetchFromGitHub { owner = "scipy"; repo = "scipy"; - tag = "v${version}"; - hash = srcHash; + tag = "v${finalAttrs.version}"; + hash = "sha256-bDcM/RGfce/ZTYpTBNpKmX/7rXDqQs7rYkAmeXtzkZk="; fetchSubmodules = true; }; @@ -189,7 +160,7 @@ buildPythonPackage { d: dpath: # Actually copy the datasets "cp ${dpath} scipy-data/${d}.dat" - ) datasets + ) finalAttrs.finalPackage.passthru.datasets )); mesonFlags = [ @@ -198,7 +169,7 @@ buildPythonPackage { # 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}" + "--cross-file=${finalAttrs.finalPackage.passthru.crossFile}" "-Duse-system-libraries=all" ]; @@ -229,26 +200,53 @@ buildPythonPackage { passthru = { 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); tests = { inherit sage; }; + # NOTE: Every once in a while, these hashes might need an update. Use: + # + # nix build -Lf. --rebuild python3.pkgs.scipy.passthru.datasets + # + # To verify the hashes are correct. + datasetsHashes = { + ascent = "sha256-A84STBr8iA+HtV9rBhEQ4uHpOWeRhPVhTjjazGwZV+I="; + ecg = "sha256-8grTNl+5t/hF0OXEi2/mcIE3fuRmw6Igt/afNciVi68="; + face = "sha256-nYsLTQgTE+K0hXSMdwRy5ale0XOBRog9hMcDBJPoKIY="; + }; + datasets = lib.mapAttrs ( + d: hash: + fetchurl { + url = "https://raw.githubusercontent.com/scipy/dataset-${d}/main/${d}.dat"; + inherit hash; + } + ) finalAttrs.finalPackage.passthru.datasetsHashes; + # Additional cross compilation related properties that scipy reads in scipy/meson.build + buildConfig = { + properties = { + numpy-include-dir = numpy.coreIncludeDir; + pythran-include-dir = "${pythran}/${python.sitePackages}/pythran"; + host-python-path = python.interpreter; + host-python-version = python.pythonVersion; + }; + }; + crossFile = writeTextFile { + name = "cross-file-scipy.conf"; + text = lib.generators.toINI { + mkKeyValue = lib.generators.mkKeyValueDefault { + mkValueString = v: "'${v}'"; + } " = "; + } finalAttrs.finalPackage.passthru.buildConfig; + }; }; SCIPY_USE_G77_ABI_WRAPPER = 1; meta = { - changelog = "https://github.com/scipy/scipy/releases/tag/v${version}"; + changelog = "https://github.com/scipy/scipy/releases/tag/v${finalAttrs.version}"; description = "SciPy (pronounced 'Sigh Pie') is open-source software for mathematics, science, and engineering"; downloadPage = "https://github.com/scipy/scipy"; homepage = "https://www.scipy.org/"; license = lib.licenses.bsd3; maintainers = with lib.maintainers; [ doronbehar ]; }; -} +}) diff --git a/pkgs/development/python-modules/scipy/update.sh b/pkgs/development/python-modules/scipy/update.sh deleted file mode 100755 index c6b3dca49186..000000000000 --- a/pkgs/development/python-modules/scipy/update.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/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'\2/g' $fname - # Verify the sed command above did not fail - grep -q $version $fname - # Update srcHash - srcHash="$(nix-prefetch-github scipy scipy --rev v${version} --fetch-submodules | jq --raw-output .hash)" - sed -i -E 's#(srcHash = ").*(";)#\1'$srcHash'\2#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