Bazel rules for FawltyDeps to automatically check Python dependencies in your Bazel projects.
rules_fawltydeps provides Bazel rules and aspects to integrate FawltyDeps into your build process. FawltyDeps finds undeclared and unused dependencies in Python projects, helping you maintain clean and accurate dependency declarations in your BUILD files.
- Automatic dependency checking: Validate that your Python code only uses declared dependencies
- Aspect-based analysis: Non-invasive checks that work with existing
py_library,py_binary, andpy_testrules - Build integration: Runs as part of your normal Bazel build process
Add the following to your MODULE.bazel file:
bazel_dep(name = "rules_fawltydeps", version = "0.1.0")To check dependencies for a specific target:
bazel build //your/package:target --aspects=@rules_fawltydeps//fawltydeps:defs.bzl%fawltydeps_aspectYou can also create explicit check targets:
load("@rules_fawltydeps//fawltydeps:defs.bzl", "fawltydeps_check")
py_library(
name = "mylib",
srcs = ["mylib.py"],
deps = [
"@pypi//requests",
],
)
fawltydeps_check(
name = "mylib_deps_check",
target = ":mylib",
)Then run:
bazel test :mylib_deps_checkSee the examples directory for a complete working example.
The fawltydeps_aspect traverses your build graph and:
- Collects all Python source files
- Analyzes imports in those files
- Compares imports against declared dependencies
- Reports any missing or unused dependencies
- Bazel 6.0 or later
- Python 3.8 or later
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the same terms as FawltyDeps.