blob: 5035677beb000d7e122ad670b33aec133b0b7df8 (
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
|
{ lib, poetry2nix, python, fetchFromGitHub, runtimeShell }:
poetry2nix.mkPoetryApplication {
inherit python;
pyproject = ./pyproject.toml;
poetrylock = ./poetry.lock;
overrides = [ (poetry2nix.defaultPoetryOverrides.overrideOverlay (self: super: {
# Needed because poetry2nix currently doesn't handle pyproject.toml python bounds
# See https://github.com/nix-community/poetry2nix/issues/50
importlib-metadata = if python.pythonOlder "3.8" then super.importlib-metadata else null;
}))];
src = fetchFromGitHub (lib.importJSON ./src.json);
# "Vendor" dependencies (for build-system support)
postPatch = ''
for path in ''${PYTHONPATH//:/ }; do
echo "sys.path.insert(0, \"$path\")" >> poetry/__init__.py
done
'';
# Poetry is a bit special in that it can't use itself as the `build-system` property in pyproject.toml.
# That's why we need to hackily install outputs completely manually.
#
# For projects using poetry normally overriding the installPhase is not required.
installPhase = ''
runHook preInstall
mkdir -p $out/lib/${python.libPrefix}/site-packages
cp -r poetry $out/lib/${python.libPrefix}/site-packages
mkdir -p $out/bin
cat > $out/bin/poetry <<EOF
#!${python.interpreter}
import sys
if __name__ == '__main__':
sys.path.append("$out/lib/${python.libPrefix}/site-packages")
from poetry.console import main
main()
EOF
chmod +x $out/bin/poetry
mkdir -p "$out/share/bash-completion/completions"
"$out/bin/poetry" completions bash > "$out/share/bash-completion/completions/poetry"
mkdir -p "$out/share/zsh/vendor-completions"
"$out/bin/poetry" completions zsh > "$out/share/zsh/vendor-completions/_poetry"
mkdir -p "$out/share/fish/vendor_completions.d"
"$out/bin/poetry" completions fish > "$out/share/fish/vendor_completions.d/poetry.fish"
runHook postInstall
'';
# Propagating dependencies leads to issues downstream
# We've already patched poetry to prefer "vendored" dependencies
postFixup = ''
rm $out/nix-support/propagated-build-inputs
'';
# Fails because of impurities (network, git etc etc)
doCheck = false;
meta = with lib; {
platforms = platforms.all;
maintainers = with maintainers; [ adisbladis jakewaksbaum ];
};
}
|