buildPythonPackage: add support for setupPyGlobalFlags (2)

This commit is contained in:
Frederik Rietdijk 2019-07-13 13:26:39 +02:00 committed by Frederik Rietdijk
parent e92a2f2fc2
commit 7da15d9b36
3 changed files with 17 additions and 8 deletions

View file

@ -603,6 +603,7 @@ All parameters from `stdenv.mkDerivation` function are still supported. The foll
* `preShellHook`: Hook to execute commands before `shellHook`. * `preShellHook`: Hook to execute commands before `shellHook`.
* `postShellHook`: Hook to execute commands after `shellHook`. * `postShellHook`: Hook to execute commands after `shellHook`.
* `removeBinByteCode ? true`: Remove bytecode from `/bin`. Bytecode is only created when the filenames end with `.py`. * `removeBinByteCode ? true`: Remove bytecode from `/bin`. Bytecode is only created when the filenames end with `.py`.
* `setupPyGlobalFlags ? []`: List of flags passed to `setup.py` command.
* `setupPyBuildFlags ? []`: List of flags passed to `setup.py build_ext` command. * `setupPyBuildFlags ? []`: List of flags passed to `setup.py build_ext` command.
The `stdenv.mkDerivation` function accepts various parameters for describing build inputs (see "Specifying dependencies"). The following are of special The `stdenv.mkDerivation` function accepts various parameters for describing build inputs (see "Specifying dependencies"). The following are of special

View file

@ -5,10 +5,12 @@
}: }:
{ {
# passed to "python setup.py build_ext" # Global options passed to "python setup.py"
setupPyGlobalFlags ? []
# Build options passed to "build_ext"
# https://github.com/pypa/pip/issues/881 # https://github.com/pypa/pip/issues/881
# Rename to `buildOptions` because it is not setuptools specific? # Rename to `buildOptions` because it is not setuptools specific?
setupPyBuildFlags ? [] , setupPyBuildFlags ? []
# Execute before shell hook # Execute before shell hook
, preShellHook ? "" , preShellHook ? ""
# Execute after shell hook # Execute after shell hook
@ -16,13 +18,14 @@
, ... } @ attrs: , ... } @ attrs:
let let
options = lib.concatMapStringsSep " " (option: "--global-option ${option}") setupPyBuildFlags; pipGlobalFlagsString = lib.concatMapStringsSep " " (option: "--global-option ${option}") setupPyGlobalFlags;
pipBuildFlagsString = lib.concatMapStringsSep " " (option: "--build-option ${option}") setupPyBuildFlags;
in attrs // { in attrs // {
buildPhase = attrs.buildPhase or '' buildPhase = attrs.buildPhase or ''
runHook preBuild runHook preBuild
mkdir -p dist mkdir -p dist
echo "Creating a wheel..." echo "Creating a wheel..."
${python.pythonForBuild.interpreter} -m pip wheel --no-index --no-deps --no-clean --no-build-isolation --wheel-dir dist ${options} . ${python.pythonForBuild.interpreter} -m pip wheel --no-index --no-deps --no-clean --no-build-isolation --wheel-dir dist ${pipGlobalFlagsString} ${pipBuildFlagsString} .
echo "Finished creating a wheel..." echo "Finished creating a wheel..."
runHook postBuild runHook postBuild
''; '';
@ -50,4 +53,4 @@ in attrs // {
${postShellHook} ${postShellHook}
''; '';
} }

View file

@ -5,9 +5,11 @@
}: }:
{ {
# passed to "python setup.py build_ext" # Global options passed to "python setup.py"
setupPyGlobalFlags ? []
# Build options passed to "python setup.py build_ext"
# https://github.com/pypa/pip/issues/881 # https://github.com/pypa/pip/issues/881
setupPyBuildFlags ? [] , setupPyBuildFlags ? []
# Execute before shell hook # Execute before shell hook
, preShellHook ? "" , preShellHook ? ""
# Execute after shell hook # Execute after shell hook
@ -19,13 +21,16 @@ let
# pip does the same thing: https://github.com/pypa/pip/pull/3265 # pip does the same thing: https://github.com/pypa/pip/pull/3265
setuppy = ./run_setup.py; setuppy = ./run_setup.py;
setupPyGlobalFlagsString = lib.concatStringsSep " " setupPyGlobalFlags;
setupPyBuildExtString = lib.optionalString (setupPyBuildFlags != []) ("build_ext " + (lib.concatStringsSep " " setupPyBuildFlags));
in attrs // { in attrs // {
# we copy nix_run_setup over so it's executed relative to the root of the source # we copy nix_run_setup over so it's executed relative to the root of the source
# many project make that assumption # many project make that assumption
buildPhase = attrs.buildPhase or '' buildPhase = attrs.buildPhase or ''
runHook preBuild runHook preBuild
cp ${setuppy} nix_run_setup cp ${setuppy} nix_run_setup
${python.pythonForBuild.interpreter} nix_run_setup ${lib.optionalString (setupPyBuildFlags != []) ("build_ext " + (lib.concatStringsSep " " setupPyBuildFlags))} bdist_wheel ${python.pythonForBuild.interpreter} nix_run_setup ${setupPyGlobalFlagsString} ${setupPyBuildExtString} bdist_wheel
runHook postBuild runHook postBuild
''; '';