| 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 = "../..", | |
| ) | |
| # (py_proto_library specific) We are using rules_proto to define rules_proto targets to be consumed by py_proto_library. | |
| bazel_dep(name = "rules_proto", version = "5.3.0-21.7") | |
| # (py_proto_library specific) Add the protobuf library for well-known types (e.g. `Any`, `Timestamp`, etc) | |
| bazel_dep(name = "protobuf", version = "24.4", repo_name = "com_google_protobuf") | |
| # 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( | |
| 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( | |
| configure_coverage_tool = True, | |
| python_version = "3.10", | |
| ) | |
| # You only need to load this repositories if you are using multiple Python versions. | |
| # 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") | |
| # EXPERIMENTAL: This is experimental and may be removed without notice | |
| uv = use_extension("@rules_python//python/uv:extensions.bzl", "uv") | |
| uv.toolchain(uv_version = "0.2.23") | |
| use_repo(uv, "uv_toolchains") | |
| register_toolchains("@uv_toolchains//:all") | |
| # This extension allows a user to create modifications to how rules_python | |
| # creates different wheel repositories. Different attributes allow the user | |
| # to modify the BUILD file, and copy files. | |
| # See @rules_python//python/extensions:whl_mods.bzl attributes for more information | |
| # on each of the attributes. | |
| # You are able to set a hub name, so that you can have different modifications of the same | |
| # wheel in different pip hubs. | |
| pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") | |
| # Call whl_mods.create for the requests package. | |
| pip.whl_mods( | |
| # we are using the appended_build_content.BUILD file | |
| # to add content to the request wheel BUILD file. | |
| additive_build_content_file = "//whl_mods:appended_build_content.BUILD", | |
| data = [":generated_file"], | |
| hub_name = "whl_mods_hub", | |
| whl_name = "requests", | |
| ) | |
| ADDITIVE_BUILD_CONTENT = """\ | |
| load("@bazel_skylib//rules:write_file.bzl", "write_file") | |
| write_file( | |
| name = "generated_file", | |
| out = "generated_file.txt", | |
| content = ["Hello world from build content file"], | |
| ) | |
| """ | |
| # Call whl_mods.create for the wheel package. | |
| pip.whl_mods( | |
| additive_build_content = ADDITIVE_BUILD_CONTENT, | |
| copy_executables = { | |
| "@@//whl_mods:data/copy_executable.py": "copied_content/executable.py", | |
| }, | |
| copy_files = { | |
| "@@//whl_mods:data/copy_file.txt": "copied_content/file.txt", | |
| }, | |
| data = [":generated_file"], | |
| data_exclude_glob = ["site-packages/*.dist-info/WHEEL"], | |
| hub_name = "whl_mods_hub", | |
| whl_name = "wheel", | |
| ) | |
| use_repo(pip, "whl_mods_hub") | |
| # To fetch pip dependencies, use pip.parse. We can pass in various options, | |
| # but typically we pass requirements and the Python version. The Python | |
| # version must have been configured by a corresponding `python.toolchain()` | |
| # call. | |
| # Alternatively, `python_interpreter_target` can be used to directly specify | |
| # the Python interpreter to run to resolve dependencies. | |
| pip.parse( | |
| # We can use `envsubst in the above | |
| envsubst = ["PIP_INDEX_URL"], | |
| # Use the bazel downloader to query the simple API for downloading the sources | |
| # Note, that we can use envsubst for this value. | |
| experimental_index_url = "${PIP_INDEX_URL:-https://pypi.org/simple}", | |
| # One can also select a particular index for a particular package. | |
| # This ensures that the setup is resistant against confusion attacks. | |
| # experimental_index_url_overrides = { | |
| # "my_package": "https://different-index-url.com", | |
| # }, | |
| # Or you can specify extra indexes like with `pip`: | |
| # experimental_extra_index_urls = [ | |
| # "https://different-index-url.com", | |
| # ], | |
| experimental_requirement_cycles = { | |
| "sphinx": [ | |
| "sphinx", | |
| "sphinxcontrib-qthelp", | |
| "sphinxcontrib-htmlhelp", | |
| "sphinxcontrib-devhelp", | |
| "sphinxcontrib-applehelp", | |
| "sphinxcontrib-serializinghtml", | |
| ], | |
| }, | |
| # You can use one of the values below to specify the target platform | |
| # to generate the dependency graph for. | |
| experimental_target_platforms = [ | |
| # Specifying the target platforms explicitly | |
| "cp39_linux_x86_64", | |
| "cp39_linux_*", | |
| "cp39_*", | |
| ], | |
| hub_name = "pip", | |
| python_version = "3.9", | |
| # The requirements files for each platform that we want to support. | |
| requirements_by_platform = { | |
| # Default requirements file for needs to explicitly provide the platforms | |
| "//:requirements_lock_3_9.txt": "linux_*,osx_*", | |
| # This API allows one to specify additional platforms that the users | |
| # configure the toolchains for themselves. In this example we add | |
| # `windows_aarch64` to illustrate that `rules_python` won't fail to | |
| # process the value, but it does not mean that this example will work | |
| # on Windows ARM. | |
| "//:requirements_windows_3_9.txt": "windows_x86_64,windows_aarch64", | |
| }, | |
| # These modifications were created above and we | |
| # are providing pip.parse with the label of the mod | |
| # and the name of the wheel. | |
| whl_modifications = { | |
| "@whl_mods_hub//:requests.json": "requests", | |
| "@whl_mods_hub//:wheel.json": "wheel", | |
| }, | |
| ) | |
| pip.parse( | |
| experimental_requirement_cycles = { | |
| "sphinx": [ | |
| "sphinx", | |
| "sphinxcontrib-qthelp", | |
| "sphinxcontrib-htmlhelp", | |
| "sphinxcontrib-devhelp", | |
| "sphinxcontrib-applehelp", | |
| "sphinxcontrib-serializinghtml", | |
| ], | |
| }, | |
| # You can use one of the values below to specify the target platform | |
| # to generate the dependency graph for. | |
| experimental_target_platforms = [ | |
| # Using host python version | |
| "linux_*", | |
| "osx_*", | |
| "windows_*", | |
| # Or specifying an exact platform | |
| "linux_x86_64", | |
| # Or the following to get the `host` platform only | |
| "host", | |
| ], | |
| hub_name = "pip", | |
| python_version = "3.10", | |
| requirements_lock = "//:requirements_lock_3_10.txt", | |
| requirements_windows = "//:requirements_windows_3_10.txt", | |
| # These modifications were created above and we | |
| # are providing pip.parse with the label of the mod | |
| # and the name of the wheel. | |
| 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. | |
| # | |
| # The patches have to be in the unified-diff format. | |
| pip.override( | |
| file = "requests-2.25.1-py2.py3-none-any.whl", | |
| patch_strip = 1, | |
| patches = [ | |
| "@//patches:empty.patch", | |
| "@//patches:requests_metadata.patch", | |
| "@//patches:requests_record.patch", | |
| ], | |
| ) | |
| 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", | |
| ) |