Skip to content
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

tests: make multi_python_verions example bzlmod compatible #1523

Merged
merged 1 commit into from
Oct 31, 2023
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
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)