summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/bootstrap/build/default.nix
blob: 0d693e2dde58b351538ce143f326388540ddb0c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
{
  stdenv,
  python,
  build,
  flit-core,
  installer,
  packaging,
  pyproject-hooks,
  tomli,
  makeWrapper,
}:
let
  buildBootstrapPythonModule =
    basePackage: attrs:
    stdenv.mkDerivation (
      {
        pname = "${python.libPrefix}-bootstrap-${basePackage.pname}";
        inherit (basePackage) version src meta;

        nativeBuildInputs = [ makeWrapper ];

        buildPhase = ''
          runHook preBuild

          PYTHONPATH="${flit-core}/${python.sitePackages}" \
            ${python.interpreter} -m flit_core.wheel

          runHook postBuild
        '';

        installPhase = ''
          runHook preInstall

          PYTHONPATH="${installer}/${python.sitePackages}" \
            ${python.interpreter} -m installer \
              --destdir "$out" --prefix "" dist/*.whl

          runHook postInstall
        '';
      }
      // attrs
    );

  bootstrap-packaging = buildBootstrapPythonModule packaging { };

  bootstrap-pyproject-hooks = buildBootstrapPythonModule pyproject-hooks { };

  bootstrap-tomli = buildBootstrapPythonModule tomli { };

  sitePkgs = python.sitePackages;
in
buildBootstrapPythonModule build {
  # like the installPhase above, but wrapping the pyproject-build command
  #   to set up PYTHONPATH with the correct dependencies.
  # This allows using `pyproject-build` without propagating its dependencies
  #   into the build environment, which is necessary to prevent
  #   pythonCatchConflicts from raising false positive alerts.
  # This would happen whenever the package to build has a dependency on
  #   another version of a package that is also a dependency of pyproject-build.
  installPhase = ''
    runHook preInstall

    PYTHONPATH="${installer}/${python.sitePackages}" \
      ${python.interpreter} -m installer \
        --destdir "$out" --prefix "" dist/*.whl

    wrapProgram $out/bin/pyproject-build \
      --prefix PYTHONPATH : "$out/${sitePkgs}" \
      --prefix PYTHONPATH : "${bootstrap-pyproject-hooks}/${sitePkgs}" \
      --prefix PYTHONPATH : "${bootstrap-packaging}/${sitePkgs}" \
      --prefix PYTHONPATH : "${bootstrap-tomli}/${sitePkgs}"

    runHook postInstall
  '';
}