nixpkgs/pkgs/tools/package-management/poetry/default.nix
2023-03-04 12:02:00 -08:00

51 lines
1.5 KiB
Nix

{ lib
, python3
, fetchFromGitHub
}:
let
python = python3.override {
packageOverrides = self: super: {
poetry = self.callPackage ./unwrapped.nix { };
# version overrides required by poetry and its plugins
platformdirs = super.platformdirs.overridePythonAttrs (old: rec {
version = "2.6.2";
src = fetchFromGitHub {
owner = "platformdirs";
repo = "platformdirs";
rev = "refs/tags/${version}";
hash = "sha256-yGpDAwn8Kt6vF2K2zbAs8+fowhYQmvsm/87WJofuhME=";
};
SETUPTOOLS_SCM_PRETEND_VERSION = version;
});
};
};
plugins = with python.pkgs; {
poetry-audit-plugin = callPackage ./plugins/poetry-audit-plugin.nix { };
poetry-plugin-up = callPackage ./plugins/poetry-plugin-up.nix { };
};
# selector is a function mapping pythonPackages to a list of plugins
# e.g. poetry.withPlugins (ps: with ps; [ poetry-plugin-up ])
withPlugins = selector: let
selected = selector plugins;
in python.pkgs.toPythonApplication (python.pkgs.poetry.overridePythonAttrs (old: {
propagatedBuildInputs = old.propagatedBuildInputs ++ selected;
# save some build time when adding plugins by disabling tests
doCheck = selected == [ ];
# Propagating dependencies leaks them through $PYTHONPATH which causes issues
# when used in nix-shell.
postFixup = ''
rm $out/nix-support/propagated-build-inputs
'';
passthru = rec {
inherit plugins withPlugins python;
};
}));
in withPlugins (ps: [ ])