| # This file replaces the WORKSPACE file when using bzlmod. |
| |
| # module declares certain properties of the Bazel module represented by the current Bazel repo. |
| # These properties are either essential metadata of the module (such as the name and version), |
| # or affect behavior of the current module and its dependents. |
| module( |
| name = "example_bzlmod_build_file_generation", |
| version = "0.0.0", |
| compatibility_level = 1, |
| ) |
| |
| # The following stanza defines the dependency rules_python. |
| # For typical setups you set the version. |
| # See the releases page for available versions. |
| # https://github.com/bazelbuild/rules_python/releases |
| bazel_dep(name = "rules_python", version = "0.0.0") |
| |
| # The following loads rules_python from the file system. |
| # For usual setups you should remove this local_path_override block. |
| local_path_override( |
| module_name = "rules_python", |
| path = "../..", |
| ) |
| |
| # The following stanza defines the dependency rules_python_gazelle_plugin. |
| # For typical setups you set the version. |
| # See the releases page for available versions. |
| # https://github.com/bazelbuild/rules_python/releases |
| bazel_dep(name = "rules_python_gazelle_plugin", version = "0.0.0") |
| |
| # The following starlark loads the gazelle plugin from the file system. |
| # For usual setups you should remove this local_path_override block. |
| local_path_override( |
| module_name = "rules_python_gazelle_plugin", |
| path = "../../gazelle", |
| ) |
| |
| # The following stanza defines the dependency for gazelle |
| # See here https://github.com/bazelbuild/bazel-gazelle/releases/ for the |
| # latest version. |
| bazel_dep(name = "gazelle", version = "0.30.0", repo_name = "bazel_gazelle") |
| |
| # The following stanze returns a proxy object representing a module extension; |
| # its methods can be invoked to create module extension tags. |
| python = use_extension("@rules_python//python:extensions.bzl", "python") |
| |
| # This name is passed into python.toolchain and it's use_repo statement. |
| # We also use the same name for python.host_python_interpreter. |
| PYTHON_NAME = "python3" |
| |
| # This is the name that is used for the host interpreter |
| PYTHON_INTERPRETER = PYTHON_NAME + "_host_interpreter" |
| |
| # We next initialize the python toolchain using the extension. |
| # You can set different Python versions in this block. |
| 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, |
| configure_coverage_tool = True, |
| python_version = "3.9", |
| ) |
| |
| # Import the python repositories generated by the given module extension |
| # into the scope of the current module. |
| # All of the python3 repositories use the PYTHON_NAME as there prefix. They |
| # are not catenated for ease of reading. |
| use_repo(python, PYTHON_NAME) |
| use_repo(python, "python3_toolchains") |
| use_repo(python, PYTHON_INTERPRETER) |
| |
| # Register an already-defined toolchain so that Bazel can use it during toolchain resolution. |
| register_toolchains( |
| "@python3_toolchains//:all", |
| ) |
| |
| # Use the pip extension |
| pip = use_extension("@rules_python//python:extensions.bzl", "pip") |
| |
| # Use the extension to call the `pip_repository` rule that invokes `pip`, with `incremental` set. |
| # Accepts a locked/compiled requirements file and installs the dependencies listed within. |
| # Those dependencies become available in a generated `requirements.bzl` file. |
| # You can instead check this `requirements.bzl` file into your repo. |
| # Because this project has different requirements for windows vs other |
| # operating systems, we have requirements for each. |
| pip.parse( |
| name = "pip", |
| # When using gazelle you must use set the following flag |
| # in order for the generation of gazelle dependency resolution. |
| incompatible_generate_aliases = True, |
| # The interpreter attribute points to the interpreter to use for running |
| # pip commands to download the packages in the requirements file. |
| # As a best practice, we use the same interpreter as the toolchain |
| # that was configured above; this ensures the same Python version |
| # is used for both resolving dependencies and running tests/binaries. |
| # If this isn't specified, then you'll get whatever is locally installed |
| # on your system. |
| python_interpreter_target = "@" + PYTHON_INTERPRETER + "//:python", |
| requirements_lock = "//:requirements_lock.txt", |
| requirements_windows = "//:requirements_windows.txt", |
| ) |
| |
| # Imports the pip toolchain generated by the given module extension into the scope of the current module. |
| use_repo(pip, "pip") |
| |
| # This project includes a different module that is on the local file system. |
| # Add the module to this parent project. |
| bazel_dep(name = "other_module", version = "", repo_name = "our_other_module") |
| local_path_override( |
| module_name = "other_module", |
| path = "other_module", |
| ) |