blob: bb4183bde2e5aaf11302453ca058730c0110d5b8 [file]
module(
name = "example_bzlmod",
version = "0.0.0",
compatibility_level = 1,
)
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "rules_python", version = "0.0.0")
local_path_override(
module_name = "rules_python",
path = "../..",
)
# This name is passed into python.toolchain and it's use_repo statement.
# We also use the same value in the python.host_python_interpreter call.
PYTHON_NAME_39 = "python_39"
PYTHON_39_TOOLCHAINS = PYTHON_NAME_39 + "_toolchains"
INTERPRETER_NAME_39 = "interpreter_39"
PYTHON_NAME_310 = "python_310"
PYTHON_310_TOOLCHAINS = PYTHON_NAME_310 + "_toolchains"
INTERPRETER_NAME_310 = "interpreter_310"
# We next initialize the python toolchain using the extension.
# You can set different Python versions in this block.
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
# This name is used in the various use_repo statements
# below, and in the local extension that is in this
# example.
name = PYTHON_NAME_39,
configure_coverage_tool = True,
# Only set when you have mulitple toolchain versions.
is_default = True,
python_version = "3.9",
)
# We are also using a second version of Python in this project.
# Typically you will only need a single version of Python, but
# If you need a different vesion we support more than one.
# Note: we do not supporting using multiple pip extensions, this is
# work in progress.
python.toolchain(
name = PYTHON_NAME_310,
configure_coverage_tool = True,
python_version = "3.10",
)
# use_repo imports one or more repos generated by the given module extension
# into the scope of the current module. We are importing the various repos
# created by the above python.toolchain calls.
use_repo(
python,
PYTHON_NAME_39,
PYTHON_39_TOOLCHAINS,
PYTHON_NAME_310,
PYTHON_310_TOOLCHAINS,
)
# This call registers the Python toolchains.
# Note: there is work under way to move this code to within
# rules_python, and the user won't have to make this call,
# unless they are registering custom toolchains.
register_toolchains(
"@{}//:all".format(PYTHON_39_TOOLCHAINS),
"@{}//:all".format(PYTHON_310_TOOLCHAINS),
)
# The interpreter extension discovers the platform specific Python binary.
# It creates a symlink to the binary, and we pass the label to the following
# pip.parse call.
interpreter = use_extension("@rules_python//python/extensions:interpreter.bzl", "interpreter")
interpreter.install(
name = INTERPRETER_NAME_39,
python_name = PYTHON_NAME_39,
)
# This second call is only needed if you are using mulitple different
# Python versions/interpreters.
interpreter.install(
name = INTERPRETER_NAME_310,
python_name = PYTHON_NAME_310,
)
use_repo(interpreter, INTERPRETER_NAME_39, INTERPRETER_NAME_310)
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
name = "pip",
# Intentionally set it false because the "true" case is already
# covered by examples/bzlmod_build_file_generation
incompatible_generate_aliases = False,
python_interpreter_target = "@{}//:python".format(INTERPRETER_NAME_39),
requirements_lock = "//:requirements_lock.txt",
requirements_windows = "//:requirements_windows.txt",
)
use_repo(pip, "pip")
bazel_dep(name = "other_module", version = "", repo_name = "our_other_module")
local_path_override(
module_name = "other_module",
path = "other_module",
)