2017-11-11 15:24:38 +00:00
|
|
|
# Generic builder.
|
2016-08-17 13:23:47 +01:00
|
|
|
|
|
|
|
{ lib
|
|
|
|
, python
|
|
|
|
, wrapPython
|
|
|
|
, setuptools
|
|
|
|
, unzip
|
|
|
|
, ensureNewerSourcesHook
|
2017-05-28 08:20:47 +01:00
|
|
|
# Whether the derivation provides a Python module or not.
|
|
|
|
, pythonModule
|
|
|
|
, namePrefix
|
2016-08-17 13:23:47 +01:00
|
|
|
}:
|
|
|
|
|
2017-11-03 04:14:22 +00:00
|
|
|
{ name ? "${attrs.pname}-${attrs.version}"
|
2016-08-17 13:23:47 +01:00
|
|
|
|
2016-08-31 10:01:16 +01:00
|
|
|
# Dependencies for building the package
|
2016-08-17 13:23:47 +01:00
|
|
|
, buildInputs ? []
|
|
|
|
|
2016-08-31 10:01:16 +01:00
|
|
|
# Dependencies needed for running the checkPhase.
|
|
|
|
# These are added to buildInputs when doCheck = true.
|
|
|
|
, checkInputs ? []
|
|
|
|
|
2016-08-17 13:23:47 +01: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 ? []
|
|
|
|
|
|
|
|
# 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 20:56:25 +01:00
|
|
|
# Skip wrapping of python programs altogether
|
|
|
|
, dontWrapPythonPrograms ? false
|
|
|
|
|
2016-08-17 13:23:47 +01:00
|
|
|
, meta ? {}
|
|
|
|
|
|
|
|
, passthru ? {}
|
|
|
|
|
2016-09-01 16:10:38 +01:00
|
|
|
, doCheck ? false
|
|
|
|
|
2016-08-17 13:23:47 +01:00
|
|
|
, ... } @ attrs:
|
|
|
|
|
|
|
|
|
|
|
|
# Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
|
|
|
|
if disabled
|
|
|
|
then throw "${name} not supported for interpreter ${python.executable}"
|
|
|
|
else
|
|
|
|
|
2017-11-11 15:21:02 +00:00
|
|
|
python.stdenv.mkDerivation (builtins.removeAttrs attrs [
|
|
|
|
"disabled" "checkInputs" "doCheck" "doInstallCheck" "dontWrapPythonPrograms" "catchConflicts"
|
|
|
|
] // {
|
2016-08-17 13:23:47 +01:00
|
|
|
|
|
|
|
name = namePrefix + name;
|
|
|
|
|
2017-11-11 15:24:38 +00:00
|
|
|
buildInputs = ([ wrapPython (ensureNewerSourcesHook { year = "1980"; }) ]
|
2016-08-31 10:01:16 +01:00
|
|
|
++ (lib.optional (lib.hasSuffix "zip" attrs.src.name or "") unzip)
|
2017-11-11 15:24:38 +00:00
|
|
|
++ lib.optionals doCheck checkInputs
|
|
|
|
++ lib.optional catchConflicts setuptools # If we nog longer propagate setuptools
|
|
|
|
++ buildInputs
|
|
|
|
++ pythonPath
|
|
|
|
);
|
2016-08-17 13:23:47 +01:00
|
|
|
|
2017-11-11 15:24:38 +00:00
|
|
|
# Propagate python and setuptools. We should stop propagating setuptools.
|
2016-08-17 13:23:47 +01:00
|
|
|
propagatedBuildInputs = propagatedBuildInputs ++ [ python setuptools ];
|
|
|
|
|
|
|
|
# Python packages don't have a checkPhase, only an installCheckPhase
|
|
|
|
doCheck = false;
|
2016-09-01 16:10:38 +01:00
|
|
|
doInstallCheck = doCheck;
|
2016-08-17 13:23:47 +01:00
|
|
|
|
2017-05-25 20:56:25 +01:00
|
|
|
postFixup = lib.optionalString (!dontWrapPythonPrograms) ''
|
2016-08-17 13:23:47 +01:00
|
|
|
wrapPythonPrograms
|
|
|
|
'' + lib.optionalString catchConflicts ''
|
2017-04-01 11:19:53 +01:00
|
|
|
# Check if we have two packages with the same name in the closure and fail.
|
|
|
|
# If this happens, something went wrong with the dependencies specs.
|
|
|
|
# Intentionally kept in a subdirectory, see catch_conflicts/README.md.
|
|
|
|
${python.interpreter} ${./catch_conflicts}/catch_conflicts.py
|
2016-10-25 21:33:45 +01:00
|
|
|
'' + attrs.postFixup or '''';
|
2016-08-17 13:23:47 +01:00
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit python; # The python interpreter
|
2017-05-28 08:20:47 +01:00
|
|
|
inherit pythonModule;
|
2016-08-17 13:23:47 +01:00
|
|
|
} // passthru;
|
|
|
|
|
2017-11-11 12:37:21 +00:00
|
|
|
meta = {
|
2016-08-17 13:23:47 +01:00
|
|
|
# default to python's platforms
|
|
|
|
platforms = python.meta.platforms;
|
|
|
|
isBuildPythonPackage = python.meta.platforms;
|
2017-11-11 12:37:21 +00:00
|
|
|
} // meta;
|
2016-08-17 13:23:47 +01:00
|
|
|
})
|