summaryrefslogtreecommitdiff
path: root/pkgs/development/interpreters/python/meta-package.nix
blob: e3d8684331835bb96b07e068876da59f3f6a2f12 (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
{
  buildPythonPackage,
  lib,
  hatchling,
}:
{
  pname,
  version,
  dependencies ? [ ],
  optional-dependencies ? { },
  passthru ? { },
  meta ? { },
}:

# Create a "fake" meta package to satisfy a dependency on a package, but don't actually build it.
# This is useful for packages that have a split binary/source dichotomy like psycopg2/psycopg2-binary,
# where we want to use the former, but some projects declare a dependency on the latter.

buildPythonPackage {
  inherit
    pname
    version
    dependencies
    optional-dependencies
    meta
    passthru
    ;

  pyproject = true;

  # Make a minimal pyproject.toml that can be built
  unpackPhase = ''
    cat > pyproject.toml << EOF
    [project]
    name = "${pname}"
    version = "${version}"
    dependencies = ${builtins.toJSON (map lib.getName dependencies)}

    [project.optional-dependencies]
    ${lib.optionalString (optional-dependencies != { }) (
      lib.concatStringsSep "\n" (
        lib.mapAttrsToList (
          group: deps: group + " = " + builtins.toJSON (map lib.getName deps)
        ) optional-dependencies
      )
    )}

    [tool.hatch.build.targets.wheel]
    bypass-selection = true

    [build-system]
    requires = ["hatchling"]
    build-backend = "hatchling.build"
    EOF
  '';

  build-system = [ hatchling ];
}