mirror of
https://github.com/vale981/poetry2nix
synced 2025-03-04 08:41:42 -05:00
PEP 425: match versions more loosely
Version specifiers are for lower bounds for required interpreter version
This commit is contained in:
parent
2de794a0df
commit
d8a6e25608
1 changed files with 21 additions and 14 deletions
35
pep425.nix
35
pep425.nix
|
@ -3,18 +3,15 @@ let
|
||||||
inherit (lib.strings) escapeRegex hasPrefix hasSuffix hasInfix splitString removePrefix removeSuffix;
|
inherit (lib.strings) escapeRegex hasPrefix hasSuffix hasInfix splitString removePrefix removeSuffix;
|
||||||
targetMachine = poetryLib.getTargetMachine stdenv;
|
targetMachine = poetryLib.getTargetMachine stdenv;
|
||||||
|
|
||||||
# The 'cpxy" as determined by `python.version`
|
pythonVer =
|
||||||
#
|
|
||||||
# e.g "2.7.17" -> "cp27"
|
|
||||||
# "3.5.9" -> "cp35"
|
|
||||||
pythonTag =
|
|
||||||
let
|
let
|
||||||
ver = builtins.splitVersion python.version;
|
ver = builtins.splitVersion python.version;
|
||||||
major = builtins.elemAt ver 0;
|
major = builtins.elemAt ver 0;
|
||||||
minor = builtins.elemAt ver 1;
|
minor = builtins.elemAt ver 1;
|
||||||
|
tags = [ "cp" "py" ];
|
||||||
in
|
in
|
||||||
"cp${major}${minor}";
|
{ inherit major minor tags; };
|
||||||
abiTag = "${pythonTag}m";
|
abiTag = "cp${pythonVer.major}${pythonVer.minor}m";
|
||||||
|
|
||||||
#
|
#
|
||||||
# Parses wheel file returning an attribute set
|
# Parses wheel file returning an attribute set
|
||||||
|
@ -50,14 +47,24 @@ let
|
||||||
then [ ]
|
then [ ]
|
||||||
else (builtins.filter (x: hasInfix v x.file) candidates) ++ (findBestMatches vs candidates);
|
else (builtins.filter (x: hasInfix v x.file) candidates) ++ (findBestMatches vs candidates);
|
||||||
|
|
||||||
# pyver = "cpXX"
|
# x = "cpXX" | "py2" | "py3" | "py2.py3"
|
||||||
# x = "cpXX" | "py2" | "py3" | "py2.py3"
|
isPyVersionCompatible = pyver@{ major, minor, tags }: x:
|
||||||
isPyVersionCompatible = pyver: x:
|
|
||||||
let
|
let
|
||||||
normalize = y: ''cp${removePrefix "cp" (removePrefix "py" y)}'';
|
isCompat = m:
|
||||||
isCompat = p: x: hasPrefix (normalize x) p;
|
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;
|
||||||
in
|
in
|
||||||
lib.lists.any (isCompat pyver) (splitString "." x);
|
lib.lists.any isCompat (map parseMarker markers);
|
||||||
|
|
||||||
#
|
#
|
||||||
# Selects the best matching wheel file from a list of files
|
# Selects the best matching wheel file from a list of files
|
||||||
|
@ -95,7 +102,7 @@ let
|
||||||
let
|
let
|
||||||
f = toWheelAttrs x.file;
|
f = toWheelAttrs x.file;
|
||||||
in
|
in
|
||||||
(withPython pythonTag abiTag f) && (withPlatforms f);
|
(withPython pythonVer abiTag f) && (withPlatforms f);
|
||||||
filtered = builtins.filter filterWheel filesWithoutSources;
|
filtered = builtins.filter filterWheel filesWithoutSources;
|
||||||
choose = files:
|
choose = files:
|
||||||
let
|
let
|
||||||
|
|
Loading…
Add table
Reference in a new issue