From 14e9a3afc3ee5c57c41f2ff8cfe16c3be387f4b9 Mon Sep 17 00:00:00 2001 From: Someone Serge Date: Fri, 5 May 2023 18:03:27 +0300 Subject: [PATCH 1/5] pythonPackages: add format = "build" for pypa/build --- .../interpreters/python/hooks/default.nix | 9 +++++++++ .../python/hooks/pypa-build-hook.sh | 19 +++++++++++++++++++ .../python/mk-python-derivation.nix | 5 ++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/interpreters/python/hooks/pypa-build-hook.sh diff --git a/pkgs/development/interpreters/python/hooks/default.nix b/pkgs/development/interpreters/python/hooks/default.nix index 001e477b9185b..d75895b819fd7 100644 --- a/pkgs/development/interpreters/python/hooks/default.nix +++ b/pkgs/development/interpreters/python/hooks/default.nix @@ -71,6 +71,15 @@ in { }; } ./pip-install-hook.sh) {}; + pypaBuildHook = callPackage ({ makePythonHook, build, wheel }: + makePythonHook { + name = "pypa-build-hook.sh"; + propagatedBuildInputs = [ build wheel ]; + substitutions = { + inherit pythonInterpreter; + }; + } ./pypa-build-hook.sh) {}; + pytestCheckHook = callPackage ({ makePythonHook, pytest }: makePythonHook { name = "pytest-check-hook"; diff --git a/pkgs/development/interpreters/python/hooks/pypa-build-hook.sh b/pkgs/development/interpreters/python/hooks/pypa-build-hook.sh new file mode 100644 index 0000000000000..add5866ca3748 --- /dev/null +++ b/pkgs/development/interpreters/python/hooks/pypa-build-hook.sh @@ -0,0 +1,19 @@ +# Setup hook to use for pypa/build projects +echo "Sourcing pypa-build-hook" + +pypaBuildPhase() { + echo "Executing pypaBuildPhase" + runHook preBuild + + echo "Creating a wheel..." + @pythonInterpreter@ -m build --no-isolation --outdir dist/ $pypaBuildFlags + echo "Finished creating a wheel..." + + runHook postBuild + echo "Finished executing pypaBuildPhase" +} + +if [ -z "${dontUsePypaBuild-}" ] && [ -z "${buildPhase-}" ]; then + echo "Using pypaBuildPhase" + buildPhase=pypaBuildPhase +fi diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix index 17b5667e8ee9c..6490e784961b2 100644 --- a/pkgs/development/interpreters/python/mk-python-derivation.nix +++ b/pkgs/development/interpreters/python/mk-python-derivation.nix @@ -14,6 +14,7 @@ , flitBuildHook , pipBuildHook , pipInstallHook +, pypaBuildHook , pythonCatchConflictsHook , pythonImportsCheckHook , pythonNamespacesHook @@ -104,7 +105,7 @@ let inherit (python) stdenv; - withDistOutput = lib.elem format ["pyproject" "setuptools" "flit" "wheel"]; + withDistOutput = lib.elem format ["pyproject" "setuptools" "build" "flit" "wheel"]; name_ = name; @@ -182,6 +183,8 @@ let unzip ] ++ lib.optionals (format == "setuptools") [ setuptoolsBuildHook + ] ++ lib.optionals (format == "build") [ + pypaBuildHook ] ++ lib.optionals (format == "flit") [ flitBuildHook ] ++ lib.optionals (format == "pyproject") [ From 6af7b92d807811b779815826e5ab17c6baf275d9 Mon Sep 17 00:00:00 2001 From: Someone Serge Date: Fri, 5 May 2023 18:06:00 +0300 Subject: [PATCH 2/5] python3Packages.scipy: respect blas settings --- .../python-modules/scipy/default.nix | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/pkgs/development/python-modules/scipy/default.nix b/pkgs/development/python-modules/scipy/default.nix index 1090e724a7fd3..1fb6eb15a9447 100644 --- a/pkgs/development/python-modules/scipy/default.nix +++ b/pkgs/development/python-modules/scipy/default.nix @@ -4,6 +4,8 @@ , python , pythonOlder , buildPythonPackage +, blas +, lapack , cython , gfortran , meson-python @@ -19,10 +21,15 @@ , libxcrypt }: +assert blas.provider == numpy.blas; + buildPythonPackage rec { pname = "scipy"; version = "1.10.1"; - format = "pyproject"; + + # Required to pass -Dblas options + # https://github.com/scipy/scipy/issues/17244 + format = "build"; src = fetchPypi { inherit pname version; @@ -39,7 +46,8 @@ buildPythonPackage rec { nativeBuildInputs = [ cython gfortran meson-python pythran pkg-config wheel ]; buildInputs = [ - numpy.blas + blas + lapack pybind11 pooch ] ++ lib.optionals (pythonOlder "3.9") [ @@ -82,7 +90,17 @@ buildPythonPackage rec { blas = numpy.blas; }; - setupPyBuildFlags = [ "--fcompiler='gnu95'" ]; + pypaBuildFlags = [ + # Current release pins pybind11's patch version and ours is newer. + # Consider restoring build-time dependency check later + "--skip-dependency-check" + + # Skip sdist + "--wheel" + + "-Csetup-args=-Dblas=cblas" + "-Csetup-args=-Dlapack=lapacke" + ]; SCIPY_USE_G77_ABI_WRAPPER = 1; From 0f3bc1c0666eca67a6f5dba4c849b1c1cf67bb49 Mon Sep 17 00:00:00 2001 From: Someone Serge Date: Fri, 5 May 2023 20:16:32 +0300 Subject: [PATCH 3/5] fixup! pythonPackages: add format = "build" for pypa/build --- pkgs/development/interpreters/python/mk-python-derivation.nix | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix index 6490e784961b2..c601729a82379 100644 --- a/pkgs/development/interpreters/python/mk-python-derivation.nix +++ b/pkgs/development/interpreters/python/mk-python-derivation.nix @@ -105,7 +105,7 @@ let inherit (python) stdenv; - withDistOutput = lib.elem format ["pyproject" "setuptools" "build" "flit" "wheel"]; + withDistOutput = lib.elem format ["pyproject" "setuptools" "flit" "wheel"]; name_ = name; @@ -183,8 +183,6 @@ let unzip ] ++ lib.optionals (format == "setuptools") [ setuptoolsBuildHook - ] ++ lib.optionals (format == "build") [ - pypaBuildHook ] ++ lib.optionals (format == "flit") [ flitBuildHook ] ++ lib.optionals (format == "pyproject") [ From 5734bfb40e67ce5712dfdd50780a2309fdbe37db Mon Sep 17 00:00:00 2001 From: Someone Serge Date: Fri, 5 May 2023 20:25:39 +0300 Subject: [PATCH 4/5] fixup! python3Packages.scipy: respect blas settings --- .../python-modules/scipy/default.nix | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/pkgs/development/python-modules/scipy/default.nix b/pkgs/development/python-modules/scipy/default.nix index 1fb6eb15a9447..0541769cbef15 100644 --- a/pkgs/development/python-modules/scipy/default.nix +++ b/pkgs/development/python-modules/scipy/default.nix @@ -1,6 +1,7 @@ { lib , stdenv , fetchPypi +, pypaBuildHook , python , pythonOlder , buildPythonPackage @@ -26,10 +27,7 @@ assert blas.provider == numpy.blas; buildPythonPackage rec { pname = "scipy"; version = "1.10.1"; - - # Required to pass -Dblas options - # https://github.com/scipy/scipy/issues/17244 - format = "build"; + format = "pyproject"; src = fetchPypi { inherit pname version; @@ -43,7 +41,15 @@ buildPythonPackage rec { ./disable-datasets-tests.patch ]; - nativeBuildInputs = [ cython gfortran meson-python pythran pkg-config wheel ]; + nativeBuildInputs = [ + pypaBuildHook + cython + gfortran + meson-python + pythran + pkg-config + wheel + ]; buildInputs = [ blas @@ -75,6 +81,19 @@ buildPythonPackage rec { # hardeningDisable = lib.optionals (stdenv.isAarch64 && stdenv.isDarwin) [ "stackprotector" ]; + dontUsePipBuild = true; + pypaBuildFlags = [ + # Current release pins pybind11's patch version and ours is newer. + # Consider restoring build-time dependency check later + "--skip-dependency-check" + + # Skip sdist + "--wheel" + + "-Csetup-args=-Dblas=cblas" + "-Csetup-args=-Dlapack=lapacke" + ]; + checkPhase = '' runHook preCheck pushd "$out" @@ -90,18 +109,6 @@ buildPythonPackage rec { blas = numpy.blas; }; - pypaBuildFlags = [ - # Current release pins pybind11's patch version and ours is newer. - # Consider restoring build-time dependency check later - "--skip-dependency-check" - - # Skip sdist - "--wheel" - - "-Csetup-args=-Dblas=cblas" - "-Csetup-args=-Dlapack=lapacke" - ]; - SCIPY_USE_G77_ABI_WRAPPER = 1; meta = with lib; { From 28355c2c6fedf6587d538b62bd3e704f0e1fc730 Mon Sep 17 00:00:00 2001 From: Someone Serge Date: Fri, 5 May 2023 20:38:37 +0300 Subject: [PATCH 5/5] fixup! python3Packages.scipy: respect blas settings --- .../python-modules/scipy/default.nix | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pkgs/development/python-modules/scipy/default.nix b/pkgs/development/python-modules/scipy/default.nix index 0541769cbef15..4df6816428681 100644 --- a/pkgs/development/python-modules/scipy/default.nix +++ b/pkgs/development/python-modules/scipy/default.nix @@ -41,6 +41,20 @@ buildPythonPackage rec { ./disable-datasets-tests.patch ]; + # The pybind11 issue seems to have already been address by 2.10.3 + # https://github.com/pybind/pybind11/issues/4420 + # + # We should update pythran + # + # Numpy is pinned at patch versions, probably as a way to choose from a set + # of wheels published in pypi? + postPatch = '' + substituteInPlace pyproject.toml \ + --replace "pybind11==2.10.1" "pybind11>=2.10.3" \ + --replace '"pythran>=0.12.0,<0.13.0",' "" \ + --replace "numpy==" "numpy>=" + ''; + nativeBuildInputs = [ pypaBuildHook cython @@ -83,10 +97,6 @@ buildPythonPackage rec { dontUsePipBuild = true; pypaBuildFlags = [ - # Current release pins pybind11's patch version and ours is newer. - # Consider restoring build-time dependency check later - "--skip-dependency-check" - # Skip sdist "--wheel"