-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
python: unsupported platforms check and buildPythonApplication support #128
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The python builder automatically sets `meta.platforms` to that of the interpreter, so the only reason to set it is to further limit the supported platforms to a subset of those supported by the python interpreter. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
final: prev: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the future, we will probably want the same rule for other languages like Go and Rust. I wonder if we should name this rule e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe but it seems like it could get messy trying to get the default platform of every builder in one overlay. Perhaps it would make more sense to abstract the shared logic into a |
||
let | ||
inherit (prev) lib; | ||
inherit (import ../lib { inherit lib; }) checkBuildPythonPackageFor; | ||
|
||
checkDerivation = drvArgs: drv: | ||
let | ||
# We can access python with the `pythonModule` attribute of `buildPythonPackage` | ||
# derivations, but it is not so simple with `buildPythonApplication`. Here we rely on the | ||
# performance hack in nixpkgs/pkgs/development/interpreters/python/mk-python-derivation.nix | ||
# which injects python into propagatedBuildInputs. | ||
python = lib.lists.last (builtins.filter (p: p ? pythonVersion) drv.propagatedBuildInputs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not very confident about this. Maybe add a comment pointing to the source code so that we can easily update this when it breaks: https://github.com/NixOS/nixpkgs/blob/dbe1337750f324137ca2ba78f20a3be00e16481a/pkgs/development/interpreters/python/mk-python-derivation.nix#L155 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I had not seen the comments added by NixOS/nixpkgs#179318 which does seem to draw into question the long-term inclusion of python as an input. |
||
drvPlatforms = drvArgs.meta.platforms or [ ]; | ||
unsupportedPlatforms = lib.lists.subtractLists python.meta.platforms drvPlatforms; | ||
in lib.singleton { | ||
name = "python-unsupported-platforms"; | ||
cond = (unsupportedPlatforms != [ ]) || (lib.lists.naturalSort drvPlatforms == lib.lists.naturalSort python.meta.platforms); | ||
msg = if unsupportedPlatforms != [ ] then '' | ||
The following meta.platforms are not supported by the ${python} interpreter: | ||
[ ${builtins.toString unsupportedPlatforms} ] | ||
'' else '' | ||
The meta.platforms attribute is set to the same value by default. | ||
''; | ||
locations = [ | ||
(builtins.unsafeGetAttrPos "platforms" python.meta) | ||
jtojnar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(builtins.unsafeGetAttrPos "platforms" drvArgs.meta) | ||
]; | ||
}; | ||
in | ||
checkBuildPythonPackageFor checkDerivation final prev |
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 | ||
]; | ||
} |
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; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ callPackage | ||
}: | ||
|
||
{ | ||
# 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 { }; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ lib | ||
, buildPythonPackage | ||
}: | ||
|
||
buildPythonPackage 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 | ||
, buildPythonPackage | ||
}: | ||
|
||
buildPythonPackage rec { | ||
pname = "package"; | ||
version = "0.1.0"; | ||
|
||
meta = with lib; { | ||
platforms = platforms.linux; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ buildPythonPackage | ||
}: | ||
|
||
buildPythonPackage rec { | ||
pname = "package"; | ||
version = "0.1.0"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the goal of including this in the error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced the inclusion provides any value but I followed the existing pattern. Here's an example error message as it currently stands:
Shall I remove "buildPythonPackage" and "buildPythonApplication" from these messages?