2017-11-11 07:24:38 -08:00
|
|
|
# Generic builder.
|
2016-08-17 05:23:47 -07:00
|
|
|
|
|
|
|
{ lib
|
2018-04-25 10:15:48 -07:00
|
|
|
, config
|
2016-08-17 05:23:47 -07:00
|
|
|
, python
|
|
|
|
, wrapPython
|
|
|
|
, setuptools
|
|
|
|
, unzip
|
2018-02-13 06:32:16 -08:00
|
|
|
, ensureNewerSourcesForZipFilesHook
|
2017-05-28 00:20:47 -07:00
|
|
|
# Whether the derivation provides a Python module or not.
|
2017-12-10 05:20:38 -08:00
|
|
|
, toPythonModule
|
2017-05-28 00:20:47 -07:00
|
|
|
, namePrefix
|
2016-08-17 05:23:47 -07:00
|
|
|
}:
|
|
|
|
|
2017-11-02 21:14:22 -07:00
|
|
|
{ name ? "${attrs.pname}-${attrs.version}"
|
2016-08-17 05:23:47 -07:00
|
|
|
|
2017-12-21 12:49:06 -08:00
|
|
|
# Build-time dependencies for the package
|
|
|
|
, nativeBuildInputs ? []
|
|
|
|
|
|
|
|
# Run-time dependencies for the package
|
2016-08-17 05:23:47 -07:00
|
|
|
, buildInputs ? []
|
|
|
|
|
2016-08-31 02:01:16 -07:00
|
|
|
# Dependencies needed for running the checkPhase.
|
|
|
|
# These are added to buildInputs when doCheck = true.
|
|
|
|
, checkInputs ? []
|
|
|
|
|
2016-08-17 05:23:47 -07: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 12:56:25 -07:00
|
|
|
# Skip wrapping of python programs altogether
|
|
|
|
, dontWrapPythonPrograms ? false
|
|
|
|
|
2017-12-10 06:41:05 -08: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
|
|
|
|
|
2016-08-17 05:23:47 -07:00
|
|
|
, meta ? {}
|
|
|
|
|
|
|
|
, passthru ? {}
|
|
|
|
|
2018-04-25 10:15:48 -07:00
|
|
|
, doCheck ? config.doCheckByDefault or false
|
2016-09-01 08:10:38 -07:00
|
|
|
|
2016-08-17 05:23:47 -07:00
|
|
|
, ... } @ attrs:
|
|
|
|
|
|
|
|
|
|
|
|
# Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
|
|
|
|
if disabled
|
|
|
|
then throw "${name} not supported for interpreter ${python.executable}"
|
|
|
|
else
|
|
|
|
|
2017-12-10 05:20:38 -08:00
|
|
|
toPythonModule (python.stdenv.mkDerivation (builtins.removeAttrs attrs [
|
2017-11-11 07:21:02 -08:00
|
|
|
"disabled" "checkInputs" "doCheck" "doInstallCheck" "dontWrapPythonPrograms" "catchConflicts"
|
|
|
|
] // {
|
2016-08-17 05:23:47 -07:00
|
|
|
|
|
|
|
name = namePrefix + name;
|
|
|
|
|
2018-02-13 06:32:16 -08:00
|
|
|
nativeBuildInputs = [ ensureNewerSourcesForZipFilesHook ]
|
2017-12-21 12:49:06 -08:00
|
|
|
++ nativeBuildInputs;
|
|
|
|
|
|
|
|
buildInputs = [ wrapPython ]
|
|
|
|
++ lib.optional (lib.hasSuffix "zip" (attrs.src.name or "")) unzip
|
|
|
|
++ lib.optional catchConflicts setuptools # If we no longer propagate setuptools
|
2017-11-11 07:24:38 -08:00
|
|
|
++ buildInputs
|
2017-12-21 12:49:06 -08:00
|
|
|
++ pythonPath;
|
2016-08-17 05:23:47 -07:00
|
|
|
|
2017-11-11 07:24:38 -08:00
|
|
|
# Propagate python and setuptools. We should stop propagating setuptools.
|
2016-08-17 05:23:47 -07:00
|
|
|
propagatedBuildInputs = propagatedBuildInputs ++ [ python setuptools ];
|
|
|
|
|
|
|
|
# Python packages don't have a checkPhase, only an installCheckPhase
|
|
|
|
doCheck = false;
|
2016-09-01 08:10:38 -07:00
|
|
|
doInstallCheck = doCheck;
|
2018-03-14 17:00:04 -07:00
|
|
|
installCheckInputs = checkInputs;
|
2016-08-17 05:23:47 -07:00
|
|
|
|
2017-05-25 12:56:25 -07:00
|
|
|
postFixup = lib.optionalString (!dontWrapPythonPrograms) ''
|
2016-08-17 05:23:47 -07:00
|
|
|
wrapPythonPrograms
|
2017-12-10 06:41:05 -08:00
|
|
|
'' + lib.optionalString removeBinBytecode ''
|
|
|
|
if [ -d "$out/bin" ]; then
|
|
|
|
rm -rf "$out/bin/__pycache__" # Python 3
|
|
|
|
find "$out/bin" -type f -name "*.pyc" -delete # Python 2
|
|
|
|
fi
|
2016-08-17 05:23:47 -07:00
|
|
|
'' + lib.optionalString catchConflicts ''
|
2017-04-01 03:19:53 -07: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 13:33:45 -07:00
|
|
|
'' + attrs.postFixup or '''';
|
2016-08-17 05:23:47 -07:00
|
|
|
|
2017-11-11 04:37:21 -08:00
|
|
|
meta = {
|
2016-08-17 05:23:47 -07:00
|
|
|
# default to python's platforms
|
|
|
|
platforms = python.meta.platforms;
|
|
|
|
isBuildPythonPackage = python.meta.platforms;
|
2017-11-11 04:37:21 -08:00
|
|
|
} // meta;
|
2017-12-10 05:20:38 -08:00
|
|
|
}))
|