Skip to content

Commit

Permalink
Rename FmtRequest to FmtTargetsRequest (plus some fix refactori…
Browse files Browse the repository at this point in the history
…ng) (#16535)

This is prepwork for dissolving update-build-files from #13504, as well as #16480. No semantic changes have been made, just renaming and refactoring.

Note that FmtResult hasn't been renamed, as it isn't target-specific.

Commits are useful to review smile

[ci skip-rust]
[ci skip-build-wheels]
  • Loading branch information
thejcannon authored Aug 16, 2022
1 parent c9c1659 commit 645b1ac
Show file tree
Hide file tree
Showing 21 changed files with 188 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ updatedAt: "2022-07-25T20:02:17.695Z"

See <https://github.com/pantsbuild/pants/blob/main/src/python/pants/notes/2.14.x.md> for the changelog.

### `FmtRequest` -> `FmtTargetsRequest`

In order to support non-target formatting (like `BUILD` files) we'll be introducing additional `fmt`
request types. Therefore `FmtRequest` has been renamed to `FmtTargetsRequest` to reflect the behavior.

This change also matches `lint`, which uses `LintTargetsRequest`.

### Optional Option flag name

Pants 2.14 adds support for deducing the flag name from the attribute name when declaring `XOption`s.
Expand Down Expand Up @@ -138,7 +145,7 @@ You can also now specify multiple globs, e.g. `req.path_globs("*.py", "*.pyi")`.

### Banned short option names like `-x`

You must now use a long option name when [defining options](doc:rules-api-subsystems). You can also now only specify a single option name per option.
You must now use a long option name when [defining options](doc:rules-api-subsystems). You can also now only specify a single option name per option.

(These changes allowed us to introduce ignore specs, like `./pants list :: -ignore_me::`.)

Expand Down
6 changes: 3 additions & 3 deletions src/python/pants/backend/cc/lint/clangformat/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pants.backend.cc.lint.clangformat.subsystem import ClangFormat
from pants.backend.cc.target_types import CCSourceField
from pants.backend.python.util_rules.pex import Pex, PexProcess, PexRequest
from pants.core.goals.fmt import FmtRequest, FmtResult
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
from pants.core.util_rules.config_files import ConfigFiles, ConfigFilesRequest
from pants.engine.fs import Digest, MergeDigests, Snapshot
from pants.engine.process import ProcessResult
Expand All @@ -30,7 +30,7 @@ class ClangFormatFmtFieldSet(FieldSet):
sources: CCSourceField


class ClangFormatRequest(FmtRequest):
class ClangFormatRequest(FmtTargetsRequest):
field_set_type = ClangFormatFmtFieldSet
name = ClangFormat.options_scope

Expand Down Expand Up @@ -88,5 +88,5 @@ async def clangformat_fmt(request: ClangFormatRequest, clangformat: ClangFormat)
def rules() -> Iterable[Rule | UnionRule]:
return (
*collect_rules(),
UnionRule(FmtRequest, ClangFormatRequest),
UnionRule(FmtTargetsRequest, ClangFormatRequest),
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ProtobufDependenciesField,
ProtobufSourceField,
)
from pants.core.goals.fmt import FmtRequest, FmtResult
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
from pants.core.util_rules.external_tool import DownloadedExternalTool, ExternalToolRequest
from pants.core.util_rules.system_binaries import (
BinaryShims,
Expand Down Expand Up @@ -39,7 +39,7 @@ def opt_out(cls, tgt: Target) -> bool:
return tgt.get(SkipBufFormatField).value


class BufFormatRequest(FmtRequest):
class BufFormatRequest(FmtTargetsRequest):
field_set_type = BufFieldSet
name = "buf-format"

Expand Down Expand Up @@ -97,5 +97,5 @@ async def run_buf_format(request: BufFormatRequest, buf: BufSubsystem) -> FmtRes
def rules():
return [
*collect_rules(),
UnionRule(FmtRequest, BufFormatRequest),
UnionRule(FmtTargetsRequest, BufFormatRequest),
]
6 changes: 3 additions & 3 deletions src/python/pants/backend/go/lint/gofmt/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pants.backend.go.target_types import GoPackageSourcesField
from pants.backend.go.util_rules import goroot
from pants.backend.go.util_rules.goroot import GoRoot
from pants.core.goals.fmt import FmtRequest, FmtResult
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
from pants.engine.fs import Digest
from pants.engine.internals.native_engine import Snapshot
from pants.engine.internals.selectors import Get
Expand All @@ -34,7 +34,7 @@ def opt_out(cls, tgt: Target) -> bool:
return tgt.get(SkipGofmtField).value


class GofmtRequest(FmtRequest):
class GofmtRequest(FmtTargetsRequest):
field_set_type = GofmtFieldSet
name = GofmtSubsystem.options_scope

Expand Down Expand Up @@ -66,5 +66,5 @@ def rules():
return [
*collect_rules(),
*goroot.rules(),
UnionRule(FmtRequest, GofmtRequest),
UnionRule(FmtTargetsRequest, GofmtRequest),
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pants.backend.java.lint.google_java_format.skip_field import SkipGoogleJavaFormatField
from pants.backend.java.lint.google_java_format.subsystem import GoogleJavaFormatSubsystem
from pants.backend.java.target_types import JavaSourceField
from pants.core.goals.fmt import FmtRequest, FmtResult
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
from pants.core.goals.generate_lockfiles import GenerateToolLockfileSentinel
from pants.engine.fs import Digest
from pants.engine.internals.native_engine import Snapshot
Expand Down Expand Up @@ -36,7 +36,7 @@ def opt_out(cls, tgt: Target) -> bool:
return tgt.get(SkipGoogleJavaFormatField).value


class GoogleJavaFormatRequest(FmtRequest):
class GoogleJavaFormatRequest(FmtTargetsRequest):
field_set_type = GoogleJavaFormatFieldSet
name = GoogleJavaFormatSubsystem.options_scope

Expand Down Expand Up @@ -111,6 +111,6 @@ def rules():
return [
*collect_rules(),
*jvm_tool.rules(),
UnionRule(FmtRequest, GoogleJavaFormatRequest),
UnionRule(FmtTargetsRequest, GoogleJavaFormatRequest),
UnionRule(GenerateToolLockfileSentinel, GoogleJavaFormatToolLockfileSentinel),
]
6 changes: 3 additions & 3 deletions src/python/pants/backend/javascript/lint/prettier/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pants.backend.javascript.lint.prettier.subsystem import Prettier
from pants.backend.javascript.subsystems.nodejs import NpxProcess
from pants.backend.javascript.target_types import JSSourceField
from pants.core.goals.fmt import FmtRequest, FmtResult
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
from pants.core.util_rules.config_files import ConfigFiles, ConfigFilesRequest
from pants.engine.fs import Digest, MergeDigests, Snapshot
from pants.engine.process import ProcessResult
Expand All @@ -30,7 +30,7 @@ class PrettierFmtFieldSet(FieldSet):
sources: JSSourceField


class PrettierFmtRequest(FmtRequest):
class PrettierFmtRequest(FmtTargetsRequest):
field_set_type = PrettierFmtFieldSet
name = Prettier.options_scope

Expand Down Expand Up @@ -79,5 +79,5 @@ async def prettier_fmt(request: PrettierFmtRequest, prettier: Prettier) -> FmtRe
def rules() -> Iterable[Rule | UnionRule]:
return (
*collect_rules(),
UnionRule(FmtRequest, PrettierFmtRequest),
UnionRule(FmtTargetsRequest, PrettierFmtRequest),
)
6 changes: 3 additions & 3 deletions src/python/pants/backend/kotlin/lint/ktlint/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pants.backend.kotlin.lint.ktlint.skip_field import SkipKtlintField
from pants.backend.kotlin.lint.ktlint.subsystem import KtlintSubsystem
from pants.backend.kotlin.target_types import KotlinSourceField
from pants.core.goals.fmt import FmtRequest, FmtResult
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
from pants.core.goals.generate_lockfiles import GenerateToolLockfileSentinel
from pants.engine.fs import Digest
from pants.engine.internals.native_engine import Snapshot
Expand Down Expand Up @@ -36,7 +36,7 @@ def opt_out(cls, tgt: Target) -> bool:
return tgt.get(SkipKtlintField).value


class KtlintRequest(FmtRequest):
class KtlintRequest(FmtTargetsRequest):
field_set_type = KtlintFieldSet
name = KtlintSubsystem.options_scope

Expand Down Expand Up @@ -95,6 +95,6 @@ def rules():
return [
*collect_rules(),
*jvm_tool.rules(),
UnionRule(FmtRequest, KtlintRequest),
UnionRule(FmtTargetsRequest, KtlintRequest),
UnionRule(GenerateToolLockfileSentinel, KtlintToolLockfileSentinel),
]
6 changes: 3 additions & 3 deletions src/python/pants/backend/python/lint/autoflake/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pants.backend.python.target_types import PythonSourceField
from pants.backend.python.util_rules import pex
from pants.backend.python.util_rules.pex import PexRequest, VenvPex, VenvPexProcess
from pants.core.goals.fmt import FmtRequest, FmtResult
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
from pants.engine.fs import Digest
from pants.engine.internals.native_engine import Snapshot
from pants.engine.process import ProcessResult
Expand All @@ -30,7 +30,7 @@ def opt_out(cls, tgt: Target) -> bool:
return tgt.get(SkipAutoflakeField).value


class AutoflakeRequest(FmtRequest):
class AutoflakeRequest(FmtTargetsRequest):
field_set_type = AutoflakeFieldSet
name = Autoflake.options_scope

Expand Down Expand Up @@ -63,6 +63,6 @@ async def autoflake_fmt(request: AutoflakeRequest, autoflake: Autoflake) -> FmtR
def rules():
return [
*collect_rules(),
UnionRule(FmtRequest, AutoflakeRequest),
UnionRule(FmtTargetsRequest, AutoflakeRequest),
*pex.rules(),
]
6 changes: 3 additions & 3 deletions src/python/pants/backend/python/lint/black/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pants.backend.python.util_rules import pex
from pants.backend.python.util_rules.interpreter_constraints import InterpreterConstraints
from pants.backend.python.util_rules.pex import PexRequest, VenvPex, VenvPexProcess
from pants.core.goals.fmt import FmtRequest, FmtResult
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
from pants.core.util_rules.config_files import ConfigFiles, ConfigFilesRequest
from pants.engine.fs import Digest, MergeDigests
from pants.engine.internals.native_engine import Snapshot
Expand All @@ -34,7 +34,7 @@ def opt_out(cls, tgt: Target) -> bool:
return tgt.get(SkipBlackField).value


class BlackRequest(FmtRequest):
class BlackRequest(FmtTargetsRequest):
field_set_type = BlackFieldSet
name = Black.options_scope

Expand Down Expand Up @@ -113,6 +113,6 @@ async def black_fmt(request: BlackRequest, black: Black, python_setup: PythonSet
def rules():
return [
*collect_rules(),
UnionRule(FmtRequest, BlackRequest),
UnionRule(FmtTargetsRequest, BlackRequest),
*pex.rules(),
]
6 changes: 3 additions & 3 deletions src/python/pants/backend/python/lint/docformatter/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pants.backend.python.target_types import PythonSourceField
from pants.backend.python.util_rules import pex
from pants.backend.python.util_rules.pex import PexRequest, VenvPex, VenvPexProcess
from pants.core.goals.fmt import FmtRequest, FmtResult
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
from pants.engine.fs import Digest
from pants.engine.internals.native_engine import Snapshot
from pants.engine.process import ProcessResult
Expand All @@ -30,7 +30,7 @@ def opt_out(cls, tgt: Target) -> bool:
return tgt.get(SkipDocformatterField).value


class DocformatterRequest(FmtRequest):
class DocformatterRequest(FmtTargetsRequest):
field_set_type = DocformatterFieldSet
name = Docformatter.options_scope

Expand Down Expand Up @@ -62,6 +62,6 @@ async def docformatter_fmt(request: DocformatterRequest, docformatter: Docformat
def rules():
return [
*collect_rules(),
UnionRule(FmtRequest, DocformatterRequest),
UnionRule(FmtTargetsRequest, DocformatterRequest),
*pex.rules(),
]
6 changes: 3 additions & 3 deletions src/python/pants/backend/python/lint/isort/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pants.backend.python.target_types import PythonSourceField
from pants.backend.python.util_rules import pex
from pants.backend.python.util_rules.pex import PexRequest, PexResolveInfo, VenvPex, VenvPexProcess
from pants.core.goals.fmt import FmtRequest, FmtResult
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
from pants.core.util_rules.config_files import ConfigFiles, ConfigFilesRequest
from pants.engine.fs import Digest, MergeDigests
from pants.engine.internals.native_engine import Snapshot
Expand All @@ -33,7 +33,7 @@ def opt_out(cls, tgt: Target) -> bool:
return tgt.get(SkipIsortField).value


class IsortRequest(FmtRequest):
class IsortRequest(FmtTargetsRequest):
field_set_type = IsortFieldSet
name = Isort.options_scope

Expand Down Expand Up @@ -100,6 +100,6 @@ async def isort_fmt(request: IsortRequest, isort: Isort) -> FmtResult:
def rules():
return [
*collect_rules(),
UnionRule(FmtRequest, IsortRequest),
UnionRule(FmtTargetsRequest, IsortRequest),
*pex.rules(),
]
6 changes: 3 additions & 3 deletions src/python/pants/backend/python/lint/pyupgrade/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pants.backend.python.target_types import PythonSourceField
from pants.backend.python.util_rules import pex
from pants.backend.python.util_rules.pex import PexRequest, VenvPex, VenvPexProcess
from pants.core.goals.fmt import FmtRequest, FmtResult
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
from pants.engine.fs import Digest
from pants.engine.internals.native_engine import Snapshot
from pants.engine.process import FallibleProcessResult
Expand All @@ -31,7 +31,7 @@ def opt_out(cls, tgt: Target) -> bool:
return tgt.get(SkipPyUpgradeField).value


class PyUpgradeRequest(FmtRequest):
class PyUpgradeRequest(FmtTargetsRequest):
field_set_type = PyUpgradeFieldSet
name = PyUpgrade.options_scope

Expand Down Expand Up @@ -61,6 +61,6 @@ async def pyupgrade_fmt(request: PyUpgradeRequest, pyupgrade: PyUpgrade) -> FmtR
def rules():
return [
*collect_rules(),
UnionRule(FmtRequest, PyUpgradeRequest),
UnionRule(FmtTargetsRequest, PyUpgradeRequest),
*pex.rules(),
]
6 changes: 3 additions & 3 deletions src/python/pants/backend/python/lint/yapf/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pants.backend.python.target_types import PythonSourceField
from pants.backend.python.util_rules import pex
from pants.backend.python.util_rules.pex import PexRequest, VenvPex, VenvPexProcess
from pants.core.goals.fmt import FmtRequest, FmtResult
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
from pants.core.util_rules.config_files import ConfigFiles, ConfigFilesRequest
from pants.engine.fs import Digest, MergeDigests
from pants.engine.internals.native_engine import Snapshot
Expand All @@ -31,7 +31,7 @@ def opt_out(cls, tgt: Target) -> bool:
return tgt.get(SkipYapfField).value


class YapfRequest(FmtRequest):
class YapfRequest(FmtTargetsRequest):
field_set_type = YapfFieldSet
name = Yapf.options_scope

Expand Down Expand Up @@ -73,6 +73,6 @@ async def yapf_fmt(request: YapfRequest, yapf: Yapf) -> FmtResult:
def rules():
return [
*collect_rules(),
UnionRule(FmtRequest, YapfRequest),
UnionRule(FmtTargetsRequest, YapfRequest),
*pex.rules(),
]
6 changes: 3 additions & 3 deletions src/python/pants/backend/scala/lint/scalafmt/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pants.backend.scala.lint.scalafmt.subsystem import ScalafmtSubsystem
from pants.backend.scala.target_types import ScalaSourceField
from pants.base.glob_match_error_behavior import GlobMatchErrorBehavior
from pants.core.goals.fmt import FmtRequest, FmtResult
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
from pants.core.goals.generate_lockfiles import GenerateToolLockfileSentinel
from pants.core.goals.tailor import group_by_dir
from pants.engine.fs import (
Expand Down Expand Up @@ -49,7 +49,7 @@ def opt_out(cls, tgt: Target) -> bool:
return tgt.get(SkipScalafmtField).value


class ScalafmtRequest(FmtRequest):
class ScalafmtRequest(FmtTargetsRequest):
field_set_type = ScalafmtFieldSet
name = ScalafmtSubsystem.options_scope

Expand Down Expand Up @@ -276,6 +276,6 @@ def rules():
return [
*collect_rules(),
*lockfile.rules(),
UnionRule(FmtRequest, ScalafmtRequest),
UnionRule(FmtTargetsRequest, ScalafmtRequest),
UnionRule(GenerateToolLockfileSentinel, ScalafmtToolLockfileSentinel),
]
6 changes: 3 additions & 3 deletions src/python/pants/backend/shell/lint/shfmt/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pants.backend.shell.lint.shfmt.skip_field import SkipShfmtField
from pants.backend.shell.lint.shfmt.subsystem import Shfmt
from pants.backend.shell.target_types import ShellSourceField
from pants.core.goals.fmt import FmtRequest, FmtResult
from pants.core.goals.fmt import FmtResult, FmtTargetsRequest
from pants.core.util_rules.config_files import ConfigFiles, ConfigFilesRequest
from pants.core.util_rules.external_tool import DownloadedExternalTool, ExternalToolRequest
from pants.engine.fs import Digest, MergeDigests
Expand All @@ -31,7 +31,7 @@ def opt_out(cls, tgt: Target) -> bool:
return tgt.get(SkipShfmtField).value


class ShfmtRequest(FmtRequest):
class ShfmtRequest(FmtTargetsRequest):
field_set_type = ShfmtFieldSet
name = Shfmt.options_scope

Expand Down Expand Up @@ -81,5 +81,5 @@ async def shfmt_fmt(request: ShfmtRequest, shfmt: Shfmt) -> FmtResult:
def rules():
return [
*collect_rules(),
UnionRule(FmtRequest, ShfmtRequest),
UnionRule(FmtTargetsRequest, ShfmtRequest),
]
Loading

0 comments on commit 645b1ac

Please sign in to comment.