This repository contains bazel integrations for python quality tools.
Each offered tool has it own README document and can be independently activated and configured.
| Tool | Tool Type | Bazel Type | Supported Languages | Workspace | Bzlmod |
|---|---|---|---|---|---|
| pylint | Code linter | aspect | Python | yes | no |
| ruff-check | Code linter | aspect | Python | yes | yes |
| mypy | Code type linter | aspect | Python | yes | yes |
| black | Code formatter | aspect | Python | yes | yes |
| ruff-format | Code formatter | aspect | Python | yes | yes |
| isort | Import formatter | aspect | Python | yes | yes |
| pytest | Test Framework | aspect | Python | yes | yes |
| pycoverage | Code coverage tool | aspect | Python | yes | yes |
| pip_audit | Vulnerability checker | rule | Python | yes | yes |
The next sections explain the steps to achieve a proper config for each Bazel dependency manager. For a fully working setup, take a look at the test workspace as an example.
It's important to note that this repository does not supply python toolchains but only its pip dependencies. Therefore one must set up its own python toolchain. This repository support major python versions from 3.8 to 3.12.
Additionaly, one must have the following bazel repositories already in place:
- bazel_skylib >= 1.7.1
- rules_python >= 0.40.0
To select the correct python dependency version one only needs to set a string_flag under one's .bazelrc file.
For example if one is using python 3.10, one should select our python 3.10 dependencies by adding the following lines to the respective .bazelrc file.
# .bazelrc
common --flag_alias=python=@rules_python//python/config_settings:python_version
common --python=3.10Add this to your WORKSPACE file.
# WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "bazel_tools_python",
sha256 = "<omitted>",
urls = ["<domain>/bazel-tools-python/<version>/bazel-tools-python-<version>.tar.gz"],
)
load("@bazel_tools_python//third_party:python_toolchains.bzl", bazel_tools_python_python_toolchains = "python_toolchains")
bazel_tools_python_python_toolchains()
load("@bazel_tools_python//third_party:python_pip_parse.bzl", bazel_tools_python_python_pip_parse = "python_pip_parse")
bazel_tools_python_python_pip_parse()
load("@bazel_tools_python//third_party:python_pip_hub.bzl", bazel_tools_python_python_pip_hub = "python_pip_hub")
bazel_tools_python_python_pip_hub()Add this to your MODULE.bazel file.
# MODULE.bazel
bazel_dep(name = "score_bazel_tools_python", version = "<version>", repo_name = "bazel_tools_python")To generate Bazel integrity value, one can use the following command:
openssl dgst -sha256 -binary bazel-tools-python-<version>.tar.gz | openssl base64 -A | sed 's/^/sha256-/'Please check our contributing guide.