Skip to content

Commit

Permalink
pep440.parseVersionConds: Support expressions surrounded by parens
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Jan 9, 2025
1 parent e14a14d commit c7fd60f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/pep440.nix
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,13 @@ fix (self: {
}
]
*/
parseVersionConds = conds: map self.parseVersionCond (splitComma conds);
parseVersionConds =
conds:
let
# If the conditions are surrounded by parens strip them away
parenM = match "\\((.+)\\)" conds;
in
map self.parseVersionCond (splitComma (if parenM != null then head parenM else conds));

/*
Compare two versions as parsed by `parseVersion` according to PEP-440.
Expand Down
7 changes: 6 additions & 1 deletion lib/test_pep440.nix
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ in
};
};

parseVersionConds = {
parseVersionConds = rec {
testSimple = {
expr = parseVersionConds ">=3.0.0rc1,<=4.0";
expected = [
Expand Down Expand Up @@ -393,6 +393,11 @@ in
}
];
};

testParen = {
expr = parseVersionConds "(>=3.0.0rc1,<=4.0)";
inherit (testSimple) expected;
};
};

comparators = {
Expand Down

0 comments on commit c7fd60f

Please sign in to comment.