-
-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begin adding goal to assist with the call-by-name
@rule
syntax migr…
…ation. (#20574) As discussed in #20572, this change adds a built-in goal `migrate-call-by-name` which emits all `Get` calls which should be migrated to call-by-name syntax. A followup change should use the resulting information (`@rule` function pointers and `Get` signatures) to execute rewrites of the relevant files. Emits lines like: ``` <function infer_python_conftest_dependencies at 0x113633af0> Get(<class 'pants.engine.target.Targets'>, [<class 'pants.engine.addresses.Addresses'>]) -> <function resolve_targets at 0x112335d30> Get(<class 'pants.engine.internals.graph.Owners'>, [<class 'pants.engine.internals.graph.OwnersRequest'>]) -> <function find_owners at 0x112349160> Get(<class 'pants.backend.python.util_rules.ancestor_files.AncestorFiles'>, [<class 'pants.backend.python.util_rules.ancestor_files.AncestorFilesRequest'>]) -> <function find_ancestor_files at 0x1131e6790> ```
- Loading branch information
Showing
8 changed files
with
121 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
from pants.base.exiter import ExitCode | ||
from pants.base.specs import Specs | ||
from pants.build_graph.build_configuration import BuildConfiguration | ||
from pants.engine.unions import UnionMembership | ||
from pants.goal.builtin_goal import BuiltinGoal | ||
from pants.init.engine_initializer import GraphSession | ||
from pants.option.options import Options | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class MigrateCallByNameBuiltinGoal(BuiltinGoal): | ||
name = "migrate-call-by-name" | ||
help = "Migrate from `Get` syntax to call-by-name syntax. See #19730." | ||
|
||
def run( | ||
self, | ||
build_config: BuildConfiguration, | ||
graph_session: GraphSession, | ||
options: Options, | ||
specs: Specs, | ||
union_membership: UnionMembership, | ||
) -> ExitCode: | ||
# Emit all `@rules` which use non-union Gets. | ||
for rule, dependencies in graph_session.scheduler_session.rule_graph_rule_gets().items(): | ||
print(f"{rule}") | ||
for output_type, input_types, rule_dep in dependencies: | ||
print(f" Get({output_type}, {input_types}) -> {rule_dep}") | ||
|
||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters