Skip to content

Commit cec63e0

Browse files
Rename V2 Configuration to FieldSet (#9668)
This name describes the ad hoc collection of Fields needed by some rules, such as the Fields needed to create an AWS Lambda. "Configuration" is a very overloaded term and doesn't express its relationship to the Target API / Fields. Rejected alternatives: * Fields -> no way to make this plural. * FieldCollection -> clunkier than FieldSet. * AdHocTarget -> clunky and too close to `Target`. [ci skip-rust-tests] [ci skip-jvm-tests]
1 parent 953c448 commit cec63e0

32 files changed

+531
-537
lines changed

src/python/pants/backend/awslambda/common/awslambda_common_rules.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212
from pants.engine.goal import Goal, GoalSubsystem, LineOriented
1313
from pants.engine.rules import goal_rule
1414
from pants.engine.selectors import Get, MultiGet
15-
from pants.engine.target import (
16-
Configuration,
17-
TargetsToValidConfigurations,
18-
TargetsToValidConfigurationsRequest,
19-
)
15+
from pants.engine.target import FieldSet, TargetsToValidFieldSets, TargetsToValidFieldSetsRequest
2016
from pants.engine.unions import union
2117

2218

@@ -33,7 +29,7 @@ class CreatedAWSLambda:
3329

3430

3531
@union
36-
class AWSLambdaConfiguration(Configuration, metaclass=ABCMeta):
32+
class AWSLambdaFieldSet(FieldSet, metaclass=ABCMeta):
3733
"""The fields necessary to create an AWS Lambda from a target."""
3834

3935

@@ -55,16 +51,16 @@ async def create_awslambda(
5551
buildroot: BuildRoot,
5652
workspace: Workspace,
5753
) -> AWSLambdaGoal:
58-
targets_to_valid_configs = await Get[TargetsToValidConfigurations](
59-
TargetsToValidConfigurationsRequest(
60-
AWSLambdaConfiguration,
54+
targets_to_valid_field_sets = await Get[TargetsToValidFieldSets](
55+
TargetsToValidFieldSetsRequest(
56+
AWSLambdaFieldSet,
6157
goal_description=f"the `{options.name}` goal",
6258
error_if_no_valid_targets=True,
6359
)
6460
)
6561
awslambdas = await MultiGet(
66-
Get[CreatedAWSLambda](AWSLambdaConfiguration, config)
67-
for config in targets_to_valid_configs.configurations
62+
Get[CreatedAWSLambda](AWSLambdaFieldSet, field_set)
63+
for field_set in targets_to_valid_field_sets.field_sets
6864
)
6965
merged_digest = await Get[Digest](MergeDigests(awslambda.digest for awslambda in awslambdas))
7066
result = workspace.materialize_directory(

src/python/pants/backend/awslambda/python/awslambda_python_rules.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from dataclasses import dataclass
55

66
from pants.backend.awslambda.common.awslambda_common_rules import (
7-
AWSLambdaConfiguration,
7+
AWSLambdaFieldSet,
88
CreatedAWSLambda,
99
)
1010
from pants.backend.awslambda.python.lambdex import Lambdex
@@ -43,7 +43,7 @@
4343

4444

4545
@dataclass(frozen=True)
46-
class PythonAwsLambdaConfiguration(AWSLambdaConfiguration):
46+
class PythonAwsLambdaFieldSet(AWSLambdaFieldSet):
4747
required_fields = (PythonAwsLambdaHandler, PythonAwsLambdaRuntime)
4848

4949
handler: PythonAwsLambdaHandler
@@ -57,23 +57,23 @@ class LambdexSetup:
5757

5858
@named_rule(desc="Create Python AWS Lambda")
5959
async def create_python_awslambda(
60-
config: PythonAwsLambdaConfiguration,
60+
field_set: PythonAwsLambdaFieldSet,
6161
lambdex_setup: LambdexSetup,
6262
python_setup: PythonSetup,
6363
subprocess_encoding_environment: SubprocessEncodingEnvironment,
6464
) -> CreatedAWSLambda:
6565
# Lambdas typically use the .zip suffix, so we use that instead of .pex.
66-
pex_filename = f"{config.address.target_name}.zip"
66+
pex_filename = f"{field_set.address.target_name}.zip"
6767
# We hardcode the platform value to the appropriate one for each AWS Lambda runtime.
6868
# (Running the "hello world" lambda in the example code will report the platform, and can be
6969
# used to verify correctness of these platform strings.)
70-
py_major, py_minor = config.runtime.to_interpreter_version()
70+
py_major, py_minor = field_set.runtime.to_interpreter_version()
7171
platform = f"manylinux2014_x86_64-cp-{py_major}{py_minor}-cp{py_major}{py_minor}m"
7272
if (py_major, py_minor) == (2, 7):
7373
platform += "u"
7474
pex_request = TwoStepPexFromTargetsRequest(
7575
PexFromTargetsRequest(
76-
addresses=Addresses([config.address]),
76+
addresses=Addresses([field_set.address]),
7777
entry_point=None,
7878
output_filename=pex_filename,
7979
platforms=PexPlatforms([platform]),
@@ -86,7 +86,7 @@ async def create_python_awslambda(
8686
)
8787

8888
# NB: Lambdex modifies its input pex in-place, so the input file is also the output file.
89-
lambdex_args = ("build", "-e", config.handler.value, pex_filename)
89+
lambdex_args = ("build", "-e", field_set.handler.value, pex_filename)
9090
process = lambdex_setup.requirements_pex.create_process(
9191
python_setup=python_setup,
9292
subprocess_encoding_environment=subprocess_encoding_environment,
@@ -102,7 +102,7 @@ async def create_python_awslambda(
102102
return CreatedAWSLambda(
103103
digest=result.output_digest,
104104
name=pex_filename,
105-
runtime=config.runtime.value,
105+
runtime=field_set.runtime.value,
106106
handler="lambdex_handler.handler",
107107
)
108108

@@ -126,7 +126,7 @@ def rules():
126126
return [
127127
create_python_awslambda,
128128
setup_lambdex,
129-
UnionRule(AWSLambdaConfiguration, PythonAwsLambdaConfiguration),
129+
UnionRule(AWSLambdaFieldSet, PythonAwsLambdaFieldSet),
130130
SubsystemRule(Lambdex),
131131
*download_pex_bin.rules(),
132132
*importable_python_sources.rules(),

src/python/pants/backend/awslambda/python/awslambda_python_rules_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from zipfile import ZipFile
88

99
from pants.backend.awslambda.common.awslambda_common_rules import CreatedAWSLambda
10-
from pants.backend.awslambda.python.awslambda_python_rules import PythonAwsLambdaConfiguration
10+
from pants.backend.awslambda.python.awslambda_python_rules import PythonAwsLambdaFieldSet
1111
from pants.backend.awslambda.python.awslambda_python_rules import rules as awslambda_python_rules
1212
from pants.backend.awslambda.python.target_types import PythonAWSLambda
1313
from pants.backend.python.target_types import PythonLibrary
@@ -23,7 +23,7 @@
2323
class TestPythonAWSLambdaCreation(TestBase):
2424
@classmethod
2525
def rules(cls):
26-
return (*super().rules(), *awslambda_python_rules(), RootRule(PythonAwsLambdaConfiguration))
26+
return (*super().rules(), *awslambda_python_rules(), RootRule(PythonAwsLambdaFieldSet))
2727

2828
@classmethod
2929
def target_types(cls):
@@ -34,7 +34,7 @@ def create_python_awslambda(self, addr: str) -> Tuple[str, bytes]:
3434
created_awslambda = self.request_single_product(
3535
CreatedAWSLambda,
3636
Params(
37-
PythonAwsLambdaConfiguration.create(target),
37+
PythonAwsLambdaFieldSet.create(target),
3838
create_options_bootstrapper(
3939
args=["--backend-packages2=pants.backend.awslambda.python"]
4040
),

src/python/pants/backend/python/lint/bandit/rules.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from pants.backend.python.subsystems import python_native_code, subprocess_environment
1616
from pants.backend.python.subsystems.subprocess_environment import SubprocessEncodingEnvironment
1717
from pants.backend.python.target_types import PythonInterpreterCompatibility, PythonSources
18-
from pants.core.goals.lint import LinterConfiguration, LinterConfigurations, LintResult
18+
from pants.core.goals.lint import LinterFieldSet, LinterFieldSets, LintResult
1919
from pants.core.util_rules import determine_source_files, strip_source_roots
2020
from pants.core.util_rules.determine_source_files import (
2121
AllSourceFilesRequest,
@@ -33,15 +33,15 @@
3333

3434

3535
@dataclass(frozen=True)
36-
class BanditConfiguration(LinterConfiguration):
36+
class BanditFieldSet(LinterFieldSet):
3737
required_fields = (PythonSources,)
3838

3939
sources: PythonSources
4040
compatibility: PythonInterpreterCompatibility
4141

4242

43-
class BanditConfigurations(LinterConfigurations):
44-
config_type = BanditConfiguration
43+
class BanditFieldSets(LinterFieldSets):
44+
field_set_type = BanditFieldSet
4545

4646

4747
def generate_args(*, specified_source_files: SourceFiles, bandit: Bandit) -> Tuple[str, ...]:
@@ -55,7 +55,7 @@ def generate_args(*, specified_source_files: SourceFiles, bandit: Bandit) -> Tup
5555

5656
@named_rule(desc="Lint using Bandit")
5757
async def bandit_lint(
58-
configs: BanditConfigurations,
58+
field_sets: BanditFieldSets,
5959
bandit: Bandit,
6060
python_setup: PythonSetup,
6161
subprocess_encoding_environment: SubprocessEncodingEnvironment,
@@ -66,7 +66,7 @@ async def bandit_lint(
6666
# NB: Bandit output depends upon which Python interpreter version it's run with. See
6767
# https://github.com/PyCQA/bandit#under-which-version-of-python-should-i-install-bandit.
6868
interpreter_constraints = PexInterpreterConstraints.create_from_compatibility_fields(
69-
(config.compatibility for config in configs), python_setup=python_setup
69+
(field_set.compatibility for field_set in field_sets), python_setup=python_setup
7070
)
7171
requirements_pex = await Get[Pex](
7272
PexRequest(
@@ -87,10 +87,12 @@ async def bandit_lint(
8787
)
8888

8989
all_source_files = await Get[SourceFiles](
90-
AllSourceFilesRequest(config.sources for config in configs)
90+
AllSourceFilesRequest(field_set.sources for field_set in field_sets)
9191
)
9292
specified_source_files = await Get[SourceFiles](
93-
SpecifiedSourceFilesRequest((config.sources, config.origin) for config in configs)
93+
SpecifiedSourceFilesRequest(
94+
(field_set.sources, field_set.origin) for field_set in field_sets
95+
)
9496
)
9597

9698
merged_input_files = await Get[Digest](
@@ -99,15 +101,17 @@ async def bandit_lint(
99101
),
100102
)
101103

102-
address_references = ", ".join(sorted(config.address.reference() for config in configs))
104+
address_references = ", ".join(
105+
sorted(field_set.address.reference() for field_set in field_sets)
106+
)
103107

104108
process = requirements_pex.create_process(
105109
python_setup=python_setup,
106110
subprocess_encoding_environment=subprocess_encoding_environment,
107111
pex_path=f"./bandit.pex",
108112
pex_args=generate_args(specified_source_files=specified_source_files, bandit=bandit),
109113
input_files=merged_input_files,
110-
description=f"Run Bandit on {pluralize(len(configs), 'target')}: {address_references}.",
114+
description=f"Run Bandit on {pluralize(len(field_sets), 'target')}: {address_references}.",
111115
)
112116
result = await Get[FallibleProcessResult](Process, process)
113117
return LintResult.from_fallible_process_result(result)
@@ -117,7 +121,7 @@ def rules():
117121
return [
118122
bandit_lint,
119123
SubsystemRule(Bandit),
120-
UnionRule(LinterConfigurations, BanditConfigurations),
124+
UnionRule(LinterFieldSets, BanditFieldSets),
121125
*download_pex_bin.rules(),
122126
*determine_source_files.rules(),
123127
*pex.rules(),

src/python/pants/backend/python/lint/bandit/rules_integration_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from typing import List, Optional
55

6-
from pants.backend.python.lint.bandit.rules import BanditConfiguration, BanditConfigurations
6+
from pants.backend.python.lint.bandit.rules import BanditFieldSet, BanditFieldSets
77
from pants.backend.python.lint.bandit.rules import rules as bandit_rules
88
from pants.backend.python.target_types import PythonInterpreterCompatibility, PythonLibrary
99
from pants.base.specs import FilesystemLiteralSpec, OriginSpec, SingleAddress
@@ -25,7 +25,7 @@ class BanditIntegrationTest(TestBase):
2525

2626
@classmethod
2727
def rules(cls):
28-
return (*super().rules(), *bandit_rules(), RootRule(BanditConfigurations))
28+
return (*super().rules(), *bandit_rules(), RootRule(BanditFieldSets))
2929

3030
def make_target_with_origin(
3131
self,
@@ -63,7 +63,7 @@ def run_bandit(
6363
return self.request_single_product(
6464
LintResult,
6565
Params(
66-
BanditConfigurations(BanditConfiguration.create(tgt) for tgt in targets),
66+
BanditFieldSets(BanditFieldSet.create(tgt) for tgt in targets),
6767
create_options_bootstrapper(args=args),
6868
),
6969
)

src/python/pants/backend/python/lint/black/rules.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import Optional, Tuple
88

99
from pants.backend.python.lint.black.subsystem import Black
10-
from pants.backend.python.lint.python_fmt import PythonFmtConfigurations
10+
from pants.backend.python.lint.python_fmt import PythonFmtFieldSets
1111
from pants.backend.python.rules import download_pex_bin, pex
1212
from pants.backend.python.rules.pex import (
1313
Pex,
@@ -18,8 +18,8 @@
1818
from pants.backend.python.subsystems import python_native_code, subprocess_environment
1919
from pants.backend.python.subsystems.subprocess_environment import SubprocessEncodingEnvironment
2020
from pants.backend.python.target_types import PythonSources
21-
from pants.core.goals.fmt import FmtConfiguration, FmtConfigurations, FmtResult
22-
from pants.core.goals.lint import LinterConfigurations, LintResult
21+
from pants.core.goals.fmt import FmtFieldSet, FmtFieldSets, FmtResult
22+
from pants.core.goals.lint import LinterFieldSets, LintResult
2323
from pants.core.util_rules import determine_source_files, strip_source_roots
2424
from pants.core.util_rules.determine_source_files import (
2525
AllSourceFilesRequest,
@@ -37,19 +37,19 @@
3737

3838

3939
@dataclass(frozen=True)
40-
class BlackConfiguration(FmtConfiguration):
40+
class BlackFieldSet(FmtFieldSet):
4141
required_fields = (PythonSources,)
4242

4343
sources: PythonSources
4444

4545

46-
class BlackConfigurations(FmtConfigurations):
47-
config_type = BlackConfiguration
46+
class BlackFieldSets(FmtFieldSets):
47+
field_set_type = BlackFieldSet
4848

4949

5050
@dataclass(frozen=True)
5151
class SetupRequest:
52-
configs: BlackConfigurations
52+
field_sets: BlackFieldSets
5353
check_only: bool
5454

5555

@@ -106,16 +106,18 @@ async def setup(
106106
)
107107
)
108108

109-
if request.configs.prior_formatter_result is None:
109+
if request.field_sets.prior_formatter_result is None:
110110
all_source_files = await Get[SourceFiles](
111-
AllSourceFilesRequest(config.sources for config in request.configs)
111+
AllSourceFilesRequest(field_set.sources for field_set in request.field_sets)
112112
)
113113
all_source_files_snapshot = all_source_files.snapshot
114114
else:
115-
all_source_files_snapshot = request.configs.prior_formatter_result
115+
all_source_files_snapshot = request.field_sets.prior_formatter_result
116116

117117
specified_source_files = await Get[SourceFiles](
118-
SpecifiedSourceFilesRequest((config.sources, config.origin) for config in request.configs)
118+
SpecifiedSourceFilesRequest(
119+
(field_set.sources, field_set.origin) for field_set in request.field_sets
120+
)
119121
)
120122

121123
merged_input_files = await Get[Digest](
@@ -124,7 +126,9 @@ async def setup(
124126
),
125127
)
126128

127-
address_references = ", ".join(sorted(config.address.reference() for config in request.configs))
129+
address_references = ", ".join(
130+
sorted(field_set.address.reference() for field_set in request.field_sets)
131+
)
128132

129133
process = requirements_pex.create_process(
130134
python_setup=python_setup,
@@ -138,26 +142,26 @@ async def setup(
138142
input_files=merged_input_files,
139143
output_files=all_source_files_snapshot.files,
140144
description=(
141-
f"Run Black on {pluralize(len(request.configs), 'target')}: {address_references}."
145+
f"Run Black on {pluralize(len(request.field_sets), 'target')}: {address_references}."
142146
),
143147
)
144148
return Setup(process, original_digest=all_source_files_snapshot.digest)
145149

146150

147151
@named_rule(desc="Format using Black")
148-
async def black_fmt(configs: BlackConfigurations, black: Black) -> FmtResult:
152+
async def black_fmt(field_sets: BlackFieldSets, black: Black) -> FmtResult:
149153
if black.options.skip:
150154
return FmtResult.noop()
151-
setup = await Get[Setup](SetupRequest(configs, check_only=False))
155+
setup = await Get[Setup](SetupRequest(field_sets, check_only=False))
152156
result = await Get[ProcessResult](Process, setup.process)
153157
return FmtResult.from_process_result(result, original_digest=setup.original_digest)
154158

155159

156160
@named_rule(desc="Lint using Black")
157-
async def black_lint(configs: BlackConfigurations, black: Black) -> LintResult:
161+
async def black_lint(field_sets: BlackFieldSets, black: Black) -> LintResult:
158162
if black.options.skip:
159163
return LintResult.noop()
160-
setup = await Get[Setup](SetupRequest(configs, check_only=True))
164+
setup = await Get[Setup](SetupRequest(field_sets, check_only=True))
161165
result = await Get[FallibleProcessResult](Process, setup.process)
162166
return LintResult.from_fallible_process_result(result)
163167

@@ -168,8 +172,8 @@ def rules():
168172
black_fmt,
169173
black_lint,
170174
SubsystemRule(Black),
171-
UnionRule(PythonFmtConfigurations, BlackConfigurations),
172-
UnionRule(LinterConfigurations, BlackConfigurations),
175+
UnionRule(PythonFmtFieldSets, BlackFieldSets),
176+
UnionRule(LinterFieldSets, BlackFieldSets),
173177
*download_pex_bin.rules(),
174178
*determine_source_files.rules(),
175179
*pex.rules(),

0 commit comments

Comments
 (0)