Python: separate buildPythonPackage into two functions
1. mkDerivation which is used when the source is without setup.py and not a wheel 2. buildPythonPackage which is used as before and calls mkDerivation
This commit is contained in:
parent
725c37b4d3
commit
3e05cce97c
@ -481,7 +481,7 @@ and the aliases
|
|||||||
#### `buildPythonPackage` function
|
#### `buildPythonPackage` function
|
||||||
|
|
||||||
The `buildPythonPackage` function is implemented in
|
The `buildPythonPackage` function is implemented in
|
||||||
`pkgs/development/interpreters/python/buildpythonpackage.nix`
|
`pkgs/development/interpreters/python/build-python-package.nix`
|
||||||
|
|
||||||
and can be used as:
|
and can be used as:
|
||||||
|
|
||||||
|
@ -3,57 +3,37 @@
|
|||||||
(http://pypi.python.org/pypi/setuptools/), which represents a large
|
(http://pypi.python.org/pypi/setuptools/), which represents a large
|
||||||
number of Python packages nowadays. */
|
number of Python packages nowadays. */
|
||||||
|
|
||||||
{ python, setuptools, unzip, wrapPython, lib, bootstrapped-pip
|
{ lib
|
||||||
, ensureNewerSourcesHook }:
|
, python
|
||||||
|
, mkPythonDerivation
|
||||||
|
, bootstrapped-pip
|
||||||
|
}:
|
||||||
|
|
||||||
{ name
|
{ buildInputs ? []
|
||||||
|
|
||||||
# by default prefix `name` e.g. "python3.3-${name}"
|
|
||||||
, namePrefix ? python.libPrefix + "-"
|
|
||||||
|
|
||||||
, buildInputs ? []
|
|
||||||
|
|
||||||
# propagate build dependencies so in case we have A -> B -> C,
|
# propagate build dependencies so in case we have A -> B -> C,
|
||||||
# C can import package A propagated by B
|
# C can import package A propagated by B
|
||||||
, propagatedBuildInputs ? []
|
#, propagatedBuildInputs ? []
|
||||||
|
|
||||||
# passed to "python setup.py build_ext"
|
# passed to "python setup.py build_ext"
|
||||||
# https://github.com/pypa/pip/issues/881
|
# https://github.com/pypa/pip/issues/881
|
||||||
, setupPyBuildFlags ? []
|
, setupPyBuildFlags ? []
|
||||||
|
|
||||||
# DEPRECATED: use propagatedBuildInputs
|
|
||||||
, pythonPath ? []
|
|
||||||
|
|
||||||
# used to disable derivation, useful for specific python versions
|
|
||||||
, disabled ? false
|
|
||||||
|
|
||||||
, meta ? {}
|
|
||||||
|
|
||||||
# Execute before shell hook
|
# Execute before shell hook
|
||||||
, preShellHook ? ""
|
, preShellHook ? ""
|
||||||
|
|
||||||
# Execute after shell hook
|
# Execute after shell hook
|
||||||
, postShellHook ? ""
|
, postShellHook ? ""
|
||||||
|
|
||||||
# Additional arguments to pass to the makeWrapper function, which wraps
|
|
||||||
# generated binaries.
|
|
||||||
, makeWrapperArgs ? []
|
|
||||||
|
|
||||||
# Additional flags to pass to "pip install".
|
# Additional flags to pass to "pip install".
|
||||||
, installFlags ? []
|
, installFlags ? []
|
||||||
|
|
||||||
# Raise an error if two packages are installed with the same name
|
|
||||||
, catchConflicts ? true
|
|
||||||
|
|
||||||
, format ? "setup"
|
, format ? "setup"
|
||||||
|
|
||||||
, ... } @ attrs:
|
, ... } @ attrs:
|
||||||
|
|
||||||
|
|
||||||
# Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
|
|
||||||
if disabled
|
|
||||||
then throw "${name} not supported for interpreter ${python.executable}"
|
|
||||||
else
|
|
||||||
|
|
||||||
let
|
let
|
||||||
# use setuptools shim (so that setuptools is imported before distutils)
|
# use setuptools shim (so that setuptools is imported before distutils)
|
||||||
@ -73,14 +53,10 @@ let
|
|||||||
installCheckPhase = attrs.checkPhase or ":";
|
installCheckPhase = attrs.checkPhase or ":";
|
||||||
|
|
||||||
# Wheels don't have any checks to run
|
# Wheels don't have any checks to run
|
||||||
doInstallCheck = attrs.doCheck or false;
|
doCheck = attrs.doCheck or false;
|
||||||
}
|
}
|
||||||
else if format == "setup" then
|
else if format == "setup" then
|
||||||
{
|
{
|
||||||
# propagate python/setuptools to active setup-hook in nix-shell
|
|
||||||
propagatedBuildInputs =
|
|
||||||
propagatedBuildInputs ++ [ python setuptools ];
|
|
||||||
|
|
||||||
# we copy nix_run_setup.py over so it's executed relative to the root of the source
|
# we copy nix_run_setup.py 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 ''
|
||||||
@ -100,21 +76,17 @@ let
|
|||||||
# are typically distributed with tests.
|
# are typically distributed with tests.
|
||||||
# With Python it's a common idiom to run the tests
|
# With Python it's a common idiom to run the tests
|
||||||
# after the software has been installed.
|
# after the software has been installed.
|
||||||
|
doCheck = attrs.doCheck or true;
|
||||||
# For backwards compatibility, let's use an alias
|
|
||||||
doInstallCheck = attrs.doCheck or true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw "Unsupported format ${format}";
|
throw "Unsupported format ${format}";
|
||||||
in
|
|
||||||
python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] // {
|
|
||||||
name = namePrefix + name;
|
|
||||||
|
|
||||||
buildInputs = [ wrapPython bootstrapped-pip ] ++ buildInputs ++ pythonPath
|
in mkPythonDerivation ( attrs // {
|
||||||
++ [ (ensureNewerSourcesHook { year = "1980"; }) ]
|
|
||||||
++ (lib.optional (lib.hasSuffix "zip" attrs.src.name or "") unzip);
|
|
||||||
|
|
||||||
pythonPath = pythonPath;
|
# To build and install a wheel we need pip
|
||||||
|
buildInputs = buildInputs ++ [ bootstrapped-pip ];
|
||||||
|
|
||||||
|
#inherit propagatedBuildInputs;
|
||||||
|
|
||||||
configurePhase = attrs.configurePhase or ''
|
configurePhase = attrs.configurePhase or ''
|
||||||
runHook preConfigure
|
runHook preConfigure
|
||||||
@ -126,9 +98,6 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] //
|
|||||||
runHook postConfigure
|
runHook postConfigure
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Python packages don't have a checkPhase, only an installCheckPhase
|
|
||||||
doCheck = false;
|
|
||||||
|
|
||||||
installPhase = attrs.installPhase or ''
|
installPhase = attrs.installPhase or ''
|
||||||
runHook preInstall
|
runHook preInstall
|
||||||
|
|
||||||
@ -142,14 +111,6 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] //
|
|||||||
runHook postInstall
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
|
||||||
postFixup = attrs.postFixup or ''
|
|
||||||
wrapPythonPrograms
|
|
||||||
'' + lib.optionalString catchConflicts ''
|
|
||||||
# check if we have two packages with the same name in closure and fail
|
|
||||||
# this shouldn't happen, something went wrong with dependencies specs
|
|
||||||
${python.interpreter} ${./catch_conflicts.py}
|
|
||||||
'';
|
|
||||||
|
|
||||||
shellHook = attrs.shellHook or ''
|
shellHook = attrs.shellHook or ''
|
||||||
${preShellHook}
|
${preShellHook}
|
||||||
if test -e setup.py; then
|
if test -e setup.py; then
|
||||||
@ -162,13 +123,4 @@ python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled" "doCheck"] //
|
|||||||
${postShellHook}
|
${postShellHook}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
meta = with lib.maintainers; {
|
|
||||||
# default to python's platforms
|
|
||||||
platforms = python.meta.platforms;
|
|
||||||
} // meta // {
|
|
||||||
# add extra maintainer(s) to every package
|
|
||||||
maintainers = (meta.maintainers or []) ++ [ chaoflow domenkozar ];
|
|
||||||
# a marker for release utilities to discover python packages
|
|
||||||
isBuildPythonPackage = python.meta.platforms;
|
|
||||||
};
|
|
||||||
} // formatspecific)
|
} // formatspecific)
|
@ -0,0 +1,87 @@
|
|||||||
|
/* Generic builder for Python packages that come without a setup.py. */
|
||||||
|
|
||||||
|
{ lib
|
||||||
|
, python
|
||||||
|
, wrapPython
|
||||||
|
, setuptools
|
||||||
|
, unzip
|
||||||
|
, ensureNewerSourcesHook
|
||||||
|
}:
|
||||||
|
|
||||||
|
{ name
|
||||||
|
|
||||||
|
# by default prefix `name` e.g. "python3.3-${name}"
|
||||||
|
, namePrefix ? python.libPrefix + "-"
|
||||||
|
|
||||||
|
, buildInputs ? []
|
||||||
|
|
||||||
|
# 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 ? []
|
||||||
|
|
||||||
|
, meta ? {}
|
||||||
|
|
||||||
|
, passthru ? {}
|
||||||
|
|
||||||
|
, ... } @ attrs:
|
||||||
|
|
||||||
|
|
||||||
|
# Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
|
||||||
|
if disabled
|
||||||
|
then throw "${name} not supported for interpreter ${python.executable}"
|
||||||
|
else
|
||||||
|
|
||||||
|
python.stdenv.mkDerivation (builtins.removeAttrs attrs ["disabled"] // {
|
||||||
|
|
||||||
|
name = namePrefix + name;
|
||||||
|
|
||||||
|
inherit pythonPath;
|
||||||
|
|
||||||
|
buildInputs = [ wrapPython ] ++ buildInputs ++ pythonPath
|
||||||
|
++ [ (ensureNewerSourcesHook { year = "1980"; }) ]
|
||||||
|
++ (lib.optional (lib.hasSuffix "zip" attrs.src.name or "") unzip);
|
||||||
|
|
||||||
|
# propagate python/setuptools to active setup-hook in nix-shell
|
||||||
|
propagatedBuildInputs = propagatedBuildInputs ++ [ python setuptools ];
|
||||||
|
|
||||||
|
# Python packages don't have a checkPhase, only an installCheckPhase
|
||||||
|
doCheck = false;
|
||||||
|
doInstallCheck = attrs.doCheck or false;
|
||||||
|
|
||||||
|
postFixup = attrs.postFixup or ''
|
||||||
|
wrapPythonPrograms
|
||||||
|
'' + lib.optionalString catchConflicts ''
|
||||||
|
# check if we have two packages with the same name in closure and fail
|
||||||
|
# this shouldn't happen, something went wrong with dependencies specs
|
||||||
|
${python.interpreter} ${./catch_conflicts.py}
|
||||||
|
'';
|
||||||
|
|
||||||
|
passthru = {
|
||||||
|
inherit python; # The python interpreter
|
||||||
|
} // passthru;
|
||||||
|
|
||||||
|
meta = with lib.maintainers; {
|
||||||
|
# default to python's platforms
|
||||||
|
platforms = python.meta.platforms;
|
||||||
|
} // meta // {
|
||||||
|
# add extra maintainer(s) to every package
|
||||||
|
maintainers = (meta.maintainers or []) ++ [ chaoflow domenkozar ];
|
||||||
|
# a marker for release utilities to discover python packages
|
||||||
|
isBuildPythonPackage = python.meta.platforms;
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
|
|
@ -18,7 +18,10 @@ let
|
|||||||
|
|
||||||
bootstrapped-pip = callPackage ../development/python-modules/bootstrapped-pip { };
|
bootstrapped-pip = callPackage ../development/python-modules/bootstrapped-pip { };
|
||||||
|
|
||||||
buildPythonPackage = makeOverridable (callPackage ../development/interpreters/python/buildpythonpackage.nix {
|
mkPythonDerivation = makeOverridable( callPackage ../development/interpreters/python/mk-python-derivation.nix {
|
||||||
|
});
|
||||||
|
buildPythonPackage = makeOverridable (callPackage ../development/interpreters/python/build-python-package.nix {
|
||||||
|
inherit mkPythonDerivation;
|
||||||
inherit bootstrapped-pip;
|
inherit bootstrapped-pip;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -34,7 +37,7 @@ let
|
|||||||
|
|
||||||
in modules // {
|
in modules // {
|
||||||
|
|
||||||
inherit python bootstrapped-pip isPy26 isPy27 isPy33 isPy34 isPy35 isPy36 isPyPy isPy3k buildPythonPackage buildPythonApplication;
|
inherit python bootstrapped-pip isPy26 isPy27 isPy33 isPy34 isPy35 isPy36 isPyPy isPy3k mkPythonDerivation buildPythonPackage buildPythonApplication;
|
||||||
|
|
||||||
# helpers
|
# helpers
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user