Skip to content

Commit

Permalink
buildPythonApplication support
Browse files Browse the repository at this point in the history
This effects python-inconsistent-interpreters because we can no longer
assume there to be a drv.pythonModule attribute.
  • Loading branch information
ryneeverett committed Jul 12, 2022
1 parent e2f5723 commit f26c376
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ rec {
lib.genAttrs pythonPackageSetNames (pythonName:
prev.${pythonName}.override (oldOverrides: {
packageOverrides = lib.composeExtensions (oldOverrides.packageOverrides or idOverlay) (final: prev: {
buildPythonApplication = wrapFunctionWithChecks prev.buildPythonApplication check;
buildPythonPackage = wrapFunctionWithChecks prev.buildPythonPackage check;
});
})
Expand Down
13 changes: 10 additions & 3 deletions overlays/python-inconsistent-interpreters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,28 @@ let
checkInputs = drvArgs.checkInputs or [];
runtimeInputs = checkInputs ++ propagatedBuildInputs;
inputPythonInterpreters = map (p: p.pythonModule) (builtins.filter (p: p ? pythonModule) runtimeInputs);
allPythonInterpreters = lib.unique (inputPythonInterpreters ++ [ drv.pythonModule ]);
allPythonInterpreters = lib.unique (inputPythonInterpreters ++ lib.optionals (drv ? pythonModule) [ drv.pythonModule ]);
in
lib.singleton {
name = "python-inconsistent-interpreters";
cond = builtins.length allPythonInterpreters > 1;
msg =
let
allPythonNames = map (p: p.name) allPythonInterpreters;
sources = [
"buildPythonPackage"
sources = if drv ? pythonModule
then [ "buildPythonPackage"
] ++ lib.optionals (builtins.any (p: p.pythonModule or drv.pythonModule != drv.pythonModule) propagatedBuildInputs) [
"propagatedBuildInputs"
] ++ lib.optionals (builtins.any (p: p.pythonModule or drv.pythonModule != drv.pythonModule) checkInputs) [
"checkInputs"
]
else [ "buildPythonApplication"
] ++ lib.optionals (builtins.length (lib.unique(map (p: p.pythonModule) propagatedBuildInputs)) > 1) [
"propagatedBuildInputs"
] ++ lib.optionals (builtins.length (lib.unique(map (p: p.pythonModule) checkInputs)) > 1) [
"checkInputs"
];

in ''
Between ${lib.concatStringsSep " and " sources}, this derivation seems
to be simultaneously trying to use packages from multiple different Python package sets.
Expand Down
6 changes: 5 additions & 1 deletion run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,13 @@ def __iter__(self):
yield make_test_rule(
'python-unsupported-platforms',
[
'platforms-all'
'platforms-all',
"build-python-application-platforms-all",
],
[
'platforms-linux',
'unspecified',
"build-python-application-platforms-linux",
]
)

Expand All @@ -302,9 +304,11 @@ def __iter__(self):
[
"mixed-1",
"mixed-2",
"build-python-application-mixed",
],
[
"normal",
"build-python-application-normal",
],
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ buildPythonApplication
, python37Packages
, python39Packages
}:

buildPythonApplication rec {
name = "package";

propagatedBuildInputs = [
python37Packages.numpy
python39Packages.scipy
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ buildPythonApplication
, numpy
, scipy
}:

buildPythonApplication rec {
name = "package";

propagatedBuildInputs = [
numpy
scipy
];
}
2 changes: 2 additions & 0 deletions tests/python-inconsistent-interpreters/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
# positive cases
mixed-1 = callPackage ./mixed-1.nix { };
mixed-2 = callPackage ./mixed-2.nix { };
build-python-application-mixed = callPackage ./build-python-application-mixed.nix { };

# negative cases
normal = callPackage ./normal.nix { };
build-python-application-normal = callPackage ./build-python-application-normal.nix { };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ lib
, buildPythonApplication
}:

buildPythonApplication rec {
pname = "package";
version = "0.1.0";

meta = with lib; {
platforms = platforms.all;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ lib
, buildPythonApplication
}:

buildPythonApplication rec {
pname = "package";
version = "0.1.0";

meta = with lib; {
platforms = platforms.linux;
};
}
2 changes: 2 additions & 0 deletions tests/python-unsupported-platforms/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
{
# positive cases
platforms-all = callPackage ./platforms-all.nix { };
build-python-application-platforms-all = callPackage ./build-python-application-platforms-all.nix { };

# negative cases
platforms-linux = callPackage ./platforms-linux.nix { };
unspecified = callPackage ./unspecified.nix { };
build-python-application-platforms-linux = callPackage ./build-python-application-platforms-linux.nix { };
}

0 comments on commit f26c376

Please sign in to comment.