Skip to content

Integrate Black formatter with Bazel for local development#244

Merged
EricRahm merged 3 commits intogoogle:masterfrom
mrkushalsm:integrate-black-formatter
Feb 12, 2026
Merged

Integrate Black formatter with Bazel for local development#244
EricRahm merged 3 commits intogoogle:masterfrom
mrkushalsm:integrate-black-formatter

Conversation

@mrkushalsm
Copy link
Contributor

Hey! 👋

This PR adds Bazel integration for the Black Python formatter, addressing #226.

What's added

Two new bazel run targets:

# Fix formatting in-place
bazel run //:black_fix -- .

# Check formatting (shows diff, exits non-zero if changes needed)  
bazel run //:black_check

Changes

File Description
MODULE.bazel Added rules_shell and pip.parse extension for managing Black
BUILD Added black_runner, black_fix, and black_check targets
requirements.txt New file pinning black==24.8.0 (matching CI)
black_runner.py Python entry point for Black
black_fix.sh Shell wrapper for fixing formatting
black_check.sh Shell wrapper for checking formatting

Note on implementation

The original issue suggested using sh_test for black_check, but I went with sh_binary instead. This is because bazel test runs in a sandbox that doesn't have access to the full source tree. Using bazel run for both commands gives consistent behavior and access to all project files.

Happy to discuss if you'd prefer a different approach!

Testing

Verified locally:

  • bazel run //:black_check reports all 85 files as correctly formatted
  • bazel run //:black_fix successfully reformats files
  • ✅ Both commands respect the pyproject.toml exclusion for cached_parser.py

Adds two bazel run targets for Python code formatting:
- //:black_fix - Reformats Python files in-place
- //:black_check - Checks formatting without modifying files

Resolves Issue google#226
@google-cla
Copy link

google-cla bot commented Feb 6, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Collaborator

@EricRahm EricRahm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, a few minor requests. Thanks for the contribution!

@mrkushalsm
Copy link
Contributor Author

Hey @EricRahm!

Made the few minor changes you asked for, it was an oversight on my side for making those date mistakes and not keeping the shell and python files under scripts folder, have fixed it now.

Do review and let me know if anymore changes are needed!!

@mrkushalsm
Copy link
Contributor Author

Sorry, forgot to change the BUILD file, do run the tests and check now!

@EricRahm
Copy link
Collaborator

Looks good, thanks for the contribution!

@EricRahm EricRahm merged commit 1dc287f into google:master Feb 12, 2026
8 checks passed
@mrkushalsm
Copy link
Contributor Author

mrkushalsm commented Feb 12, 2026

Thanks for providing this opportunity to me Eric, glad to have contributed!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants