Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement more operators
  • Loading branch information
adisbladis committed Jan 9, 2020
1 parent 70c6964 commit c1ce616
Show file tree
Hide file tree
Showing 7 changed files with 378 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pep508.nix
Expand Up @@ -151,7 +151,7 @@ let
">=" = x: y: (unmarshal x) >= (unmarshal y);
">" = x: y: (unmarshal x) > (unmarshal y);
"~=" = null;
"===" = null;
"===" = x: y: x == y;
"in" = x: y: let
values = builtins.filter (x: builtins.typeOf x == "string") (builtins.split " " (unmarshal y));
in
Expand Down
15 changes: 14 additions & 1 deletion semver.nix
Expand Up @@ -37,10 +37,23 @@ let
">=" = v: c: operators."==" v c || operators.">" v c;
"<=" = v: c: operators."==" v c || operators."<" v c;
# Semver specific operators
"~" = mkIdxComparison 1; #
"~" = mkIdxComparison 1;
"^" = mkIdxComparison 0;
"~=" = v: c: let
# Prune constraint
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
operators.">=" v c && operators."<" v upperConstraint;
# Infix operators
"-" = version: v: operators.">=" version v.vl && operators."<=" version v.vu;
# Arbitrary equality clause, just run simple comparison
"===" = v: c: v == c;
#
};

re = {
Expand Down
1 change: 1 addition & 0 deletions tests/default.nix
Expand Up @@ -20,6 +20,7 @@ in
git-deps-pinned = pkgs.callPackage ./git-deps-pinned { inherit poetry2nix; };
cli = poetry2nix;
path-deps = pkgs.callPackage ./path-deps { inherit poetry2nix; };
operators = pkgs.callPackage ./operators { inherit poetry2nix; };

# Egg support not yet in channel, uncomment when channel progressed
# eggs = pkgs.callPackage ./eggs { inherit poetry2nix; };
Expand Down
8 changes: 8 additions & 0 deletions tests/operators/default.nix
@@ -0,0 +1,8 @@
{ lib, poetry2nix, python3 }:

poetry2nix.mkPoetryApplication {
python = python3;
pyproject = ./pyproject.toml;
poetrylock = ./poetry.lock;
src = lib.cleanSource ./.;
}
Empty file.
339 changes: 339 additions & 0 deletions tests/operators/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c1ce616

Please sign in to comment.