Skip to content

Commit

Permalink
Factor out loop body in py_wd_test to a separate function (#3414)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoodmane authored Jan 28, 2025
1 parent 8790957 commit c96bcc9
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions src/workerd/server/tests/python/py_wd_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,32 @@ FEATURE_FLAGS = {
"development": ["python_workers_development", "python_external_packages"],
}

def _py_wd_test_helper(
name,
src,
python_flag,
**kwargs):
name_flag = name + "_" + python_flag
templated_src = name_flag.replace("/", "-") + "@template"
templated_src = "/".join(src.split("/")[:-1] + [templated_src])
flags = FEATURE_FLAGS[python_flag] + ["python_workers"]
feature_flags_txt = ",".join(['"{}"'.format(flag) for flag in flags])
expand_template(
name = name_flag + "@rule",
out = templated_src,
template = src,
substitutions = {"%PYTHON_FEATURE_FLAGS": feature_flags_txt},
)

wd_test(
src = templated_src,
name = name_flag + "@",
**kwargs
)

def py_wd_test(
directory = None,
*,
src = None,
data = None,
name = None,
Expand Down Expand Up @@ -36,25 +60,14 @@ def py_wd_test(
name = src.removesuffix(".wd-test")
data += ["//src/workerd/server/tests/python:pyodide_dev.capnp.bin@rule"]
args = args + ["--pyodide-bundle-disk-cache-dir", "$(location //src/workerd/server/tests/python:pyodide_dev.capnp.bin@rule)/..", "--experimental"]
tags = tags + ["py_wd_test"]
for python_flag in python_flags:
name_flag = name + "_" + python_flag
templated_src = name_flag.replace("/", "-") + "@template"
templated_src = "/".join(src.split("/")[:-1] + [templated_src])
flags = FEATURE_FLAGS[python_flag] + ["python_workers"]
feature_flags_txt = ",".join(['"{}"'.format(flag) for flag in flags])
expand_template(
name = name_flag + "@rule",
out = templated_src,
template = src,
substitutions = {"%PYTHON_FEATURE_FLAGS": feature_flags_txt},
)

wd_test(
src = templated_src,
_py_wd_test_helper(
name,
src,
python_flag,
data = data,
name = name_flag + "@",
args = args,
size = size,
tags = tags + ["py_wd_test"],
**kwargs
tags = tags,
)

0 comments on commit c96bcc9

Please sign in to comment.