2009-05-25 01:02:59 +04:00
|
|
|
/* This function provides a generic Python package builder. It is
|
2014-01-07 02:24:05 +04:00
|
|
|
intended to work with packages that use `distutils/setuptools'
|
2009-05-25 01:02:59 +04:00
|
|
|
(http://pypi.python.org/pypi/setuptools/), which represents a large
|
|
|
|
number of Python packages nowadays. */
|
|
|
|
|
2015-11-17 13:38:26 +03:00
|
|
|
{ python, setuptools, unzip, wrapPython, lib, bootstrapped-pip }:
|
2009-05-25 01:02:59 +04:00
|
|
|
|
2014-01-07 02:24:05 +04:00
|
|
|
{ name
|
2009-05-25 01:02:59 +04:00
|
|
|
|
2014-01-11 14:44:24 +04:00
|
|
|
# by default prefix `name` e.g. "python3.3-${name}"
|
2014-01-07 02:24:05 +04:00
|
|
|
, namePrefix ? python.libPrefix + "-"
|
2010-07-28 17:05:04 +04:00
|
|
|
|
2014-01-07 02:24:05 +04:00
|
|
|
, buildInputs ? []
|
2012-12-03 08:20:50 +04:00
|
|
|
|
2014-01-11 14:44:24 +04:00
|
|
|
# propagate build dependencies so in case we have A -> B -> C,
|
|
|
|
# C can import propagated packages by A
|
2014-01-07 02:24:05 +04:00
|
|
|
, propagatedBuildInputs ? []
|
2013-01-17 17:19:14 +04:00
|
|
|
|
2014-01-07 02:24:05 +04:00
|
|
|
# passed to "python setup.py build"
|
2015-11-17 13:38:26 +03:00
|
|
|
# https://github.com/pypa/pip/issues/881
|
2014-01-07 02:24:05 +04:00
|
|
|
, setupPyBuildFlags ? []
|
2009-05-25 01:02:59 +04:00
|
|
|
|
2014-01-07 02:24:05 +04:00
|
|
|
# enable tests by default
|
2011-03-30 16:27:04 +04:00
|
|
|
, doCheck ? true
|
|
|
|
|
2015-11-17 13:38:26 +03:00
|
|
|
# DEPRECATED: use propagatedBuildInputs
|
2014-08-24 18:01:21 +04:00
|
|
|
, pythonPath ? []
|
|
|
|
|
|
|
|
# used to disable derivation, useful for specific python versions
|
|
|
|
, disabled ? false
|
2009-06-28 18:05:41 +04:00
|
|
|
|
2014-01-11 00:57:28 +04:00
|
|
|
, meta ? {}
|
2013-01-19 21:21:23 +04:00
|
|
|
|
2014-03-10 13:06:04 +04:00
|
|
|
# Execute before shell hook
|
|
|
|
, preShellHook ? ""
|
|
|
|
|
|
|
|
# Execute after shell hook
|
|
|
|
, postShellHook ? ""
|
|
|
|
|
2015-05-24 18:19:13 +03:00
|
|
|
# Additional arguments to pass to the makeWrapper function, which wraps
|
|
|
|
# generated binaries.
|
|
|
|
, makeWrapperArgs ? []
|
2015-05-22 07:32:03 +03:00
|
|
|
|
2011-03-28 19:30:48 +04:00
|
|
|
, ... } @ attrs:
|
2009-05-25 01:02:59 +04:00
|
|
|
|
2014-08-24 18:01:21 +04:00
|
|
|
|
2014-01-07 02:24:05 +04:00
|
|
|
# Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
|
2015-05-22 07:32:03 +03:00
|
|
|
if disabled
|
|
|
|
then throw "${name} not supported for interpreter ${python.executable}"
|
|
|
|
else
|
|
|
|
|
2015-11-17 13:38:26 +03:00
|
|
|
let
|
|
|
|
setuppy = "import setuptools, tokenize;__file__='setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))";
|
|
|
|
in
|
2015-10-30 13:31:09 +03:00
|
|
|
python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled"] // {
|
2014-01-07 02:24:05 +04:00
|
|
|
inherit doCheck;
|
2009-05-25 01:02:59 +04:00
|
|
|
|
2011-03-28 19:30:48 +04:00
|
|
|
name = namePrefix + name;
|
2009-05-25 01:02:59 +04:00
|
|
|
|
2015-11-17 13:38:26 +03:00
|
|
|
buildInputs = [ wrapPython bootstrapped-pip ] ++ buildInputs ++ pythonPath
|
2014-03-10 17:51:05 +04:00
|
|
|
++ (lib.optional (lib.hasSuffix "zip" attrs.src.name or "") unzip);
|
2009-05-25 01:02:59 +04:00
|
|
|
|
2015-04-13 04:15:31 +03:00
|
|
|
# propagate python/setuptools to active setup-hook in nix-shell
|
2015-11-17 13:38:26 +03:00
|
|
|
propagatedBuildInputs = propagatedBuildInputs ++ [ python setuptools ];
|
2012-07-21 03:55:50 +04:00
|
|
|
|
2015-04-13 04:15:31 +03:00
|
|
|
pythonPath = pythonPath;
|
2012-11-23 20:27:55 +04:00
|
|
|
|
2014-01-07 02:24:05 +04:00
|
|
|
configurePhase = attrs.configurePhase or ''
|
|
|
|
runHook preConfigure
|
|
|
|
|
2014-01-11 01:04:05 +04:00
|
|
|
# patch python interpreter to write null timestamps when compiling python files
|
2015-11-17 13:38:26 +03:00
|
|
|
# this way python doesn't try to update them when we freeze timestamps in nix store
|
2013-06-22 09:52:27 +04:00
|
|
|
export DETERMINISTIC_BUILD=1
|
2014-01-07 02:24:05 +04:00
|
|
|
|
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
|
|
|
checkPhase = attrs.checkPhase or ''
|
2015-11-17 13:38:26 +03:00
|
|
|
runHook preCheck
|
|
|
|
${python.interpreter} -c "${setuppy}" test
|
|
|
|
runHook postCheck
|
2014-01-07 02:24:05 +04:00
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = attrs.buildPhase or ''
|
|
|
|
runHook preBuild
|
2015-11-17 13:38:26 +03:00
|
|
|
${python.interpreter} -c "${setuppy}" bdist_wheel
|
2014-01-07 02:24:05 +04:00
|
|
|
runHook postBuild
|
2012-11-29 18:29:41 +04:00
|
|
|
'';
|
2009-05-25 01:02:59 +04:00
|
|
|
|
2014-01-07 02:24:05 +04:00
|
|
|
installPhase = attrs.installPhase or ''
|
|
|
|
runHook preInstall
|
|
|
|
|
2015-11-17 13:38:26 +03:00
|
|
|
mkdir -p "$out/${python.sitePackages}"
|
|
|
|
export PYTHONPATH="$out/${python.sitePackages}:$PYTHONPATH"
|
2012-11-23 18:54:55 +04:00
|
|
|
|
2015-11-17 13:38:26 +03:00
|
|
|
pushd dist
|
|
|
|
${bootstrapped-pip}/bin/pip install *.whl --no-index --prefix=$out
|
|
|
|
popd
|
2012-11-23 18:54:55 +04:00
|
|
|
|
2014-01-07 02:24:05 +04:00
|
|
|
runHook postInstall
|
2009-05-25 01:02:59 +04:00
|
|
|
'';
|
|
|
|
|
2014-05-21 16:46:37 +04:00
|
|
|
postFixup = attrs.postFixup or ''
|
2015-11-17 13:38:26 +03:00
|
|
|
wrapPythonPrograms
|
|
|
|
'';
|
2014-01-07 02:24:05 +04:00
|
|
|
|
2014-03-10 13:06:04 +04:00
|
|
|
shellHook = attrs.shellHook or ''
|
2015-11-15 15:49:20 +03:00
|
|
|
${preShellHook}
|
2014-06-15 18:05:09 +04:00
|
|
|
if test -e setup.py; then
|
2015-11-15 15:49:20 +03:00
|
|
|
tmp_path=$(mktemp -d)
|
2014-09-19 16:23:45 +04:00
|
|
|
export PATH="$tmp_path/bin:$PATH"
|
2015-11-15 15:49:20 +03:00
|
|
|
export PYTHONPATH="$tmp_path/${python.sitePackages}:$PYTHONPATH"
|
|
|
|
${python.interpreter} setup.py develop --prefix $tmp_path
|
2014-06-15 18:05:09 +04:00
|
|
|
fi
|
2015-11-15 15:49:20 +03:00
|
|
|
${postShellHook}
|
2014-03-10 13:06:04 +04:00
|
|
|
'';
|
|
|
|
|
2014-01-22 13:15:26 +04:00
|
|
|
meta = with lib.maintainers; {
|
2014-01-07 02:24:05 +04:00
|
|
|
# default to python's platforms
|
|
|
|
platforms = python.meta.platforms;
|
2014-01-22 13:15:26 +04:00
|
|
|
} // meta // {
|
2014-01-07 02:24:05 +04:00
|
|
|
# add extra maintainer(s) to every package
|
2014-01-11 14:44:24 +04:00
|
|
|
maintainers = (meta.maintainers or []) ++ [ chaoflow iElectric ];
|
2014-01-07 02:24:05 +04:00
|
|
|
};
|
2011-03-28 19:30:48 +04:00
|
|
|
})
|