Merge pull request #254547 from DavHau/fix-pyproject-build

python3.pkgs.pypaBuildHook: fix conflicts via propagated inputs
This commit is contained in:
Lassulus
2023-09-15 21:40:45 +02:00
committed by GitHub
4 changed files with 73 additions and 8 deletions
@@ -66,7 +66,19 @@ in {
pypaBuildHook = callPackage ({ makePythonHook, build, wheel }:
makePythonHook {
name = "pypa-build-hook.sh";
propagatedBuildInputs = [ build wheel ];
propagatedBuildInputs = [ wheel ];
substitutions = {
inherit build;
};
# A test to ensure that this hook never propagates any of its dependencies
# into the build environment.
# This prevents false positive alerts raised by catchConflictsHook.
# Such conflicts don't happen within the standard nixpkgs python package
# set, but in downstream projects that build packages depending on other
# versions of this hook's dependencies.
passthru.tests = import ./pypa-build-hook-tests.nix {
inherit pythonForBuild runCommand;
};
} ./pypa-build-hook.sh) {
inherit (pythonForBuild.pkgs) build;
};
@@ -0,0 +1,32 @@
{ pythonForBuild, runCommand }: {
dont-propagate-conflicting-deps = let
# customize a package so that its store paths differs
mkConflict = pkg: pkg.overrideAttrs { some_modification = true; };
# minimal pyproject.toml for the example project
pyprojectToml = builtins.toFile "pyproject.toml" ''
[project]
name = "my-project"
version = "1.0.0"
'';
# the source of the example project
projectSource = runCommand "my-project-source" {} ''
mkdir -p $out/src
cp ${pyprojectToml} $out/pyproject.toml
touch $out/src/__init__.py
'';
in
# this build must never triger conflicts
pythonForBuild.pkgs.buildPythonPackage {
pname = "dont-propagate-conflicting-deps";
version = "0.0.0";
src = projectSource;
format = "pyproject";
propagatedBuildInputs = [
# At least one dependency of `build` should be included here to
# keep the test meaningful
(mkConflict pythonForBuild.pkgs.tomli)
# setuptools is also needed to build the example project
pythonForBuild.pkgs.setuptools
];
};
}
@@ -6,7 +6,7 @@ pypaBuildPhase() {
runHook preBuild
echo "Creating a wheel..."
pyproject-build --no-isolation --outdir dist/ --wheel $pypaBuildFlags
@build@/bin/pyproject-build --no-isolation --outdir dist/ --wheel $pypaBuildFlags
echo "Finished creating a wheel..."
runHook postBuild