2021-01-26 14:29:24 +03:00
|
|
|
{ lib, stdenv, poetryLib, python, isLinux ? stdenv.isLinux }:
|
2019-12-10 10:21:22 +01:00
|
|
|
let
|
2022-03-28 19:40:46 +02:00
|
|
|
inherit (lib.strings) escapeRegex hasPrefix hasSuffix hasInfix splitString removePrefix removeSuffix;
|
2022-01-19 03:56:47 +12:00
|
|
|
targetMachine = poetryLib.getTargetMachine stdenv;
|
2019-12-10 10:21:22 +01:00
|
|
|
|
2022-09-08 20:22:15 +02:00
|
|
|
pythonVer =
|
2019-12-10 10:21:22 +01:00
|
|
|
let
|
|
|
|
ver = builtins.splitVersion python.version;
|
|
|
|
major = builtins.elemAt ver 0;
|
|
|
|
minor = builtins.elemAt ver 1;
|
2022-09-08 20:22:15 +02:00
|
|
|
tags = [ "cp" "py" ];
|
2019-12-10 10:21:22 +01:00
|
|
|
in
|
2022-09-08 20:22:15 +02:00
|
|
|
{ inherit major minor tags; };
|
|
|
|
abiTag = "cp${pythonVer.major}${pythonVer.minor}m";
|
2019-12-10 10:21:22 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# Parses wheel file returning an attribute set
|
|
|
|
#
|
|
|
|
toWheelAttrs = str:
|
|
|
|
let
|
2020-06-08 15:00:44 +02:00
|
|
|
entries' = splitString "-" str;
|
|
|
|
# Hack: Remove version "suffixes" like 2.11.4-1
|
2022-05-04 23:51:24 -03:00
|
|
|
# Some wheels have build tag with more than one digit
|
|
|
|
# like openvino-2022.1.0-7019-cp36-cp36m-manylinux_2_27_x86_64.whl
|
|
|
|
entries = builtins.filter (x: builtins.match "[0-9]*" x == null) entries';
|
2019-12-10 10:21:22 +01:00
|
|
|
p = removeSuffix ".whl" (builtins.elemAt entries 4);
|
|
|
|
in
|
2020-04-29 14:12:59 +01:00
|
|
|
{
|
|
|
|
pkgName = builtins.elemAt entries 0;
|
|
|
|
pkgVer = builtins.elemAt entries 1;
|
|
|
|
pyVer = builtins.elemAt entries 2;
|
|
|
|
abi = builtins.elemAt entries 3;
|
|
|
|
platform = p;
|
|
|
|
};
|
2019-12-10 10:21:22 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# Builds list of acceptable osx wheel files
|
|
|
|
#
|
|
|
|
# <versions> accepted versions in descending order of preference
|
|
|
|
# <candidates> list of wheel files to select from
|
|
|
|
findBestMatches = versions: candidates:
|
|
|
|
let
|
|
|
|
v = lib.lists.head versions;
|
|
|
|
vs = lib.lists.tail versions;
|
|
|
|
in
|
2020-04-29 14:12:59 +01:00
|
|
|
if (builtins.length versions == 0)
|
|
|
|
then [ ]
|
|
|
|
else (builtins.filter (x: hasInfix v x.file) candidates) ++ (findBestMatches vs candidates);
|
2019-12-10 10:21:22 +01:00
|
|
|
|
2022-09-08 20:22:15 +02:00
|
|
|
# x = "cpXX" | "py2" | "py3" | "py2.py3"
|
|
|
|
isPyVersionCompatible = pyver@{ major, minor, tags }: x:
|
2019-12-17 18:13:11 +01:00
|
|
|
let
|
2022-09-08 20:22:15 +02:00
|
|
|
isCompat = m:
|
|
|
|
builtins.elem m.tag tags
|
|
|
|
&& m.major == major
|
|
|
|
&& builtins.compareVersions minor m.minor >= 0;
|
|
|
|
parseMarker = v:
|
|
|
|
let
|
|
|
|
tag = builtins.substring 0 2 v;
|
|
|
|
major = builtins.substring 2 1 v;
|
|
|
|
end = builtins.substring 3 3 v;
|
|
|
|
minor = if builtins.stringLength end > 0 then end else "0";
|
|
|
|
in
|
|
|
|
{ inherit major minor tag; };
|
|
|
|
markers = splitString "." x;
|
2019-12-17 18:13:11 +01:00
|
|
|
in
|
2022-09-08 20:22:15 +02:00
|
|
|
lib.lists.any isCompat (map parseMarker markers);
|
2019-12-10 10:21:22 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# Selects the best matching wheel file from a list of files
|
|
|
|
#
|
2019-12-13 16:56:51 +01:00
|
|
|
selectWheel = files:
|
2019-12-10 10:21:22 +01:00
|
|
|
let
|
|
|
|
filesWithoutSources = (builtins.filter (x: hasSuffix ".whl" x.file) files);
|
2022-03-28 19:33:30 +02:00
|
|
|
isPyAbiCompatible = pyabi: x: x == "none" || hasPrefix pyabi x || hasPrefix x pyabi || (
|
2020-06-08 15:00:44 +02:00
|
|
|
# The CPython stable ABI is abi3 as in the shared library suffix.
|
|
|
|
python.passthru.implementation == "cpython" &&
|
|
|
|
builtins.elemAt (lib.splitString "." python.version) 0 == "3" &&
|
|
|
|
x == "abi3"
|
|
|
|
);
|
2019-12-17 18:13:11 +01:00
|
|
|
withPython = ver: abi: x: (isPyVersionCompatible ver x.pyVer) && (isPyAbiCompatible abi x.abi);
|
2020-04-29 14:12:59 +01:00
|
|
|
withPlatform =
|
|
|
|
if isLinux
|
2020-10-01 19:08:57 +02:00
|
|
|
then
|
2021-01-26 14:29:24 +03:00
|
|
|
if targetMachine != null
|
|
|
|
then
|
2022-03-28 19:40:46 +02:00
|
|
|
# See PEP 600 for details.
|
|
|
|
(p:
|
|
|
|
builtins.match "any|manylinux(1|2010|2014)_${escapeRegex targetMachine}|manylinux_[0-9]+_[0-9]+_${escapeRegex targetMachine}" p != null
|
2021-01-26 14:29:24 +03:00
|
|
|
)
|
|
|
|
else
|
2022-03-28 19:39:51 +02:00
|
|
|
(p: p == "any")
|
2022-01-06 23:19:14 +00:00
|
|
|
else
|
|
|
|
if stdenv.isDarwin
|
|
|
|
then
|
|
|
|
if stdenv.targetPlatform.isAarch64
|
2022-03-28 19:39:51 +02:00
|
|
|
then (p: p == "any" || (hasInfix "macosx" p && lib.lists.any (e: hasSuffix e p) [ "arm64" "aarch64" ]))
|
|
|
|
else (p: p == "any" || (hasInfix "macosx" p && hasSuffix "x86_64" p))
|
|
|
|
else (p: p == "any");
|
|
|
|
withPlatforms = x: lib.lists.any withPlatform (splitString "." x.platform);
|
2019-12-10 10:21:22 +01:00
|
|
|
filterWheel = x:
|
|
|
|
let
|
|
|
|
f = toWheelAttrs x.file;
|
|
|
|
in
|
2022-09-08 20:22:15 +02:00
|
|
|
(withPython pythonVer abiTag f) && (withPlatforms f);
|
2019-12-10 10:21:22 +01:00
|
|
|
filtered = builtins.filter filterWheel filesWithoutSources;
|
|
|
|
choose = files:
|
|
|
|
let
|
2022-07-11 15:31:46 -04:00
|
|
|
osxMatches = [ "12_0" "11_0" "10_15" "10_12" "10_11" "10_10" "10_9" "10_8" "10_7" "any" ];
|
2022-03-28 19:40:46 +02:00
|
|
|
linuxMatches = [ "manylinux1_" "manylinux2010_" "manylinux2014_" "manylinux_" "any" ];
|
2020-04-08 16:24:35 +12:00
|
|
|
chooseLinux = x: lib.take 1 (findBestMatches linuxMatches x);
|
|
|
|
chooseOSX = x: lib.take 1 (findBestMatches osxMatches x);
|
2019-12-10 10:21:22 +01:00
|
|
|
in
|
2020-04-29 14:12:59 +01:00
|
|
|
if isLinux
|
|
|
|
then chooseLinux files
|
|
|
|
else chooseOSX files;
|
2019-12-10 10:21:22 +01:00
|
|
|
in
|
2020-04-29 14:12:59 +01:00
|
|
|
if (builtins.length filtered == 0)
|
|
|
|
then [ ]
|
|
|
|
else choose (filtered);
|
2019-12-10 10:21:22 +01:00
|
|
|
in
|
|
|
|
{
|
2019-12-17 18:13:11 +01:00
|
|
|
inherit selectWheel toWheelAttrs isPyVersionCompatible;
|
2019-12-10 10:21:22 +01:00
|
|
|
}
|