2017-11-11 16:24:38 +01:00
|
|
|
# Generic builder.
|
2016-08-17 14:23:47 +02:00
|
|
|
|
|
|
|
{ lib
|
2018-04-25 19:15:48 +02:00
|
|
|
, config
|
2016-08-17 14:23:47 +02:00
|
|
|
, python
|
|
|
|
, wrapPython
|
|
|
|
, unzip
|
2018-02-13 15:32:16 +01:00
|
|
|
, ensureNewerSourcesForZipFilesHook
|
2017-05-28 09:20:47 +02:00
|
|
|
# Whether the derivation provides a Python module or not.
|
2017-12-10 14:20:38 +01:00
|
|
|
, toPythonModule
|
2017-05-28 09:20:47 +02:00
|
|
|
, namePrefix
|
2018-11-24 12:56:24 +01:00
|
|
|
, update-python-libraries
|
2019-07-17 20:36:47 +02:00
|
|
|
, setuptools
|
|
|
|
, flitBuildHook
|
|
|
|
, pipBuildHook
|
|
|
|
, pipInstallHook
|
|
|
|
, pythonCatchConflictsHook
|
|
|
|
, pythonImportsCheckHook
|
|
|
|
, pythonRemoveBinBytecodeHook
|
|
|
|
, setuptoolsBuildHook
|
|
|
|
, setuptoolsCheckHook
|
|
|
|
, wheelUnpackHook
|
2016-08-17 14:23:47 +02:00
|
|
|
}:
|
|
|
|
|
2017-11-03 05:14:22 +01:00
|
|
|
{ name ? "${attrs.pname}-${attrs.version}"
|
2016-08-17 14:23:47 +02:00
|
|
|
|
2017-12-21 21:49:06 +01:00
|
|
|
# Build-time dependencies for the package
|
|
|
|
, nativeBuildInputs ? []
|
|
|
|
|
|
|
|
# Run-time dependencies for the package
|
2016-08-17 14:23:47 +02:00
|
|
|
, buildInputs ? []
|
|
|
|
|
2016-08-31 11:01:16 +02:00
|
|
|
# Dependencies needed for running the checkPhase.
|
|
|
|
# These are added to buildInputs when doCheck = true.
|
|
|
|
, checkInputs ? []
|
|
|
|
|
2016-08-17 14:23:47 +02:00
|
|
|
# propagate build dependencies so in case we have A -> B -> C,
|
|
|
|
# C can import package A propagated by B
|
|
|
|
, propagatedBuildInputs ? []
|
|
|
|
|
|
|
|
# DEPRECATED: use propagatedBuildInputs
|
|
|
|
, pythonPath ? []
|
|
|
|
|
2019-04-24 21:10:25 +02:00
|
|
|
# Enabled to detect some (native)BuildInputs mistakes
|
|
|
|
, strictDeps ? true
|
|
|
|
|
2016-08-17 14:23:47 +02:00
|
|
|
# used to disable derivation, useful for specific python versions
|
|
|
|
, disabled ? false
|
|
|
|
|
|
|
|
# Raise an error if two packages are installed with the same name
|
|
|
|
, catchConflicts ? true
|
|
|
|
|
|
|
|
# Additional arguments to pass to the makeWrapper function, which wraps
|
|
|
|
# generated binaries.
|
|
|
|
, makeWrapperArgs ? []
|
|
|
|
|
2017-05-25 21:56:25 +02:00
|
|
|
# Skip wrapping of python programs altogether
|
|
|
|
, dontWrapPythonPrograms ? false
|
|
|
|
|
2019-07-17 20:36:47 +02:00
|
|
|
# Don't use Pip to install a wheel
|
|
|
|
# Note this is actually a variable for the pipInstallPhase in pip's setupHook.
|
|
|
|
# It's included here to prevent an infinite recursion.
|
|
|
|
, dontUsePipInstall ? false
|
|
|
|
|
2018-11-22 07:20:38 +01:00
|
|
|
# Skip setting the PYTHONNOUSERSITE environment variable in wrapped programs
|
2018-12-07 00:18:59 +01:00
|
|
|
, permitUserSite ? false
|
2018-11-22 07:20:38 +01:00
|
|
|
|
2017-12-10 15:41:05 +01:00
|
|
|
# Remove bytecode from bin folder.
|
|
|
|
# When a Python script has the extension `.py`, bytecode is generated
|
|
|
|
# Typically, executables in bin have no extension, so no bytecode is generated.
|
|
|
|
# However, some packages do provide executables with extensions, and thus bytecode is generated.
|
|
|
|
, removeBinBytecode ? true
|
|
|
|
|
2019-07-17 20:36:47 +02:00
|
|
|
# Several package formats are supported.
|
|
|
|
# "setuptools" : Install a common setuptools/distutils based package. This builds a wheel.
|
|
|
|
# "wheel" : Install from a pre-compiled wheel.
|
|
|
|
# "flit" : Install a flit package. This builds a wheel.
|
|
|
|
# "other" : Provide your own buildPhase and installPhase.
|
|
|
|
, format ? "setuptools"
|
|
|
|
|
2016-08-17 14:23:47 +02:00
|
|
|
, meta ? {}
|
|
|
|
|
|
|
|
, passthru ? {}
|
|
|
|
|
2018-04-25 19:15:48 +02:00
|
|
|
, doCheck ? config.doCheckByDefault or false
|
2016-09-01 17:10:38 +02:00
|
|
|
|
2016-08-17 14:23:47 +02:00
|
|
|
, ... } @ attrs:
|
|
|
|
|
|
|
|
|
|
|
|
# Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
|
|
|
|
if disabled
|
|
|
|
then throw "${name} not supported for interpreter ${python.executable}"
|
|
|
|
else
|
|
|
|
|
2019-07-17 20:36:47 +02:00
|
|
|
let
|
|
|
|
inherit (python) stdenv;
|
|
|
|
|
|
|
|
self = toPythonModule (stdenv.mkDerivation ((builtins.removeAttrs attrs [
|
|
|
|
"disabled" "checkPhase" "checkInputs" "doCheck" "doInstallCheck" "dontWrapPythonPrograms" "catchConflicts" "format"
|
|
|
|
]) // {
|
2016-08-17 14:23:47 +02:00
|
|
|
|
|
|
|
name = namePrefix + name;
|
|
|
|
|
2019-01-05 10:31:16 +01:00
|
|
|
nativeBuildInputs = [
|
|
|
|
python
|
|
|
|
wrapPython
|
2019-07-17 20:36:47 +02:00
|
|
|
ensureNewerSourcesForZipFilesHook # move to wheel installer (pip) or builder (setuptools, flit, ...)?
|
|
|
|
] ++ lib.optionals catchConflicts [
|
|
|
|
setuptools pythonCatchConflictsHook
|
|
|
|
] ++ lib.optionals removeBinBytecode [
|
|
|
|
pythonRemoveBinBytecodeHook
|
2019-01-05 10:31:16 +01:00
|
|
|
] ++ lib.optionals (lib.hasSuffix "zip" (attrs.src.name or "")) [
|
|
|
|
unzip
|
2019-07-17 20:36:47 +02:00
|
|
|
] ++ lib.optionals (format == "setuptools") [
|
|
|
|
setuptoolsBuildHook
|
|
|
|
] ++ lib.optionals (format == "flit") [
|
|
|
|
flitBuildHook
|
|
|
|
] ++ lib.optionals (format == "pyproject") [
|
|
|
|
pipBuildHook
|
|
|
|
] ++ lib.optionals (format == "wheel") [
|
|
|
|
wheelUnpackHook
|
|
|
|
] ++ lib.optionals (!(format == "other") || dontUsePipInstall) [
|
|
|
|
pipInstallHook
|
|
|
|
] ++ lib.optionals (stdenv.buildPlatform == stdenv.hostPlatform) [
|
|
|
|
# This is a test, however, it should be ran independent of the checkPhase and checkInputs
|
|
|
|
pythonImportsCheckHook
|
2019-01-05 10:31:16 +01:00
|
|
|
] ++ nativeBuildInputs;
|
|
|
|
|
|
|
|
buildInputs = buildInputs ++ pythonPath;
|
2016-08-17 14:23:47 +02:00
|
|
|
|
2019-07-17 20:36:47 +02:00
|
|
|
propagatedBuildInputs = propagatedBuildInputs ++ [ python ];
|
2016-08-17 14:23:47 +02:00
|
|
|
|
2019-04-24 21:10:25 +02:00
|
|
|
inherit strictDeps;
|
2019-01-05 10:26:57 +01:00
|
|
|
|
2019-02-15 13:30:59 +01:00
|
|
|
LANG = "${if python.stdenv.isDarwin then "en_US" else "C"}.UTF-8";
|
|
|
|
|
2016-08-17 14:23:47 +02:00
|
|
|
# Python packages don't have a checkPhase, only an installCheckPhase
|
|
|
|
doCheck = false;
|
2019-07-17 20:36:47 +02:00
|
|
|
doInstallCheck = attrs.doCheck or true;
|
|
|
|
installCheckInputs = [
|
|
|
|
] ++ lib.optionals (format == "setuptools") [
|
|
|
|
# Longer-term we should get rid of this and require
|
|
|
|
# users of this function to set the `installCheckPhase` or
|
|
|
|
# pass in a hook that sets it.
|
|
|
|
setuptoolsCheckHook
|
|
|
|
] ++ checkInputs;
|
2016-08-17 14:23:47 +02:00
|
|
|
|
2017-05-25 21:56:25 +02:00
|
|
|
postFixup = lib.optionalString (!dontWrapPythonPrograms) ''
|
2016-08-17 14:23:47 +02:00
|
|
|
wrapPythonPrograms
|
2016-10-25 22:33:45 +02:00
|
|
|
'' + attrs.postFixup or '''';
|
2016-08-17 14:23:47 +02:00
|
|
|
|
2019-01-02 20:09:44 +01:00
|
|
|
# Python packages built through cross-compilation are always for the host platform.
|
|
|
|
disallowedReferences = lib.optionals (python.stdenv.hostPlatform != python.stdenv.buildPlatform) [ python.pythonForBuild ];
|
|
|
|
|
2017-11-11 13:37:21 +01:00
|
|
|
meta = {
|
2016-08-17 14:23:47 +02:00
|
|
|
# default to python's platforms
|
|
|
|
platforms = python.meta.platforms;
|
|
|
|
isBuildPythonPackage = python.meta.platforms;
|
2017-11-11 13:37:21 +01:00
|
|
|
} // meta;
|
2019-07-17 20:36:47 +02:00
|
|
|
} // lib.optionalAttrs (attrs?checkPhase) {
|
|
|
|
# If given use the specified checkPhase, otherwise use the setup hook.
|
|
|
|
# Longer-term we should get rid of `checkPhase` and use `installCheckPhase`.
|
|
|
|
installCheckPhase = attrs.checkPhase;
|
2018-11-24 12:56:24 +01:00
|
|
|
}));
|
|
|
|
|
2018-12-23 09:59:56 +01:00
|
|
|
passthru.updateScript = let
|
2018-11-24 12:56:24 +01:00
|
|
|
filename = builtins.head (lib.splitString ":" self.meta.position);
|
2018-12-23 09:59:56 +01:00
|
|
|
in attrs.passthru.updateScript or [ update-python-libraries filename ];
|
2018-11-24 12:56:24 +01:00
|
|
|
in lib.extendDerivation true passthru self
|