Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: implement less/greater operators for string for env marker evaluation #2827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions python/private/pypi/pep508_evaluate.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ def _env_expr(left, op, right):
return left in right
elif op == "not in":
return left not in right
elif op == "<":
return left < right
elif op == "<=":
return left <= right
elif op == ">":
return left > right
elif op == ">=":
return left >= right
else:
return fail("TODO: op unsupported: '{}'".format(op))

Expand Down
22 changes: 16 additions & 6 deletions tests/pypi/pep508/evaluate_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,28 @@ def _evaluate_non_version_env_tests(env):

# When
for input, want in {
"{} == 'osx'".format(var_name): True,
"{} != 'osx'".format(var_name): False,
"'osx' == {}".format(var_name): True,
"'osx' != {}".format(var_name): False,
"'x' in {}".format(var_name): True,
"'osx' < {}".format(var_name): False,
"'osx' <= {}".format(var_name): True,
"'osx' == {}".format(var_name): True,
"'osx' >= {}".format(var_name): True,
"'w' not in {}".format(var_name): True,
}.items(): # buildifier: @unsorted-dict-items
"'x' in {}".format(var_name): True,
"{} != 'osx'".format(var_name): False,
"{} < 'osx'".format(var_name): False,
"{} <= 'osx'".format(var_name): True,
"{} == 'osx'".format(var_name): True,
"{} > 'osx'".format(var_name): False,
"{} >= 'osx'".format(var_name): True,
}.items():
got = evaluate(
input,
env = marker_env,
)
env.expect.that_bool(got).equals(want)
env.expect.where(
expr = input,
env = marker_env,
).that_bool(got).equals(want)

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