Skip to content

Commit 1c35e4c

Browse files
authored
feat: implement less/greater operators for string for env marker evaluation (#2827)
Right now, if two strings are compared, it results in an error. Per spec, strings are suppose to "use the python behavior". Starlark is going to use Java semantics underneath, but it should behave close enough for the (almost exclusively) ASCII input that will be used. Work towards #2826
1 parent 5b9d545 commit 1c35e4c

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

python/private/pypi/pep508_evaluate.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,14 @@ def _env_expr(left, op, right):
344344
return left in right
345345
elif op == "not in":
346346
return left not in right
347+
elif op == "<":
348+
return left < right
349+
elif op == "<=":
350+
return left <= right
351+
elif op == ">":
352+
return left > right
353+
elif op == ">=":
354+
return left >= right
347355
else:
348356
return fail("TODO: op unsupported: '{}'".format(op))
349357

tests/pypi/pep508/evaluate_tests.bzl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,28 @@ def _evaluate_non_version_env_tests(env):
6868

6969
# When
7070
for input, want in {
71-
"{} == 'osx'".format(var_name): True,
72-
"{} != 'osx'".format(var_name): False,
73-
"'osx' == {}".format(var_name): True,
7471
"'osx' != {}".format(var_name): False,
75-
"'x' in {}".format(var_name): True,
72+
"'osx' < {}".format(var_name): False,
73+
"'osx' <= {}".format(var_name): True,
74+
"'osx' == {}".format(var_name): True,
75+
"'osx' >= {}".format(var_name): True,
7676
"'w' not in {}".format(var_name): True,
77-
}.items(): # buildifier: @unsorted-dict-items
77+
"'x' in {}".format(var_name): True,
78+
"{} != 'osx'".format(var_name): False,
79+
"{} < 'osx'".format(var_name): False,
80+
"{} <= 'osx'".format(var_name): True,
81+
"{} == 'osx'".format(var_name): True,
82+
"{} > 'osx'".format(var_name): False,
83+
"{} >= 'osx'".format(var_name): True,
84+
}.items():
7885
got = evaluate(
7986
input,
8087
env = marker_env,
8188
)
82-
env.expect.that_bool(got).equals(want)
89+
env.expect.where(
90+
expr = input,
91+
env = marker_env,
92+
).that_bool(got).equals(want)
8393

8494
# Check that the non-strict eval gives us back the input when no
8595
# env is supplied.

0 commit comments

Comments
 (0)