depot/third_party/nixpkgs/pkgs/tools/package-management/poetry/default.nix
Default email 83405b6dd2 Project import generated by Copybara.
GitOrigin-RevId: ac718d02867a84b42522a0ece52d841188208f2c
2023-03-15 17:39:30 +01:00

50 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: [ ])