-
-
Notifications
You must be signed in to change notification settings - Fork 636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hygienic BUILD file modifications (like buildozer) with libCST #9434
hygienic BUILD file modifications (like buildozer) with libCST #9434
Conversation
…T!!! save progress [ci skip-jvm-tests] # No JVM changes made. add basic @goal_rule!!! [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made. make a v2 repl!!! [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made. add a HashableDict and remove a ton of code [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made. fixes after rebase [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made. make it work a lot more [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made. make parsing BUILD files for targets work!!! [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made. attempt to write down buildozer commands!!! [ci skip-jvm-tests] # No JVM changes made. refactor BUILD file object matching [ci skip-jvm-tests] # No JVM changes made. refactor object matching again [ci skip-jvm-tests] # No JVM changes made. the following command works!! (add to list attr) rlwrap ./pants -ldebug --v2 --no-v1 --no-v2-ui --query="owner_of('src/python/pants/util/strutil.py')" --query="type_filter('python_library')" --query='minimize()' --query='noop()' buildozer2 --args='add sources "tarutil.py"' [ci skip-jvm-tests] # No JVM changes made. getting and modifying data is easy now!!! this command totally works!!! rlwrap ./pants --v2 --no-v1 --no-v2-ui --query="owner_of('src/python/pants/util/strutil.py')" --query="type_filter('python_library')" --query='minimize()' --query='noop()' buildozer2 --args='add sources "tarutil.py"' --args='print name' [ci skip-jvm-tests] # No JVM changes made. refactor the AddValuesToList part [ci skip-jvm-tests] # No JVM changes made. add schema.py! [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made. everything appears to be working??? including this command: ./pants binary examples/src/scala/org/pantsbuild/example/build_graph:find-orphaned-targets && ./pants --query="type_filter('python_library')" list --output-format=json src/python/pants/util: | java -jar ./dist/find-orphaned-targets.jar | ./pants --spec-file=/dev/stdin buildozer2 --args="add tags 'orphaned'" [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made. additional fixes after rebase [ci skip-jvm-tests] # No JVM changes made. [ci skip-jvm-tests] # No JVM changes made.
@@ -61,127 +61,3 @@ def root_dir(self): | |||
def registered_aliases(self): | |||
"""Returns a copy of the registered build file aliases this build file parser uses.""" | |||
return self._build_configuration.registered_aliases() | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this is all dead code. It was dead code before this PR, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please break this out into a dedicated PR?
This change looks incredible, although the size of the diff makes it a little overwhelming to review. It’d be hugely helpful to break out any possible prework PRs like this so that this PR is smaller.
|
||
@frozen_after_init | ||
@dataclass(unsafe_hash=True) | ||
class HashableDict(Generic[_K, _V]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See FrozenDict from Pants.util.frozendict. I think it does what you’re after here.
Closing as stale, which we're doing for all changes that haven't been touched in 1+ years to simplify project management. |
TODO: add testing!
Problem
buildozer is a fantastic tool that hygeinically rewrites bazel BUILD files. We would like to do the same, but with a couple caveats (I made these up, so feel free to disagree!):
Solution
Addresses
from BUILD files to the libCST node that represents the named target.@rule
s which implement about 10% of buildozer commands by interacting with libCST.Result
(describe how your changes affect the end-user behavior of the system. this section is
optional, and should generally be summarized in the title of the pull request.)
Example commands when combined with #7356 and #8450:
rlwrap ./pants -ldebug --v2 --no-v1 --no-v2-ui --query="owner_of('src/python/pants/util/strutil.py')" --query="type_filter('python_library')" --query='minimize()' --query='noop()' buildozer2 --args='add sources "tarutil.py"'
rlwrap ./pants --v2 --no-v1 --no-v2-ui --query="owner_of('src/python/pants/util/strutil.py')" --query="type_filter('python_library')" --query='minimize()' --query='noop()' buildozer2 --args='add sources "tarutil.py"' --args='print name'
./pants binary examples/src/scala/org/pantsbuild/example/build_graph:find-orphaned-targets && ./pants --query="type_filter('python_library')" list --output-format=json src/python/pants/util: | java -jar ./dist/find-orphaned-targets.jar | ./pants --spec-file=/dev/stdin buildozer2 --args="add tags 'orphaned'"