python/hooks/setuptools-build-hook.sh: use `--parallel` flag only for fresh setuptools

Without the change attempt to enable parallelist for `python2` packages
fails with unsupported `--parallel` flag for `setuptools`-based
packages:

    $ nix build --no-link -f. --arg config '{enableParallelBuildingByDefault = true;}' xdg-utils
    error: builder for '/nix/store/...-python2.7-setuptools-44.0.0.drv' failed with exit code 1;
       last 10 log lines:
       > no configure script, doing nothing
       > Running phase: buildPhase
       > Executing setuptoolsBuildPhase
       > usage: nix_run_setup [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       >    or: nix_run_setup --help [cmd1 cmd2 ...]
       >    or: nix_run_setup --help-commands
       >    or: nix_run_setup cmd --help
       >
       > error: option --parallel not recognized
This commit is contained in:
Sergei Trofimovich 2024-02-12 22:30:36 +00:00 committed by Sandro Jäckel
parent f904a6b3b5
commit 187ac583a0
No known key found for this signature in database
GPG Key ID: 3AF5A43A3EECC2E5
2 changed files with 6 additions and 2 deletions

View File

@ -195,6 +195,8 @@ in {
propagatedBuildInputs = [ setuptools wheel ];
substitutions = {
inherit pythonInterpreter setuppy;
# python2.pkgs.setuptools does not support parallelism
setuptools_has_parallel = setuptools != null && lib.versionAtLeast setuptools.version "69";
};
} ./setuptools-build-hook.sh) {};

View File

@ -3,7 +3,7 @@ echo "Sourcing setuptools-build-hook"
setuptoolsBuildPhase() {
echo "Executing setuptoolsBuildPhase"
local args
local args setuptools_has_parallel=@setuptools_has_parallel@
runHook preBuild
cp -f @setuppy@ nix_run_setup
@ -12,7 +12,9 @@ setuptoolsBuildPhase() {
args+="$setupPyGlobalFlags"
fi
if [ -n "$enableParallelBuilding" ]; then
setupPyBuildFlags+=" --parallel $NIX_BUILD_CORES"
if [ -n "$setuptools_has_parallel" ]; then
setupPyBuildFlags+=" --parallel $NIX_BUILD_CORES"
fi
fi
if [ -n "$setupPyBuildFlags" ]; then
args+=" build_ext $setupPyBuildFlags"