Skip to content

Commit

Permalink
Add check 'python-inconsistent-interpreters'
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcgibbo committed Jan 26, 2021
1 parent 101e4b0 commit d0aa5aa
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 0 deletions.
39 changes: 39 additions & 0 deletions overlays/python-inconsistent-interpreters.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{ builtAttrs
, packageSet
, namePositions
}@attrs:

final: prev:
let
inherit (prev) lib;
inherit (import ../lib { inherit lib; }) checkBuildPythonPackageFor;

checkDerivation = drvArgs: drv:
let
propagatedBuildInputs = drvArgs.propagatedBuildInputs or [];
checkInputs = drvArgs.checkInputs or [];
runtimeInputs = checkInputs ++ propagatedBuildInputs;
inputPythonInterpreters = map (p: p.pythonModule) (builtins.filter (p: p ? pythonModule) runtimeInputs);
allPythonInterpreters = lib.unique (inputPythonInterpreters ++ [drv.pythonModule]);
in
lib.singleton {
name = "python-inconsistent-interpreters";
cond = lib.length allPythonInterpreters > 1;
msg = let
allPythonNames = map (p: p.name) allPythonInterpreters;
sources = ["buildPythonPackage"] ++
(lib.optionals ((lib.length propagatedBuildInputs) > 0) ["propagatedBuildInputs"]) ++
(lib.optionals ((lib.length checkInputs) > 0) ["checkInputs"]);
in
''
Between ${lib.concatStringsSep " and " sources}, this derivation seems
to be simultaneously trying to use packages from multiple different python package sets.
Mixing package sets like this is not supported.
Detected pythons:
${lib.concatStringsSep "\n " allPythonNames}
'';
};
in
checkBuildPythonPackageFor checkDerivation attrs final prev
11 changes: 11 additions & 0 deletions run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ def __iter__(self):
]
)

yield make_test_rule(
'python-inconsistent-interpreters',
[
'mixed-1',
'mixed-2',
],
[
'normal',
]
)

yield make_test_rule(
'unnecessary-parallel-building',
[
Expand Down
1 change: 1 addition & 0 deletions tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
python-explicit-check-phase = pkgs.python3.pkgs.callPackage ./python-explicit-check-phase { };
python-imports-check-typo = pkgs.python3.pkgs.callPackage ./python-imports-check-typo { };
python-include-tests = pkgs.python3.pkgs.callPackage ./python-include-tests { };
python-inconsistent-interpreters = pkgs.python3.pkgs.callPackage ./python-inconsistent-interpreters { };
unclear-gpl = pkgs.callPackage ./unclear-gpl { };
unnecessary-parallel-building = pkgs.callPackage ./unnecessary-parallel-building { };
}
11 changes: 11 additions & 0 deletions tests/python-inconsistent-interpreters/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ callPackage
}:

{
# positive cases
mixed-1 = callPackage ./mixed-1.nix { };
mixed-2 = callPackage ./mixed-2.nix { };

# negative cases
normal = callPackage ./normal.nix { };
}
11 changes: 11 additions & 0 deletions tests/python-inconsistent-interpreters/mixed-1.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ buildPythonPackage
, python37Packages
, python39Packages
}:

buildPythonPackage rec {
pname = "package";

propagatedBuildInputs = [ python37Packages.numpy python39Packages.scipy ];
}

10 changes: 10 additions & 0 deletions tests/python-inconsistent-interpreters/mixed-2.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ buildPythonPackage
, python27Packages
}:

buildPythonPackage rec {
pname = "package";

checkInputs = [ python27Packages.numpy ];
}

11 changes: 11 additions & 0 deletions tests/python-inconsistent-interpreters/normal.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ buildPythonPackage
, numpy
, scipy
}:

buildPythonPackage rec {
pname = "package";

propagatedBuildInputs = [ numpy scipy ];
}

0 comments on commit d0aa5aa

Please sign in to comment.