Skip to content

Commit f7d37c4

Browse files
authored
docs: update imports to reflect current classes (#23100)
This is the less mechanical LLM followup to #23097. For each non-example import that doesn't match current reality, try to update it. I've looked at each of the cited PRs and checked with `grep`, but I wasn't looking closely at the internals at the time of most of these. * `InjectDependenciesRequest` → `InferDependenciesRequest` - #16107 * `InjectedDependencies` → `InferredDependencies` - #16107 * `inject_for` → `infer_from` - #16107 * `Sources` → `MultipleSourcesField` - #13439 * `LintResults` → `LintResult` - #16735 * `BanditRequest` → `BanditRequest.Batch` - #16735 * `PexBinaryTarget` → `PexBinary` - N/A (docs error introduced in #20399 - code was always `PexBinary`) * `PexEntryPoint` → `PexEntryPointField` - #17870
1 parent 5fb080e commit f7d37c4

File tree

5 files changed

+32
-27
lines changed

5 files changed

+32
-27
lines changed

docs/docs/writing-plugins/common-plugin-tasks/add-a-publisher.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def rules():
162162
If your publisher has expensive packaging steps, you can use `check_skip_request` to preemptively skip packaging when you know the publish will be skipped:
163163

164164
```python
165+
from pants.core.goals.package import PackageFieldSet
165166
from pants.core.goals.publish import CheckSkipRequest, CheckSkipResult
166-
from pants.core.goals import package
167167

168168

169169
@dataclass(frozen=True)
@@ -174,7 +174,7 @@ class MyPublishFieldSet(PublishFieldSet):
174174
repositories: MyRepositoriesField
175175
skip_push: MySkipPushField
176176

177-
def check_skip_request(self, package_fs: package.PackageFieldSet) -> CheckSkipRequest[Self] | None:
177+
def check_skip_request(self, package_fs: PackageFieldSet) -> CheckSkipRequest[Self] | None:
178178
"""Return a request to check if we should skip packaging."""
179179
return MyPublishSkipRequest(publish_fs=self, package_fs=package_fs)
180180
```

docs/docs/writing-plugins/common-plugin-tasks/add-codegen.mdx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ Instead of users having to explicitly add this dependency every time, you can dy
5454
To inject dependencies:
5555

5656
1. Subclass the `Dependencies` field. Register this subclass on your protocol target type.
57-
2. Define a subclass of `InjectDependenciesRequest` and set the class property `inject_for` to the `Dependencies` subclass defined in the previous step. Register this new class with a [`UnionRule`](../the-rules-api/union-rules-advanced.mdx) for `InjectDependenciesRequest`.
58-
3. Create a new rule that takes your new `InjectDependenciesRequest` subclass as a parameter and returns `InjectedDependencies`.
57+
2. Define a `FieldSet` subclass that includes the `Dependencies` subclass and any other fields needed for inference.
58+
3. Define a subclass of `InferDependenciesRequest` and set the class property `infer_from` to the `FieldSet` subclass defined in the previous step. Register this new class with a [`UnionRule`](../the-rules-api/union-rules-advanced.mdx) for `InferDependenciesRequest`.
59+
4. Create a new rule that takes your new `InferDependenciesRequest` subclass as a parameter and returns `InferredDependencies`.
5960

6061
```python
6162
from pants.engine.addresses import Address
62-
from pants.engine.target import Dependencies, InjectDependenciesRequest, InjectedDependencies
63+
from pants.engine.target import Dependencies, FieldSet, InferDependenciesRequest, InferredDependencies
6364
from pants.engine.rules import collect_rules, rule
6465
from pants.engine.unions import UnionRule
6566

@@ -72,18 +73,24 @@ class ProtobufSourceTarget(Target):
7273
alias = "protobuf_source"
7374
core_fields = (*COMMON_TARGET_FIELDS, ProtobufDependencies, ProtobufSourceField)
7475

75-
class InjectProtobufDependencies(InjectDependenciesRequest):
76-
inject_for = ProtobufDependencies
76+
class ProtobufDependenciesInferenceFieldSet(FieldSet):
77+
required_fields = (ProtobufDependencies,)
78+
dependencies: ProtobufDependencies
79+
80+
class InferProtobufDependencies(InferDependenciesRequest):
81+
infer_from = ProtobufDependenciesInferenceFieldSet
7782

7883
@rule
79-
async def inject_dependencies(_: InjectProtobufDependencies) -> InjectedDependencies:
84+
async def infer_protobuf_dependencies(
85+
request: InferProtobufDependencies
86+
) -> InferredDependencies:
8087
address = Address("3rdparty/python", target_name="protobuf")
81-
return InjectedDependencies([address])
88+
return InferredDependencies([address])
8289

8390
def rules():
8491
return [
8592
*collect_rules(),
86-
UnionRule(InjectDependenciesRequest, InjectProtobufDependencies),
93+
UnionRule(InferDependenciesRequest, InferProtobufDependencies),
8794
]
8895
```
8996

docs/docs/writing-plugins/the-rules-api/testing-plugins.mdx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ We can write this test:
153153
from pants.engine.addresses import Address
154154
from pants.engine.fs import EMPTY_DIGEST, Snapshot
155155
from pants.engine.internals.graph import hydrate_sources
156-
from pants.engine.target import HydratedSources, HydrateSourcesRequest, Target, Sources
156+
from pants.engine.target import HydratedSources, HydrateSourcesRequest, MultipleSourcesField, Target
157157
from pants.testutil.rule_runner import run_rule_with_mocks
158158

159159
class MockTarget(Target):
160160
alias = "mock_target"
161-
core_fields = (Sources,)
161+
core_fields = (MultipleSourcesField,)
162162

163163

164164
def test_find_needle_in_haystack() -> None:
@@ -442,24 +442,22 @@ Given this rule signature for running the linter Bandit:
442442

443443
```python
444444
@rule
445-
async def bandit_lint(
446-
request: BanditRequest, bandit: Bandit, python_setup: PythonSetup
447-
) -> LintResults:
445+
async def bandit_lint(batch: BanditRequest.Batch) -> LintResult:
448446
...
449447
```
450448

451449
We can write a test like this:
452450

453451
```python
454-
from pants.core.goals.lint import LintResult, LintResults
452+
from pants.core.goals.lint import LintResult
455453
from pants.testutil.rule_runner import QueryRule, RuleRunner
456454

457455
@pytest.fixture
458456
def rule_runner() -> RuleRunner:
459457
return RuleRunner(
460458
rules=[
461459
*bandit_rules(),
462-
QueryRule(LintResults, [BanditRequest]),
460+
QueryRule(LintResult, [BanditRequest.Batch]),
463461
],
464462
target_types=[PythonSourceTarget]
465463
)
@@ -470,11 +468,11 @@ def test_bandit(rule_runner: RuleRunner) -> None:
470468
...
471469

472470
# Run Bandit rule.
473-
bandit_request = BanditRequest(...)
474-
lint_results = rule_runner.request(LintResults, [bandit_request])
471+
bandit_batch = BanditRequest.Batch(...)
472+
lint_result = rule_runner.request(LintResult, [bandit_batch])
475473
```
476474

477-
Note that our `@rule` takes 3 parameters, but we only explicitly included `BanditRequest` in the inputs. This is possible because the engine knows how to compute all [Subsystems](./options-and-subsystems.mdx) based on the initial input to the graph. See [Concepts](./concepts.mdx).
475+
Note that the lint rule now takes a `Batch` object as input. The engine knows how to compute all [Subsystems](./options-and-subsystems.mdx) based on the initial input to the graph. See [Concepts](./concepts.mdx).
478476

479477
We are happy [to help](/community/members) figure out what rules to register, and what inputs to pass to `rule_runner.request()`. It can also help to [visualize the rule graph](./tips-and-debugging.mdx) when running your code in production. If you're missing an input that you need, the engine will error explaining that there is no way to compute your `OutputType`.
480478

docs/docs/writing-plugins/the-rules-api/union-rules-advanced.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ class LintTargetsRequest(ABC):
3333

3434

3535
@dataclass(frozen=True)
36-
class LintResults:
36+
class LintResult:
3737
...
3838

3939

4040
@rule(polymorphic=True)
41-
async def lint_target(req: LintTargetsRequest) -> LintResults:
41+
async def lint_target(req: LintTargetsRequest) -> LintResult:
4242
# If no implementation for the member type is found, this generic
4343
# implementation will be invoked. In this case that is not useful,
4444
# so we raise.
@@ -63,7 +63,7 @@ async def lint(targets: Targets, union_membership: UnionMembership) -> Lint:
6363
```
6464

6565
```python title="pants-plugins/bash/shellcheck.py"
66-
from pants.core.goals.lint import LintResults, LintTargetsRequest
66+
from pants.core.goals.lint import LintResult, LintTargetsRequest
6767
from pants.engine.rules import collect_rules, rule
6868

6969

@@ -75,7 +75,7 @@ class ShellcheckRequest(LintTargetsRequest):
7575

7676

7777
@rule
78-
async def shellcheck_target(req: ShellcheckRequest) -> LintResults:
78+
async def shellcheck_target(req: ShellcheckRequest) -> LintResult:
7979
# At runtime, calls to the generic `lint_target()` on a
8080
# `ShellcheckRequest` will be dispatched here.
8181
...

docs/docs/writing-plugins/the-target-api/creating-new-targets.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ For example, you might like how `pex_binary` behaves in general, but you have a
7070
Rather than subclassing the original target type, use this pattern:
7171

7272
```python
73-
from pants.backend.python.target_types import PexBinaryTarget, PexEntryPointField
73+
from pants.backend.python.target_types import PexBinary, PexEntryPointField
7474
from pants.engine.target import Target
7575
from pants.util.ordered_set import FrozenOrderedSet
7676

@@ -81,12 +81,12 @@ class DjangoEntryPointField(PexEntryPointField):
8181
class DjangoManagePyTarget(Target):
8282
alias = "django_manage_py"
8383
core_fields = (
84-
*(FrozenOrderedSet(PexBinaryTarget.core_fields) - {PexEntryPoint}),
84+
*(FrozenOrderedSet(PexBinary.core_fields) - {PexEntryPointField}),
8585
DjangoEntryPointField,
8686
)
8787
```
8888

89-
In this example, we register all of the fields of `PexBinaryTarget`, except for the field `PexEntryPoint `. We instead register our custom field `DjangoEntryPointField `.
89+
In this example, we register all of the fields of `PexBinary`, except for the field `PexEntryPointField`. We instead register our custom field `DjangoEntryPointField`.
9090
:::
9191

9292
## Step 2: Register the target type in `register.py`

0 commit comments

Comments
 (0)