Skip to content

Commit

Permalink
First, change the way in which our checkDerivation functions are call…
Browse files Browse the repository at this point in the history
…ed so that they get access to either stdenv (for mkDerivation checks) or python (for buildPythonPackage checks), so that they know which interpreter/compiler they're using. Next, using this feature, implement a check for inconsistent versions of python in the same package, as suggested by @SuperSandro2000
  • Loading branch information
rmcgibbo committed Jan 24, 2021
1 parent c64f442 commit aa085cb
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 20 deletions.
19 changes: 12 additions & 7 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ rec {
if builtins.elem namePosition namePositions
then
lib.recursiveUpdate originalDrv {
__nixpkgs-hammering-state = {
reports = originalDrv.__nixpkgs-hammering-state.reports or [] ++ lib.filter ({ cond, ... }: cond) (check drv);
__nixpkgs-hammering-state =
let checkResult = check prev.stdenv drv;
in
{
reports = originalDrv.__nixpkgs-hammering-state.reports or [] ++ lib.filter ({ cond, ... }: cond) checkResult;
};
}
else
Expand All @@ -62,9 +65,9 @@ rec {
final:
prev:

let pythonPackageOverrides = buildPythonPackage: self: super: {
let pythonPackageOverrides = python: self: super: {
buildPythonPackage = drv:
let originalDrv = buildPythonPackage drv;
let originalDrv = python.pkgs.buildPythonPackage drv;
namePosition =
let
pnamePosition = builtins.unsafeGetAttrPos "pname" drv;
Expand All @@ -74,8 +77,10 @@ rec {
if builtins.elem namePosition namePositions
then
lib.recursiveUpdate originalDrv {
__nixpkgs-hammering-state = {
reports = originalDrv.__nixpkgs-hammering-state.reports or [] ++ lib.filter ({ cond, ... }: cond) (check drv);
__nixpkgs-hammering-state =
let checkResult = check python drv;
in {
reports = originalDrv.__nixpkgs-hammering-state.reports or [] ++ lib.filter ({ cond, ... }: cond) checkResult;
};
}
else
Expand All @@ -100,7 +105,7 @@ rec {
];
in
lib.genAttrs pythonPackageSetNames (name: (builtins.getAttr name prev).override {
packageOverrides = pythonPackageOverrides (lib.getAttr name prev).pkgs.buildPythonPackage;
packageOverrides = pythonPackageOverrides (lib.getAttr name prev);
});

checkFor = check: let
Expand Down
2 changes: 1 addition & 1 deletion overlays/attribute-ordering.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let
builtins.listToAttrs
];

checkDerivation = drv:
checkDerivation = stdenv: drv:
let
getAttrLine = attr: (builtins.unsafeGetAttrPos attr drv).line;

Expand Down
2 changes: 1 addition & 1 deletion overlays/build-tools-in-build-inputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let
"pkg-config"
];

checkDerivation = drv:
checkDerivation = stdenv: drv:
(map
(tool: {
name = "build-tools-in-build-inputs";
Expand Down
2 changes: 1 addition & 1 deletion overlays/duplicate-check-inputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let
inherit (import ../lib { inherit lib; }) checkFor;
regex = "[[:space:]]*pytest[[:space:]]*";

checkDerivation = drv:
checkDerivation = stdenv: drv:
lib.singleton {
name = "duplicate-check-inputs";

Expand Down
2 changes: 1 addition & 1 deletion overlays/explicit-phases.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let
"install"
];

checkDerivation = drv:
checkDerivation = stdenv: drv:
(map
(phase: {
name = "explicit-phases";
Expand Down
2 changes: 1 addition & 1 deletion overlays/fixup-phase.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let
inherit (prev) lib;
inherit (import ../lib { inherit lib; }) checkMkDerivationFor;

checkDerivation = drv:
checkDerivation = stdenv: drv:
lib.singleton {
name = "fixup-phase";
cond = drv ? fixupPhase;
Expand Down
2 changes: 1 addition & 1 deletion overlays/meson-cmake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let
inherit (prev) lib;
inherit (import ../lib { inherit lib; }) checkMkDerivationFor;

checkDerivation = drv:
checkDerivation = stdenv: drv:
lib.singleton {
name = "meson-cmake";
cond = lib.elem prev.meson (drv.nativeBuildInputs or [ ]) && lib.elem prev.cmake (drv.nativeBuildInputs or [ ]);
Expand Down
2 changes: 1 addition & 1 deletion overlays/missing-phase-hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let
"install"
];

checkDerivation = drv:
checkDerivation = stdenv: drv:
(map
(phase:
let
Expand Down
2 changes: 1 addition & 1 deletion overlays/patch-phase.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let
inherit (prev) lib;
inherit (import ../lib { inherit lib; }) checkMkDerivationFor;

checkDerivation = drv:
checkDerivation = stdenv: drv:
lib.singleton {
name = "patch-phase";
cond = drv ? patchPhase;
Expand Down
2 changes: 1 addition & 1 deletion overlays/python-explicit-check-phase.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let
inherit (import ../lib { inherit lib; }) checkBuildPytonPackageFor;
regex = "[[:space:]]*pytest[[:space:]]*";

checkDerivation = drv:
checkDerivation = python: drv:
lib.singleton {
name = "python-explicit-check-phase";
cond = (drv ? checkPhase) && (builtins.match regex drv.checkPhase) != null;
Expand Down
2 changes: 1 addition & 1 deletion overlays/python-imports-check-typo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let
"pythonCheckImports"
];

checkDerivation = drv:
checkDerivation = python: drv:
(map
(incorrectSpelling: {
name = "python-imports-check-typo";
Expand Down
2 changes: 1 addition & 1 deletion overlays/python-include-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let
inherit (prev) lib;
inherit (import ../lib { inherit lib; }) checkBuildPytonPackageFor;

checkDerivation = drv:
checkDerivation = python: drv:
lib.singleton {
name = "python-include-tests";
cond = let
Expand Down
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; }) checkBuildPytonPackageFor;

checkDerivation = python: drv:
let
propagatedBuildInputs = lib.attrByPath ["propagatedBuildInputs"] [] drv;
checkInputs = lib.attrByPath ["checkInputs"] [] drv;
runtimeInputs = checkInputs ++ propagatedBuildInputs;
inputPythonInterpreters = map (p: p.pythonModule) (builtins.filter (p: p ? pythonModule) runtimeInputs);
allPythonInterpreters = lib.unique (inputPythonInterpreters ++ [python]);
in
lib.singleton {
name = "python-inconsistent-interpreters";
cond = lib.length allPythonInterpreters > 1;
msg = let
allPythonNames = map (p: p.name) allPythonInterpreters;
sources = ["buildPythonPackage"] ++
(if (lib.length propagatedBuildInputs) > 0 then ["propagatedBuildInputs"] else []) ++
(if (lib.length checkInputs) > 0 then ["checkInputs"] else []);
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
checkBuildPytonPackageFor checkDerivation attrs final prev
2 changes: 1 addition & 1 deletion overlays/unclear-gpl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let
"lgpl3"
];

checkDerivation = drv:
checkDerivation = python: drv:
(map
(license: {
name = "unclear-gpl";
Expand Down
2 changes: 1 addition & 1 deletion overlays/unnecessary-parallel-building.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let
inherit (prev) lib;
inherit (import ../lib { inherit lib; }) checkMkDerivationFor;

checkDerivation = drv:
checkDerivation = stdenv: drv:
lib.singleton {
name = "unnecessary-parallel-building";
cond =
Expand Down

0 comments on commit aa085cb

Please sign in to comment.