[codex] extract Bazel build file parsing utility#128
Conversation
69d21f1 to
0a15164
Compare
|
Thanks for the cleanup. Could you split this up in 2 PRs. A first one where we extract the common logic + tests into the utils file and utils tests. We get that merged first. Then a second PR adding the new hook. This makes it easier to review. |
8a81d91 to
3a15c77
Compare
|
Done. I split this so PR #128 now only extracts the shared Bazel BUILD file parsing/tag helpers into |
|
Created the stacked follow-up PR for the new hook here: lukasoyen#1 It is based on the utility branch from this PR and contains only the |
| import sys | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from dev_tools.build_file_parsing_util import find_rule_calls as find_build_file_rule_calls |
There was a problem hiding this comment.
| from dev_tools.build_file_parsing_util import find_rule_calls as find_build_file_rule_calls | |
| from dev_tools.build_file_parsing_util import find_rule_calls |
There was a problem hiding this comment.
Oh now I get it, the impl slighly changed and we have the function still here. Can you explain?
There was a problem hiding this comment.
Previously the find_rule_calls() got the rule kind to inject into the regex. With the new helper function that is no longer the case as the forbidden tag use case needs to be able to glob on the rule kind.
So now the regex matches all targets and the function needs to filter down to the rule kinds it is interested in for check_rule_has_tag.py. Also the return type is enhanced because the forbidden tags use case needs to get the rule kind and the target body.
We want to have the filtering in the helper find_rule_calls() because we can do that before we try to do the expensive parenthesis matching.
| from dev_tools.build_file_parsing_util import find_rule_calls as find_build_file_rule_calls | ||
| from dev_tools.build_file_parsing_util import rule_has_tag |
There was a problem hiding this comment.
Since we are moving these two, we should also move their tests in https://github.com/hofbi/dev-tools/blob/master/tests/test_check_rule_has_tag.py instead of creating new ones.
There was a problem hiding this comment.
Done in 761899f: moved the parser/tag tests out of test_check_rule_has_tag.py so they now live in tests/test_build_file_parsing_util.py, and left test_check_rule_has_tag.py focused on the hook-level file checks.
3a15c77 to
761899f
Compare
Summary
Extracts shared Bazel BUILD file parsing helpers into
dev_tools.build_file_parsing_util.This moves rule-call parsing and tag detection out of
check_rule_has_tag.py, keeps the existing hook behavior unchanged, and adds dedicated utility tests.Validation
uv run --extra dev pytest tests/test_build_file_parsing_util.py tests/test_check_rule_has_tag.pyuv run --with ruff ruff check dev_tools/build_file_parsing_util.py dev_tools/check_rule_has_tag.py tests/test_build_file_parsing_util.py tests/test_check_rule_has_tag.pyuv run --with ruff ruff format --check dev_tools/build_file_parsing_util.py dev_tools/check_rule_has_tag.py tests/test_build_file_parsing_util.py tests/test_check_rule_has_tag.pyuv run --with ty ty check dev_tools/build_file_parsing_util.py dev_tools/check_rule_has_tag.py tests/test_build_file_parsing_util.py tests/test_check_rule_has_tag.py