Add full operator support

This commit is contained in:
adisbladis 2020-01-09 12:42:56 +00:00
parent c1ce6163be
commit f394798d72
No known key found for this signature in database
GPG key ID: 110BFAD44C6249B7
4 changed files with 20 additions and 12 deletions

View file

@ -14,7 +14,7 @@ let
defaultPoetryOverrides = (import ./overrides.nix { inherit pkgs lib; });
mkEvalPep508 = import ./pep508.nix {
inherit lib;
inherit lib poetryLib;
stdenv = pkgs.stdenv;
};

View file

@ -1,6 +1,12 @@
{ lib, pkgs }:
let
inherit (import ./semver.nix { inherit lib; }) satisfiesSemver;
inherit (import ./semver.nix { inherit lib ireplace; }) satisfiesSemver;
inherit (builtins) genList length;
# Replace a list entry at defined index with set value
ireplace = idx: value: list: (
genList (i: if i == idx then value else (builtins.elemAt list i)) (length list)
);
# Returns true if pythonVersion matches with the expression in pythonVersions
isCompatible = pythonVersion: pythonVersions:

View file

@ -1,6 +1,7 @@
{ lib, stdenv }: python:
{ lib, stdenv, poetryLib }: python:
let
inherit (poetryLib) ireplace;
# Like builtins.substring but with stop being offset instead of length
substr = start: stop: s: builtins.substring start (stop - start) s;
@ -142,7 +143,6 @@ let
else builtins.fromJSON v
);
hasElem = needle: haystack: builtins.elem needle (builtins.filter (x: builtins.typeOf x == "string") (builtins.split " " haystack));
# TODO: Implement all operators
op = {
"<=" = x: y: (unmarshal x) <= (unmarshal y);
"<" = x: y: (unmarshal x) < (unmarshal y);
@ -150,7 +150,15 @@ let
"==" = x: y: x == y;
">=" = x: y: (unmarshal x) >= (unmarshal y);
">" = x: y: (unmarshal x) > (unmarshal y);
"~=" = null;
"~=" = v: c: let
parts = builtins.splitVersion c;
pruned = lib.take ((builtins.length parts) - 1) parts;
upper = builtins.toString (
(lib.toInt (builtins.elemAt pruned (builtins.length pruned - 1))) + 1
);
upperConstraint = builtins.concatStringsSep "." (ireplace (builtins.length pruned - 1) upper pruned);
in
op.">=" v c && op."<" v upperConstraint;
"===" = x: y: x == y;
"in" = x: y: let
values = builtins.filter (x: builtins.typeOf x == "string") (builtins.split " " (unmarshal y));

View file

@ -1,14 +1,8 @@
{ lib }:
{ lib, ireplace }:
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 "([^\*])(\.[\*])" s;
mkComparison = ret: version: v: builtins.compareVersions version v == ret;