@@ -25,19 +25,21 @@ let
2525 # Get license by id falling back to input string
2626 getLicenseBySpdxId = spdxId: spdxLicenses.${spdxId} or spdxId;
2727
28− #
29− # Returns an attrset { python, poetryPackages } for the given lockfile
30− #
31− mkPoetryPython =
32− { poetrylock
28+ /*
29+ Returns an attrset { python, poetryPackages, pyProject, poetryLock } for the given pyproject/lockfile.
30+ */
31+ mkPoetryPackages =
32+ { pyproject
33+ , poetrylock
3334 , poetryPkg
3435 , overrides ? [ defaultPoetryOverrides ]
3536 , meta ? {}
3637 , python ? pkgs.python3
3738 , pwd ? null
3839 }@attrs: let
39− lockData = readTOML poetrylock;
40− lockFiles = lib.getAttrFromPath [ "metadata" "files" ] lockData;
40+ pyProject = readTOML pyproject;
41+ poetryLock = readTOML poetrylock;
42+ lockFiles = lib.getAttrFromPath [ "metadata" "files" ] poetryLock;
4143
4244 specialAttrs = [
4345 "overrides"
@@ -48,11 +50,18 @@ let
4850
4951 evalPep508 = mkEvalPep508 python;
5052
51− # Filter packages by their PEP508 markers
53+ # Filter packages by their PEP508 markers & pyproject interpreter version
5254 partitions = let
53− supportsPythonVersion = pkgMeta: if pkgMeta ? marker then (evalPep508 pkgMeta.marker) else true;
55+ supportsPythonVersion = pkgMeta: let
56+ pep508Result = if pkgMeta ? marker then (evalPep508 pkgMeta.marker) else true;
57+
58+ flatDeps = (pyProject.tool.poetry.dependencies or {}) // (pyProject.tool.poetry.dev-dependencies or {});
59+ constraints = flatDeps.${pkgMeta.name}.python or "";
60+ pyprojectResult = isCompatible python.pythonVersion constraints;
61+ in
62+ pyprojectResult && pep508Result;
5463 in
55− lib.partition supportsPythonVersion lockData.package;
64+ lib.partition supportsPythonVersion poetryLock.package;
5665
5766 compatible = partitions.right;
5867 incompatible = partitions.wrong;
@@ -82,18 +91,22 @@ let
8291 );
8392 in
8493 lockPkgs;
85−
8694 overlays = builtins.map getFunctorFn (
8795 [
8896 (
89− self: super: {
90− mkPoetryDep = self.callPackage ./mk-poetry-dep.nix {
91− inherit pkgs lib python poetryLib;
92− };
93− poetry = poetryPkg;
94− # The canonical name is setuptools-scm
95− setuptools-scm = super.setuptools_scm;
96− }
97+ self: super: let
98+ hooks = self.callPackage ./hooks {};
99+ in
100+ {
101+ mkPoetryDep = self.callPackage ./mk-poetry-dep.nix {
102+ inherit pkgs lib python poetryLib;
103+ };
104+ poetry = poetryPkg;
105+ # The canonical name is setuptools-scm
106+ setuptools-scm = super.setuptools_scm;
107+
108+ inherit (hooks) removePathDependenciesHook;
109+ }
97110 )
98111 # Null out any filtered packages, we don't want python.pkgs from nixpkgs
99112 (self: super: builtins.listToAttrs (builtins.map (x: { name = x.name; value = null; }) incompatible))
@@ -110,6 +123,8 @@ let
110123 {
111124 python = py;
112125 poetryPackages = map (pkg: py.pkgs.${pkg.name}) compatible;
126+ poetryLock = poetryLock;
127+ inherit pyProject;
113128 };
114129
115130 /* Returns a package with a python interpreter and all packages specified in the poetry.lock lock file.
@@ -118,7 +133,8 @@ let
118133 poetry2nix.mkPoetryEnv { poetrylock = ./poetry.lock; python = python3; }
119134 */
120135 mkPoetryEnv =
121− { poetrylock
136+ { pyproject
137+ , poetrylock
122138 , overrides ? [ defaultPoetryOverrides ]
123139 , meta ? {}
124140 , pwd ? null
@@ -126,9 +142,9 @@ let
126142 }:
127143 let
128144 poetryPkg = poetry.override { inherit python; };
129− py = mkPoetryPython (
145+ py = mkPoetryPackages (
130146 {
131− inherit poetryPkg poetrylock overrides meta python pwd;
147+ inherit poetryPkg pyproject poetrylock overrides meta python pwd;
132148 }
133149 );
134150 in
@@ -147,13 +163,12 @@ let
147163 }@attrs: let
148164 poetryPkg = poetry.override { inherit python; };
149165
150− py = (
151− mkPoetryPython {
152− inherit poetryPkg poetrylock overrides meta python pwd;
153− }
154− ).python;
166+ poetryPython = mkPoetryPackages {
167+ inherit poetryPkg pyproject poetrylock overrides meta python pwd;
168+ };
169+ py = poetryPython.python;
155170
156− pyProject = readTOML pyproject;
171+ inherit (poetryPython) pyProject;
157172
158173 specialAttrs = [
159174 "overrides"
@@ -187,21 +202,13 @@ let
187202
188203 buildInputs = mkInput "buildInputs" buildSystemPkgs;
189204 propagatedBuildInputs = mkInput "propagatedBuildInputs" (getDeps "dependencies") ++ ([ py.pkgs.setuptools ]);
190− nativeBuildInputs = mkInput "nativeBuildInputs" [ pkgs.yj ];
205+ nativeBuildInputs = mkInput "nativeBuildInputs" [ pkgs.yj py.pkgs.removePathDependenciesHook ];
191206 checkInputs = mkInput "checkInputs" (getDeps "dev-dependencies");
192207
193208 passthru = {
194209 python = py;
195210 };
196211
197− postPatch = (passedAttrs.postPatch or "") + ''
198− # Tell poetry not to resolve the path dependencies. Any version is
199− # fine !
200− yj -tj < pyproject.toml | ${python.interpreter} ${./pyproject-without-path.py} > pyproject.json
201− yj -jt < pyproject.json > pyproject.toml
202− rm pyproject.json
203− '';
204−
205212 meta = meta // {
206213 inherit (pyProject.tool.poetry) description homepage;
207214 license = getLicenseBySpdxId (pyProject.tool.poetry.license or "unknown");
@@ -240,7 +247,7 @@ let
240247
241248in
242249{
243− inherit mkPoetryEnv mkPoetryApplication cli doc;
250+ inherit mkPoetryEnv mkPoetryApplication mkPoetryPackages cli doc;
244251
245252 /*
246253 The default list of poetry2nix override overlays