2023-03-21 17:51:59 +02:00
|
|
|
{ config, dependencySets, drv-parts, lib, ... }:
|
2022-12-18 16:31:54 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
inherit (config) deps;
|
|
|
|
|
|
|
|
withDistOutput = lib.elem config.format [
|
|
|
|
"pyproject"
|
|
|
|
"setuptools"
|
|
|
|
"flit"
|
|
|
|
"wheel"
|
|
|
|
];
|
2022-12-18 16:45:24 +02:00
|
|
|
|
|
|
|
hasPyproject = config.format == "pyproject" && config.pyprojectToml != null;
|
|
|
|
|
|
|
|
pyproject = if hasPyproject then
|
|
|
|
lib.importTOML config.pyprojectToml
|
|
|
|
else
|
|
|
|
null;
|
2022-12-18 16:31:54 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2023-03-21 17:51:59 +02:00
|
|
|
imports = [
|
|
|
|
drv-parts.modules.drv-parts.mkDerivation
|
|
|
|
];
|
|
|
|
|
|
|
|
name = lib.mkIf hasPyproject (lib.mkDefault pyproject.tool.poetry.name);
|
2022-12-18 16:45:24 +02:00
|
|
|
version = lib.mkIf hasPyproject (lib.mkDefault pyproject.tool.poetry.version);
|
|
|
|
|
2022-12-18 16:31:54 +02:00
|
|
|
deps = { pkgs, python3Packages, ... }: {
|
|
|
|
inherit (python3Packages)
|
|
|
|
python
|
|
|
|
wrapPython
|
|
|
|
pythonRemoveTestsDirHook
|
|
|
|
pythonCatchConflictsHook
|
|
|
|
pythonRemoveBinBytecodeHook
|
|
|
|
unzip
|
|
|
|
setuptoolsBuildHook
|
|
|
|
flitBuildHook
|
|
|
|
pipBuildHook
|
|
|
|
wheelUnpackHook
|
|
|
|
eggUnpackHook eggBuildHook eggInstallHook
|
|
|
|
pipInstallHook
|
|
|
|
pythonImportsCheckHook
|
|
|
|
pythonNamespacesHook
|
|
|
|
pythonOutputDistHook
|
|
|
|
;
|
|
|
|
inherit (pkgs)
|
|
|
|
ensureNewerSourcesForZipFilesHook
|
2023-02-25 14:13:34 +02:00
|
|
|
stdenv
|
2022-12-18 16:31:54 +02:00
|
|
|
;
|
|
|
|
};
|
|
|
|
|
|
|
|
env = {
|
|
|
|
LANG = "${if deps.python.stdenv.isDarwin then "en_US" else "C"}.UTF-8";
|
|
|
|
};
|
|
|
|
|
2023-03-21 17:51:59 +02:00
|
|
|
mkDerivation = {
|
|
|
|
|
|
|
|
nativeBuildInputs = with deps; [
|
|
|
|
python
|
|
|
|
wrapPython
|
|
|
|
ensureNewerSourcesForZipFilesHook
|
|
|
|
pythonRemoveTestsDirHook
|
|
|
|
] ++ lib.optionals config.catchConflicts [
|
|
|
|
pythonCatchConflictsHook
|
|
|
|
] ++ lib.optionals config.removeBinByteCode [
|
|
|
|
pythonRemoveBinBytecodeHook
|
|
|
|
] ++ lib.optionals (lib.hasSuffix "zip" (config.src.name or "")) [
|
|
|
|
unzip
|
|
|
|
] ++ lib.optionals (config.format == "setuptools") [
|
|
|
|
setuptoolsBuildHook
|
|
|
|
] ++ lib.optionals (config.format == "flit") [
|
|
|
|
flitBuildHook
|
|
|
|
] ++ lib.optionals (config.format == "pyproject") [
|
|
|
|
pipBuildHook
|
|
|
|
] ++ lib.optionals (config.format == "wheel") [
|
|
|
|
wheelUnpackHook
|
|
|
|
] ++ lib.optionals (config.format == "egg") [
|
|
|
|
eggUnpackHook eggBuildHook eggInstallHook
|
|
|
|
] ++ lib.optionals (!(config.format == "other") || config.dontUsePipInstall) [
|
|
|
|
pipInstallHook
|
|
|
|
] ++ lib.optionals (python.stdenv.buildPlatform == python.stdenv.hostPlatform) [
|
|
|
|
# This is a test, however, it should be ran independent of the checkPhase and checkInputs
|
|
|
|
pythonImportsCheckHook
|
|
|
|
] ++ lib.optionals (python.pythonAtLeast "3.3") [
|
|
|
|
# Optionally enforce PEP420 for python3
|
|
|
|
pythonNamespacesHook
|
|
|
|
] ++ lib.optionals withDistOutput [
|
|
|
|
pythonOutputDistHook
|
|
|
|
];
|
2022-12-18 16:31:54 +02:00
|
|
|
|
2023-03-21 17:51:59 +02:00
|
|
|
propagatedBuildInputs = with deps; [
|
|
|
|
python
|
|
|
|
];
|
2022-12-18 16:31:54 +02:00
|
|
|
|
2023-03-21 17:51:59 +02:00
|
|
|
doCheck = false;
|
|
|
|
doInstallCheck = lib.mkDefault true;
|
|
|
|
installCheckInputs = lib.optionals (config.format == "setuptools") [
|
|
|
|
deps.setuptoolsCheckHook
|
|
|
|
];
|
|
|
|
|
|
|
|
postFixup = lib.mkBefore (lib.optionalString (!config.dontWrapPythonPrograms) ''
|
|
|
|
wrapPythonPrograms
|
|
|
|
'');
|
|
|
|
|
|
|
|
outputs = [ "out" ] ++ lib.optional withDistOutput "dist";
|
|
|
|
};
|
2022-12-18 16:31:54 +02:00
|
|
|
}
|