Skip to content

Commit 843084d

Browse files
authored
tests: make multi_python_verions example bzlmod compatible (#1523)
Bazel is enabling bzlmod by default, which means the examples need to be updated to be bzlmod compatible. Work towards #1520
1 parent a326b68 commit 843084d

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module(
2+
name = "multi_python_versions",
3+
)
4+
5+
bazel_dep(name = "bazel_skylib", version = "1.4.0")
6+
bazel_dep(name = "rules_python", version = "0.0.0")
7+
local_path_override(
8+
module_name = "rules_python",
9+
path = "../..",
10+
)
11+
12+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
13+
python.toolchain(
14+
configure_coverage_tool = True,
15+
python_version = "3.8",
16+
)
17+
python.toolchain(
18+
configure_coverage_tool = True,
19+
# Only set when you have mulitple toolchain versions.
20+
is_default = True,
21+
python_version = "3.9",
22+
)
23+
python.toolchain(
24+
configure_coverage_tool = True,
25+
python_version = "3.10",
26+
)
27+
python.toolchain(
28+
configure_coverage_tool = True,
29+
python_version = "3.11",
30+
)
31+
use_repo(
32+
python,
33+
python = "python_versions",
34+
)
35+
36+
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
37+
use_repo(pip, "pypi")
38+
pip.parse(
39+
hub_name = "pypi",
40+
python_version = "3.8",
41+
requirements_lock = "//requirements:requirements_lock_3_8.txt",
42+
)
43+
pip.parse(
44+
hub_name = "pypi",
45+
python_version = "3.9",
46+
requirements_lock = "//requirements:requirements_lock_3_9.txt",
47+
)
48+
pip.parse(
49+
hub_name = "pypi",
50+
python_version = "3.10",
51+
requirements_lock = "//requirements:requirements_lock_3_10.txt",
52+
)
53+
pip.parse(
54+
hub_name = "pypi",
55+
python_version = "3.11",
56+
requirements_lock = "//requirements:requirements_lock_3_11.txt",
57+
)

examples/multi_python_versions/WORKSPACE.bzlmod

Whitespace-only changes.

examples/multi_python_versions/tests/my_lib_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717

1818
import libs.my_lib as my_lib
1919

20-
sanitized_version_check = f"{sys.version_info.major}_{sys.version_info.minor}"
20+
workspace_version = f"{sys.version_info.major}_{sys.version_info.minor}"
21+
bzlmod_version = f"{sys.version_info.major}{sys.version_info.minor}"
2122

22-
if not my_lib.websockets_is_for_python_version(sanitized_version_check):
23+
if not my_lib.websockets_is_for_python_version(
24+
workspace_version
25+
) and not my_lib.websockets_is_for_python_version(bzlmod_version):
2326
print("expected package for Python version is different than returned")
2427
sys.exit(1)

0 commit comments

Comments
 (0)