Integrate Black formatter with Bazel for local development#244
Integrate Black formatter with Bazel for local development#244EricRahm merged 3 commits intogoogle:masterfrom
Conversation
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
|
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. |
EricRahm
left a comment
There was a problem hiding this comment.
Overall looks good, a few minor requests. Thanks for the contribution!
|
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!! |
|
Sorry, forgot to change the |
|
Looks good, thanks for the contribution! |
|
Thanks for providing this opportunity to me Eric, glad to have contributed!! |
Hey! 👋
This PR adds Bazel integration for the Black Python formatter, addressing #226.
What's added
Two new
bazel runtargets:Changes
MODULE.bazelrules_shellandpip.parseextension for managing BlackBUILDblack_runner,black_fix, andblack_checktargetsrequirements.txtblack==24.8.0(matching CI)black_runner.pyblack_fix.shblack_check.shNote on implementation
The original issue suggested using
sh_testforblack_check, but I went withsh_binaryinstead. This is becausebazel testruns in a sandbox that doesn't have access to the full source tree. Usingbazel runfor 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_checkreports all 85 files as correctly formattedbazel run //:black_fixsuccessfully reformats filespyproject.tomlexclusion forcached_parser.py