1{ 2 lib, 3 stdenv, 4 python, 5 build, 6 flit-core, 7 installer, 8 packaging, 9 pyproject-hooks, 10 tomli, 11 makeWrapper, 12}: 13let 14 buildBootstrapPythonModule = 15 basePackage: attrs: 16 stdenv.mkDerivation ( 17 { 18 pname = "${python.libPrefix}-bootstrap-${basePackage.pname}"; 19 inherit (basePackage) version src meta; 20 21 nativeBuildInputs = [ makeWrapper ]; 22 23 buildPhase = '' 24 runHook preBuild 25 26 PYTHONPATH="${flit-core}/${python.sitePackages}" \ 27 ${python.interpreter} -m flit_core.wheel 28 29 runHook postBuild 30 ''; 31 32 installPhase = '' 33 runHook preInstall 34 35 PYTHONPATH="${installer}/${python.sitePackages}" \ 36 ${python.interpreter} -m installer \ 37 --destdir "$out" --prefix "" dist/*.whl 38 39 runHook postInstall 40 ''; 41 } 42 // attrs 43 ); 44 45 bootstrap-packaging = buildBootstrapPythonModule packaging { }; 46 47 bootstrap-pyproject-hooks = buildBootstrapPythonModule pyproject-hooks { }; 48 49 bootstrap-tomli = buildBootstrapPythonModule tomli { }; 50 51 sitePkgs = python.sitePackages; 52in 53buildBootstrapPythonModule build { 54 # like the installPhase above, but wrapping the pyproject-build command 55 # to set up PYTHONPATH with the correct dependencies. 56 # This allows using `pyproject-build` without propagating its dependencies 57 # into the build environment, which is necessary to prevent 58 # pythonCatchConflicts from raising false positive alerts. 59 # This would happen whenever the package to build has a dependency on 60 # another version of a package that is also a dependency of pyproject-build. 61 installPhase = '' 62 runHook preInstall 63 64 PYTHONPATH="${installer}/${python.sitePackages}" \ 65 ${python.interpreter} -m installer \ 66 --destdir "$out" --prefix "" dist/*.whl 67 68 wrapProgram $out/bin/pyproject-build \ 69 --prefix PYTHONPATH : "$out/${sitePkgs}" \ 70 --prefix PYTHONPATH : "${bootstrap-pyproject-hooks}/${sitePkgs}" \ 71 --prefix PYTHONPATH : "${bootstrap-packaging}/${sitePkgs}" \ 72 --prefix PYTHONPATH : "${bootstrap-tomli}/${sitePkgs}" 73 74 runHook postInstall 75 ''; 76}