2023-10-25 20:07:52 +13:00
|
|
|
{ lib, pyproject-nix, pkgs, ... }:
|
2019-12-13 16:56:51 +01:00
|
|
|
let
|
2023-10-25 20:07:52 +13:00
|
|
|
inherit (import ./vendor/pyproject.nix/lib/util.nix { inherit lib; }) splitComma;
|
2020-01-09 12:42:56 +00:00
|
|
|
|
2020-01-12 22:18:49 +00:00
|
|
|
fromTOML = builtins.fromTOML or
|
2020-01-13 00:24:05 +00:00
|
|
|
(
|
2020-05-19 21:06:02 +01:00
|
|
|
toml: builtins.fromJSON (
|
|
|
|
builtins.readFile (
|
|
|
|
pkgs.runCommand "from-toml"
|
|
|
|
{
|
|
|
|
inherit toml;
|
|
|
|
allowSubstitutes = false;
|
|
|
|
preferLocalBuild = true;
|
|
|
|
}
|
|
|
|
''
|
|
|
|
${pkgs.remarshal}/bin/remarshal \
|
|
|
|
-if toml \
|
|
|
|
-i <(echo "$toml") \
|
|
|
|
-of json \
|
|
|
|
-o $out
|
|
|
|
''
|
2020-01-13 00:24:05 +00:00
|
|
|
)
|
2020-05-19 21:06:02 +01:00
|
|
|
)
|
2020-01-13 00:24:05 +00:00
|
|
|
);
|
2020-01-11 23:33:40 +00:00
|
|
|
readTOML = path: fromTOML (builtins.readFile path);
|
2019-12-13 16:56:51 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the appropriate manylinux dependencies and string representation for the file specified
|
|
|
|
#
|
|
|
|
getManyLinuxDeps = f:
|
|
|
|
let
|
|
|
|
ml = pkgs.pythonManylinuxPackages;
|
|
|
|
in
|
2020-04-29 14:12:59 +01:00
|
|
|
if lib.strings.hasInfix "manylinux1" f then { pkg = [ ml.manylinux1 ]; str = "1"; }
|
|
|
|
else if lib.strings.hasInfix "manylinux2010" f then { pkg = [ ml.manylinux2010 ]; str = "2010"; }
|
|
|
|
else if lib.strings.hasInfix "manylinux2014" f then { pkg = [ ml.manylinux2014 ]; str = "2014"; }
|
2022-03-28 19:40:46 +02:00
|
|
|
else if lib.strings.hasInfix "manylinux_" f then { pkg = [ ml.manylinux2014 ]; str = "pep600"; }
|
2020-04-29 14:12:59 +01:00
|
|
|
else { pkg = [ ]; str = null; };
|
2019-12-13 16:56:51 +01:00
|
|
|
|
2019-12-29 12:51:22 +00:00
|
|
|
getBuildSystemPkgs =
|
|
|
|
{ pythonPackages
|
|
|
|
, pyProject
|
2020-03-14 23:13:51 +00:00
|
|
|
}:
|
2020-04-29 14:12:59 +01:00
|
|
|
let
|
2020-07-14 23:09:10 +02:00
|
|
|
missingBuildBackendError = "No build-system.build-backend section in pyproject.toml. "
|
|
|
|
+ "Add such a section as described in https://python-poetry.org/docs/pyproject/#poetry-and-pep-517";
|
2020-10-01 17:17:06 +02:00
|
|
|
requires = lib.attrByPath [ "build-system" "requires" ] (throw missingBuildBackendError) pyProject;
|
2023-11-12 18:44:49 +01:00
|
|
|
requiredPkgs = builtins.map (n: (pyproject-nix.lib.pep508.parseString n).name) requires;
|
2020-10-01 19:08:57 +02:00
|
|
|
in
|
|
|
|
builtins.map (drvAttr: pythonPackages.${drvAttr} or (throw "unsupported build system requirement ${drvAttr}")) requiredPkgs;
|
2019-12-29 12:51:22 +00:00
|
|
|
|
2020-02-29 21:19:09 +00:00
|
|
|
# Find gitignore files recursively in parent directory stopping with .git
|
2020-03-14 23:13:51 +00:00
|
|
|
findGitIgnores = path:
|
|
|
|
let
|
2024-03-09 18:17:39 +01:00
|
|
|
parent = builtins.dirOf path;
|
2020-03-14 23:13:51 +00:00
|
|
|
gitIgnore = path + "/.gitignore";
|
|
|
|
isGitRoot = builtins.pathExists (path + "/.git");
|
|
|
|
hasGitIgnore = builtins.pathExists gitIgnore;
|
2020-04-29 14:12:59 +01:00
|
|
|
gitIgnores = if hasGitIgnore then [ gitIgnore ] else [ ];
|
2020-03-14 23:13:51 +00:00
|
|
|
in
|
2022-04-14 16:19:59 +12:00
|
|
|
lib.optionals (builtins.pathExists path && builtins.toString path != "/" && ! isGitRoot) (findGitIgnores parent) ++ gitIgnores;
|
2020-02-29 21:19:09 +00:00
|
|
|
|
2020-02-26 18:18:56 +00:00
|
|
|
/*
|
2021-12-25 16:00:20 -08:00
|
|
|
Provides a source filtering mechanism that:
|
2020-02-26 18:18:56 +00:00
|
|
|
|
2021-12-25 16:00:20 -08:00
|
|
|
- Filters gitignore's
|
|
|
|
- Filters pycache/pyc files
|
|
|
|
- Uses cleanSourceFilter to filter out .git/.hg, .o/.so, editor backup files & nix result symlinks
|
2020-02-26 18:18:56 +00:00
|
|
|
*/
|
2020-03-14 23:13:51 +00:00
|
|
|
cleanPythonSources = { src }:
|
|
|
|
let
|
|
|
|
gitIgnores = findGitIgnores src;
|
|
|
|
pycacheFilter = name: type:
|
|
|
|
(type == "directory" && ! lib.strings.hasInfix "__pycache__" name)
|
|
|
|
|| (type == "regular" && ! lib.strings.hasSuffix ".pyc" name)
|
|
|
|
;
|
|
|
|
in
|
2020-04-29 14:12:59 +01:00
|
|
|
lib.cleanSourceWith {
|
|
|
|
filter = lib.cleanSourceFilter;
|
|
|
|
src = lib.cleanSourceWith {
|
|
|
|
filter = pkgs.nix-gitignore.gitignoreFilterPure pycacheFilter gitIgnores src;
|
|
|
|
inherit src;
|
2020-02-26 18:18:56 +00:00
|
|
|
};
|
2020-04-29 14:12:59 +01:00
|
|
|
};
|
2021-01-26 14:29:24 +03:00
|
|
|
|
2023-10-25 20:07:52 +13:00
|
|
|
checkPythonVersions = pyVersion: python-versions: (
|
2023-11-05 16:16:04 -08:00
|
|
|
lib.any
|
|
|
|
(python-versions': lib.all
|
|
|
|
(cond:
|
|
|
|
let
|
|
|
|
conds = pyproject-nix.lib.poetry.parseVersionCond cond;
|
|
|
|
in
|
|
|
|
lib.all (cond': pyproject-nix.lib.pep440.comparators.${cond'.op} pyVersion cond'.version) conds)
|
|
|
|
(splitComma python-versions'))
|
|
|
|
(builtins.filter lib.isString (builtins.split " *\\|\\| *" python-versions)));
|
2023-10-25 20:07:52 +13:00
|
|
|
|
2019-12-13 16:56:51 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
inherit
|
|
|
|
getManyLinuxDeps
|
|
|
|
readTOML
|
2019-12-29 12:51:22 +00:00
|
|
|
getBuildSystemPkgs
|
2020-02-26 18:18:56 +00:00
|
|
|
cleanPythonSources
|
2023-10-25 20:07:52 +13:00
|
|
|
checkPythonVersions
|
2019-12-16 14:51:45 +01:00
|
|
|
;
|
2019-12-13 16:56:51 +01:00
|
|
|
}
|