Skip to content
Closed
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
2 changes: 1 addition & 1 deletion examples/bzlmod/.python_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9
3.11
12 changes: 6 additions & 6 deletions examples/bzlmod/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
# names. Those names are defined in the MODULES.bazel file.
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@pip//:requirements.bzl", "all_data_requirements", "all_requirements", "all_whl_requirements", "requirement")
load("@python_3_9//:defs.bzl", py_test_with_transition = "py_test")
load("@python_versions//3.10:defs.bzl", compile_pip_requirements_3_10 = "compile_pip_requirements")
load("@python_3_11//:defs.bzl", py_test_with_transition = "py_test")
load("@python_versions//3.12:defs.bzl", compile_pip_requirements_3_12 = "compile_pip_requirements")
load("@rules_python//python:py_binary.bzl", "py_binary")
load("@rules_python//python:py_library.bzl", "py_library")
load("@rules_python//python:py_test.bzl", "py_test")

# This stanza calls a rule that generates targets for managing pip dependencies
# with pip-compile for a particular python version.
compile_pip_requirements_3_10(
name = "requirements_3_10",
compile_pip_requirements_3_12(
name = "requirements_3_12",
timeout = "moderate",
src = "requirements.in",
requirements_txt = "requirements_lock_3_10.txt",
requirements_windows = "requirements_windows_3_10.txt",
requirements_txt = "requirements_lock_3_12.txt",
requirements_windows = "requirements_windows_3_12.txt",
)

# The rules below are language specific rules defined in
Expand Down
59 changes: 38 additions & 21 deletions examples/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ bazel_dep(name = "rules_rust", version = "0.67.0")
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.defaults(
# Use python.defaults if you have defined multiple toolchain versions.
python_version = "3.9",
python_version = "3.11",
python_version_env = "BAZEL_PYTHON_VERSION",
)
python.toolchain(
configure_coverage_tool = True,
python_version = "3.9",
python_version = "3.11",
)

# We are also using a second version of Python in this project.
Expand All @@ -42,27 +42,22 @@ python.toolchain(
# work in progress.
python.toolchain(
configure_coverage_tool = True,
python_version = "3.10",
python_version = "3.12",
)

# One can override the actual toolchain versions that are available, which can be useful
# when optimizing what gets downloaded and when.
# Adding the latest Python 3.13 version for testing
python.toolchain(
configure_coverage_tool = True,
python_version = "3.13",
)

# One can override the actual toolchain versions that are available
python.override(
# NOTE: These are disabled in the example because transitive dependencies
# require versions not listed here.
# available_python_versions = [
# "3.10.9",
# "3.9.19",
# # The following is used by the `other_module` and we need to include it here
# # as well.
# "3.11.8",
# "3.12.9",
# "3.11.19",
# "3.13.4",
# ],
# Also override the `minor_mapping` so that the root module,
# instead of rules_python's defaulting to the latest available version,
# controls what full version is used when `3.x` is requested.
minor_mapping = {
"3.9": "3.9.25",
},
)

# Or the sources that the toolchains come from for all platforms
Expand Down Expand Up @@ -98,7 +93,7 @@ python.single_version_platform_override(
# See the tests folder for various examples on using multiple Python versions.
# The names "python_3_9" and "python_3_10" are autmatically created by the repo
# rules based on the `python_version` arg values.
use_repo(python, "python_3_10", "python_3_9", "python_versions", "pythons_hub")
use_repo(python, "python_3_11", "python_3_12", "python_3_13", "python_versions", "pythons_hub")

# EXPERIMENTAL: This is experimental and may be changed or removed without notice
uv = use_extension(
Expand Down Expand Up @@ -207,7 +202,7 @@ pip.parse(
"--index-url=${PIP_INDEX_URL:-https://pypi.org/simple}",
],
hub_name = "pip",
python_version = "3.9",
python_version = "3.11",
requirements_lock = "requirements_lock_3_9.txt",
# These modifications were created above and we
# are providing pip.parse with the label of the mod
Expand All @@ -229,7 +224,7 @@ pip.parse(
],
},
hub_name = "pip",
python_version = "3.10",
python_version = "3.12",
# The requirements files for each platform that we want to support.
requirements_by_platform = {
# Default requirements file for needs to explicitly provide the platforms
Expand Down Expand Up @@ -265,6 +260,28 @@ pip.parse(
"@whl_mods_hub//:wheel.json": "wheel",
},
)
pip.parse(
hub_name = "pip",
python_version = "3.12",
requirements_by_platform = {
"//:requirements_lock_3_12.txt": "linux_*,osx_*",
},
whl_modifications = {
"@whl_mods_hub//:requests.json": "requests",
"@whl_mods_hub//:wheel.json": "wheel",
},
)
pip.parse(
hub_name = "pip",
python_version = "3.13",
requirements_by_platform = {
"//:requirements_lock_3_13.txt": "linux_*,osx_*",
},
whl_modifications = {
"@whl_mods_hub//:requests.json": "requests",
"@whl_mods_hub//:wheel.json": "wheel",
},
)

# You can add patches that will be applied on the whl contents.
#
Expand Down
4 changes: 2 additions & 2 deletions examples/bzlmod/entry_points/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ py_console_script_binary(
)

# A specific Python version can be forced by passing `python_version`
# attribute, e.g. to force Python 3.9:
# attribute, e.g. to force Python 3.11:
py_console_script_binary(
name = "yamllint",
pkg = "@pip//yamllint:pkg",
python_version = "3.9",
python_version = "3.11",
visibility = ["//entry_points:__subpackages__"],
)
Loading