Skip to content

Commit 15abbd2

Browse files
committed
finish fixing the toolchain tests
1 parent 4613c66 commit 15abbd2

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

examples/bzlmod/libs/my_lib/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ def websockets_is_for_python_version(sanitized_version_check):
1919
# We are checking that the name of the repository folders
2020
# match the expected generated names. If we update the folder
2121
# structure or naming we will need to modify this test.
22-
return f"_{sanitized_version_check}__websockets" in websockets.__file__
22+
want = f"_{sanitized_version_check}_websockets"
23+
got_full = websockets.__file__
24+
if want not in got_full:
25+
print(f"Failed, expected '{want}' to be a substring of '{got_full}'.")
26+
return False
27+
28+
return True

python/private/pip_repo_name.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def pip_repo_name(prefix, filename, sha256):
2929
Returns:
3030
a string that can be used in `whl_library`.
3131
"""
32-
parts = [prefix, ""]
32+
parts = [prefix]
3333

3434
if not filename.endswith(".whl"):
3535
# Then the filename is basically foo-3.2.1.<ext>
@@ -47,6 +47,6 @@ def pip_repo_name(prefix, filename, sha256):
4747
parts.append(abi_tag)
4848
parts.append(platform_tag)
4949

50-
parts.append(sha256[:9])
50+
parts.append(sha256[:8])
5151

5252
return "_".join(parts)

python/private/py_toolchain_suite.bzl

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def py_toolchain_suite(*, prefix, user_repository_name, python_version, set_pyth
4040
# string as we cannot have list of bools in build rule attribues.
4141
# This if statement does not appear to work unless it is in the
4242
# toolchain file.
43-
if set_python_version_constraint == "True":
43+
if set_python_version_constraint in ["True", "False"]:
4444
major_minor, _, _ = python_version.rpartition(".")
4545

4646
match_any = []
@@ -65,6 +65,18 @@ def py_toolchain_suite(*, prefix, user_repository_name, python_version, set_pyth
6565
visibility = ["//visibility:private"],
6666
)
6767

68+
if set_python_version_constraint == "False":
69+
if flag_values:
70+
name = "{prefix}_version_setting_no_python_version".format(prefix = prefix)
71+
match_any.append(name)
72+
native.config_setting(
73+
name = name,
74+
flag_values = flag_values | {
75+
str(Label("//python/config_settings:python_version")): "",
76+
},
77+
visibility = ["//visibility:private"],
78+
)
79+
6880
name = "{prefix}_version_setting_{python_version}".format(
6981
prefix = prefix,
7082
python_version = python_version,
@@ -75,17 +87,14 @@ def py_toolchain_suite(*, prefix, user_repository_name, python_version, set_pyth
7587
match_any = match_any,
7688
visibility = ["//visibility:private"],
7789
)
78-
target_settings = [name]
79-
elif set_python_version_constraint == "False":
80-
name = "{prefix}_version_setting_default".format(prefix = prefix)
81-
native.config_setting(
82-
name = name,
83-
flag_values = flag_values | {
84-
Label("//python/config_settings:python_version"): "",
85-
},
86-
visibility = ["//visibility:private"],
87-
)
88-
target_settings = [name]
90+
91+
if set_python_version_constraint == "True":
92+
target_settings = [name]
93+
else:
94+
target_settings = select({
95+
name: [name],
96+
"//conditions:default": [],
97+
})
8998
else:
9099
fail(("Invalid set_python_version_constraint value: got {} {}, wanted " +
91100
"either the string 'True' or the string 'False'; " +

tests/private/pip_repo_name/pip_repo_name_tests.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ _tests = []
2121

2222
def _test_simple(env):
2323
got = pip_repo_name("prefix", "foo-1.2.3-py3-none-any.whl", "deadbeef")
24-
env.expect.that_str(got).equals("prefix__foo_py3_none_any_deadbeef")
24+
env.expect.that_str(got).equals("prefix_foo_py3_none_any_deadbeef")
2525

2626
_tests.append(_test_simple)
2727

2828
def _test_sdist(env):
2929
got = pip_repo_name("prefix", "foo-1.2.3.tar.gz", "deadbeef000deadbeef")
30-
env.expect.that_str(got).equals("prefix__foo_sdist_deadbeef")
30+
env.expect.that_str(got).equals("prefix_foo_sdist_deadbeef")
3131

3232
_tests.append(_test_sdist)
3333

@@ -39,7 +39,7 @@ def _test_platform_whl(env):
3939
)
4040

4141
# We only need the first segment of each
42-
env.expect.that_str(got).equals("prefix__foo_cp39_abi3_manylinux_2_5_x86_64_deadbeef")
42+
env.expect.that_str(got).equals("prefix_foo_cp39_abi3_manylinux_2_5_x86_64_deadbeef")
4343

4444
_tests.append(_test_platform_whl)
4545

0 commit comments

Comments
 (0)