mirror of
https://github.com/vale981/poetry2nix
synced 2025-03-05 09:11:39 -05:00
Add support for the python-versions field from poetry.lock
This commit is contained in:
parent
49055769cf
commit
4d56dcce71
2 changed files with 98 additions and 2 deletions
28
default.nix
28
default.nix
|
@ -13,6 +13,28 @@ let
|
||||||
then builtins.getAttr attribute set
|
then builtins.getAttr attribute set
|
||||||
else default;
|
else default;
|
||||||
|
|
||||||
|
satisfiesSemver = (import ./semver.nix {inherit lib;}).satisfies;
|
||||||
|
|
||||||
|
# Check Python version is compatible with package
|
||||||
|
isCompatible = pythonVersions: let
|
||||||
|
operators = {
|
||||||
|
"||" = cond1: cond2: cond1 || cond2;
|
||||||
|
"," = cond1: cond2: cond1 && cond2; # , means &&
|
||||||
|
};
|
||||||
|
tokens = builtins.split "(,|\\|\\|)" pythonVersions;
|
||||||
|
in (builtins.foldl' (acc: v: let
|
||||||
|
isOperator = builtins.typeOf v == "list";
|
||||||
|
operator = if isOperator then (builtins.elemAt v 0) else acc.operator;
|
||||||
|
in if isOperator then (acc // {inherit operator;}) else {
|
||||||
|
inherit operator;
|
||||||
|
state = operators."${operator}" acc.state (satisfiesSemver python.version v);
|
||||||
|
})
|
||||||
|
{
|
||||||
|
operator = ",";
|
||||||
|
state = true;
|
||||||
|
}
|
||||||
|
tokens).state;
|
||||||
|
|
||||||
extensions = pkgs.lib.importJSON ./extensions.json;
|
extensions = pkgs.lib.importJSON ./extensions.json;
|
||||||
getExtension = filename: builtins.elemAt
|
getExtension = filename: builtins.elemAt
|
||||||
(builtins.filter (ext: builtins.match "^.*\.${ext}" filename != null) extensions)
|
(builtins.filter (ext: builtins.match "^.*\.${ext}" filename != null) extensions)
|
||||||
|
@ -52,8 +74,6 @@ let
|
||||||
all = getAttrDefault pkgMeta.name files [];
|
all = getAttrDefault pkgMeta.name files [];
|
||||||
in builtins.filter (f: fileSupported f.file) all;
|
in builtins.filter (f: fileSupported f.file) all;
|
||||||
|
|
||||||
# files = poetryLock.metadata.files;
|
|
||||||
# files = getAttrDefault "files" pkgMeta [];
|
|
||||||
files_sdist = builtins.filter isSdist pkgFiles;
|
files_sdist = builtins.filter isSdist pkgFiles;
|
||||||
files_bdist = builtins.filter isBdist pkgFiles;
|
files_bdist = builtins.filter isBdist pkgFiles;
|
||||||
files_supported = files_sdist ++ files_bdist;
|
files_supported = files_sdist ++ files_bdist;
|
||||||
|
@ -80,6 +100,10 @@ let
|
||||||
dependencies = builtins.map (d: lib.toLower d) (builtins.attrNames depAttrs);
|
dependencies = builtins.map (d: lib.toLower d) (builtins.attrNames depAttrs);
|
||||||
in builtins.map (dep: self."${dep}") dependencies;
|
in builtins.map (dep: self."${dep}") dependencies;
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
broken = ! isCompatible pkgMeta.python-versions;
|
||||||
|
};
|
||||||
|
|
||||||
src =
|
src =
|
||||||
if format == "wheel"
|
if format == "wheel"
|
||||||
then self.fetchPypi {
|
then self.fetchPypi {
|
||||||
|
|
72
semver.nix
Normal file
72
semver.nix
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
{ lib }:
|
||||||
|
|
||||||
|
let
|
||||||
|
inherit (builtins) elemAt match;
|
||||||
|
|
||||||
|
# Replace a list entry at defined index with set value
|
||||||
|
ireplace = idx: value: list: let
|
||||||
|
inherit (builtins) genList length;
|
||||||
|
in genList (i: if i == idx then value else (elemAt list i)) (length list);
|
||||||
|
|
||||||
|
operators = let
|
||||||
|
matchWildCard = s: match "(.*)(\.[x\*])" s;
|
||||||
|
mkComparison = ret: version: v: builtins.compareVersions version v == ret;
|
||||||
|
mkIdxComparison = idx: version: v: let
|
||||||
|
ver = builtins.splitVersion v;
|
||||||
|
minor = builtins.toString (lib.toInt (elemAt ver idx) + 1);
|
||||||
|
upper = builtins.concatStringsSep "." (ireplace idx minor ver);
|
||||||
|
in operators.">=" version v && operators."<" version upper;
|
||||||
|
dropWildcardPrecision = f: version: constraint: let
|
||||||
|
m = matchWildCard constraint;
|
||||||
|
hasWildcard = m != null;
|
||||||
|
c = if hasWildcard then (elemAt m 0) else constraint;
|
||||||
|
v =
|
||||||
|
if hasWildcard then (builtins.substring 0 (builtins.stringLength c) version)
|
||||||
|
else version;
|
||||||
|
in f v c;
|
||||||
|
in {
|
||||||
|
# Prefix operators
|
||||||
|
"==" = dropWildcardPrecision (mkComparison 0);
|
||||||
|
">" = dropWildcardPrecision (mkComparison 1);
|
||||||
|
"<" = dropWildcardPrecision (mkComparison (-1));
|
||||||
|
"!=" = v: c: ! operators."==" v c;
|
||||||
|
">=" = v: c: operators."==" v c || operators.">" v c;
|
||||||
|
"<=" = v: c: operators."==" v c || operators."<" v c;
|
||||||
|
# Semver specific operators
|
||||||
|
"~" = mkIdxComparison 1; #
|
||||||
|
"^" = mkIdxComparison 0;
|
||||||
|
# Infix operators
|
||||||
|
"-" = version: v: operators.">=" version v.vl && operators."<=" version v.vu;
|
||||||
|
};
|
||||||
|
|
||||||
|
re = {
|
||||||
|
operators = "([=><!~\^]+)";
|
||||||
|
version = "([0-9\.\*x]+)";
|
||||||
|
};
|
||||||
|
|
||||||
|
parseConstraint = constraint: let
|
||||||
|
constraintStr = builtins.replaceStrings [ " " ] [ "" ] constraint;
|
||||||
|
# The common prefix operators
|
||||||
|
mPre = match "${re.operators} *${re.version}" constraintStr;
|
||||||
|
# There is also an infix operator to match ranges
|
||||||
|
mIn = match "${re.version} *(-) *${re.version}" constraintStr;
|
||||||
|
in (
|
||||||
|
if mPre != null then {
|
||||||
|
op = elemAt mPre 0;
|
||||||
|
v = elemAt mPre 1;
|
||||||
|
}
|
||||||
|
# Infix operators are range matches
|
||||||
|
else if mIn != null then {
|
||||||
|
op = elemAt mIn 1;
|
||||||
|
v = {
|
||||||
|
vl = (elemAt mIn 0);
|
||||||
|
vu = (elemAt mIn 2);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else throw "Constraint \"${constraintStr}\" could not be parsed");
|
||||||
|
|
||||||
|
satisfies = version: constraint: let
|
||||||
|
inherit (parseConstraint constraint) op v;
|
||||||
|
in if constraint == "*" then true else operators."${op}" version v;
|
||||||
|
|
||||||
|
in { inherit satisfies; }
|
Loading…
Add table
Reference in a new issue