base16-schemes: unstable-2024-06-21 -> unstable-2024-11-12
[NixPkgs.git] / pkgs / by-name / po / poetry / package.nix
blobdda8d0a132a194847cce6816a629c3fdb42f77fe
1 { lib, python3, fetchFromGitHub }:
3 let
4   newPackageOverrides =
5     self: super: {
6       poetry = self.callPackage ./unwrapped.nix { };
8       # The versions of Poetry and poetry-core need to match exactly,
9       # and poetry-core in nixpkgs requires a staging cycle to be updated,
10       # so apply an override here.
11       #
12       # We keep the override around even when the versions match, as
13       # it's likely to become relevant again after the next Poetry update.
14       poetry-core = super.poetry-core.overridePythonAttrs (old: rec {
15         version = "1.9.1";
16         src = fetchFromGitHub {
17           owner = "python-poetry";
18           repo = "poetry-core";
19           rev = "refs/tags/${version}";
20           hash = "sha256-L8lR9sUdRYqjkDCQ0XHXZm5X6xD40t1gxlGiovvb/+8=";
21         };
22         patches = [ ];
23       });
24     } // (plugins self);
25   python = python3.override (old: {
26     self = python;
27     packageOverrides = lib.composeManyExtensions
28       ((if old ? packageOverrides then [ old.packageOverrides ] else [ ]) ++ [ newPackageOverrides ]);
29   });
31   plugins = ps: with ps; {
32     poetry-audit-plugin = callPackage ./plugins/poetry-audit-plugin.nix { };
33     poetry-plugin-export = callPackage ./plugins/poetry-plugin-export.nix { };
34     poetry-plugin-up = callPackage ./plugins/poetry-plugin-up.nix { };
35     poetry-plugin-poeblix = callPackage ./plugins/poetry-plugin-poeblix.nix { };
36   };
38   # selector is a function mapping pythonPackages to a list of plugins
39   # e.g. poetry.withPlugins (ps: with ps; [ poetry-plugin-up ])
40   withPlugins = selector: let
41     selected = selector (plugins python.pkgs);
42   in python.pkgs.toPythonApplication (python.pkgs.poetry.overridePythonAttrs (old: {
43     dependencies = old.dependencies ++ selected;
45     # save some build time when adding plugins by disabling tests
46     doCheck = selected == [ ];
48     # Propagating dependencies leaks them through $PYTHONPATH which causes issues
49     # when used in nix-shell.
50     postFixup = ''
51       rm $out/nix-support/propagated-build-inputs
52     '';
54     passthru = {
55       plugins = plugins python.pkgs;
56       inherit withPlugins python;
57     };
58   }));
59 in withPlugins (ps: [ ])