mirror of
https://github.com/vale981/poetry2nix
synced 2025-03-04 16:51:40 -05:00
Add full operator support
This commit is contained in:
parent
c1ce6163be
commit
f394798d72
4 changed files with 20 additions and 12 deletions
|
@ -14,7 +14,7 @@ let
|
|||
defaultPoetryOverrides = (import ./overrides.nix { inherit pkgs lib; });
|
||||
|
||||
mkEvalPep508 = import ./pep508.nix {
|
||||
inherit lib;
|
||||
inherit lib poetryLib;
|
||||
stdenv = pkgs.stdenv;
|
||||
};
|
||||
|
||||
|
|
8
lib.nix
8
lib.nix
|
@ -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:
|
||||
|
|
14
pep508.nix
14
pep508.nix
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue