Skip to content

Commit

Permalink
tests: make multi_python_verions example bzlmod compatible
Browse files Browse the repository at this point in the history
Bazel is enabling bzlmod by default, which means the examples need to
be updated to be bzlmod compatible.

Fixes #1520
  • Loading branch information
rickeylev committed Oct 30, 2023
1 parent 5b082bb commit 103cbee
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
57 changes: 57 additions & 0 deletions examples/multi_python_versions/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module(
name = "multi_python_versions",
)

bazel_dep(name = "bazel_skylib", version = "1.4.0")
bazel_dep(name = "rules_python", version = "0.0.0")
local_path_override(
module_name = "rules_python",
path = "../..",
)

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
configure_coverage_tool = True,
python_version = "3.8",
)
python.toolchain(
configure_coverage_tool = True,
# Only set when you have mulitple toolchain versions.
is_default = True,
python_version = "3.9",
)
python.toolchain(
configure_coverage_tool = True,
python_version = "3.10",
)
python.toolchain(
configure_coverage_tool = True,
python_version = "3.11",
)
use_repo(
python,
python = "python_versions",
)

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
use_repo(pip, "pypi")
pip.parse(
hub_name = "pypi",
python_version = "3.8",
requirements_lock = "//requirements:requirements_lock_3_8.txt",
)
pip.parse(
hub_name = "pypi",
python_version = "3.9",
requirements_lock = "//requirements:requirements_lock_3_9.txt",
)
pip.parse(
hub_name = "pypi",
python_version = "3.10",
requirements_lock = "//requirements:requirements_lock_3_10.txt",
)
pip.parse(
hub_name = "pypi",
python_version = "3.11",
requirements_lock = "//requirements:requirements_lock_3_11.txt",
)
Empty file.
7 changes: 5 additions & 2 deletions examples/multi_python_versions/tests/my_lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@

import libs.my_lib as my_lib

sanitized_version_check = f"{sys.version_info.major}_{sys.version_info.minor}"
workspace_version = f"{sys.version_info.major}_{sys.version_info.minor}"
bzlmod_version = f"{sys.version_info.major}{sys.version_info.minor}"

if not my_lib.websockets_is_for_python_version(sanitized_version_check):
if not my_lib.websockets_is_for_python_version(
workspace_version
) and not my_lib.websockets_is_for_python_version(bzlmod_version):
print("expected package for Python version is different than returned")
sys.exit(1)

0 comments on commit 103cbee

Please sign in to comment.