Skip to content
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

GenerateToolLockfileSentinel encouraged to use language-specific subclasses #16449

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -45,6 +45,19 @@ likely include the relevant `Dependencies` subclass. Likewise for pre-2.14 `Infe
Note that in most cases, you no longer need to request the target in your rule code, and should rely
on `FieldSet`'s mechanisms for matching targets and getting field values.

### `GenerateToolLockfileSentinel` encouraged to use language-specific subclasses

Rather than directly subclassing `GenerateToolLockfileSentinel`, we encourage you to subclass
`GeneratePythonToolLockfileSentinel` and `GenerateJvmToolLockfileSentinel`. This is so that we can
distinguish what language a tool belongs to, which is used for options like
`[python].resolves_to_constraints_file` to validate which resolve names are recognized.

Things will still work if you do not make this change, other than the new options not recognizing
your tool.

However, keep the `UnionRule` the same, i.e. with the first argument still
`GenerateToolLockfileSentinel`.

2.13
----

Expand Down
7 changes: 5 additions & 2 deletions src/python/pants/backend/cc/lint/clangformat/subsystem.py
Expand Up @@ -8,7 +8,10 @@

from pants.backend.python.goals import lockfile
from pants.backend.python.goals.export import ExportPythonTool, ExportPythonToolSentinel
from pants.backend.python.goals.lockfile import GeneratePythonLockfile
from pants.backend.python.goals.lockfile import (
GeneratePythonLockfile,
GeneratePythonToolLockfileSentinel,
)
from pants.backend.python.subsystems.python_tool_base import ExportToolOption, PythonToolBase
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.target_types import ConsoleScript
Expand Down Expand Up @@ -62,7 +65,7 @@ def config_request(self, dirs: Iterable[str]) -> ConfigFilesRequest:
)


class ClangFormatLockfileSentinel(GenerateToolLockfileSentinel):
class ClangFormatLockfileSentinel(GeneratePythonToolLockfileSentinel):
resolve_name = ClangFormat.options_scope


Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/codegen/avro/java/rules.py
Expand Up @@ -53,7 +53,7 @@
from pants.jvm.jdk_rules import InternalJdk, JvmProcess
from pants.jvm.resolve import jvm_tool
from pants.jvm.resolve.coursier_fetch import ToolClasspath, ToolClasspathRequest
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool, GenerateJvmToolLockfileSentinel
from pants.jvm.subsystems import JvmSubsystem
from pants.jvm.target_types import JvmResolveField, PrefixedJvmJdkField, PrefixedJvmResolveField
from pants.source.source_root import SourceRoot, SourceRootRequest
Expand All @@ -66,7 +66,7 @@ class GenerateJavaFromAvroRequest(GenerateSourcesRequest):
output = JavaSourceField


class AvroToolLockfileSentinel(GenerateToolLockfileSentinel):
class AvroToolLockfileSentinel(GenerateJvmToolLockfileSentinel):
resolve_name = AvroSubsystem.options_scope


Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/codegen/protobuf/java/rules.py
Expand Up @@ -42,7 +42,7 @@
)
from pants.engine.unions import UnionRule
from pants.jvm.resolve.coursier_fetch import ToolClasspath, ToolClasspathRequest
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool, GenerateJvmToolLockfileSentinel
from pants.jvm.target_types import PrefixedJvmJdkField, PrefixedJvmResolveField
from pants.source.source_root import SourceRoot, SourceRootRequest
from pants.util.logging import LogLevel
Expand All @@ -53,7 +53,7 @@ class GenerateJavaFromProtobufRequest(GenerateSourcesRequest):
output = JavaSourceField


class GrpcJavaToolLockfileSentinel(GenerateToolLockfileSentinel):
class GrpcJavaToolLockfileSentinel(GenerateJvmToolLockfileSentinel):
resolve_name = JavaProtobufGrpcSubsystem.options_scope


Expand Down
Expand Up @@ -11,7 +11,10 @@
from pants.backend.codegen.utils import find_python_runtime_library_or_raise_error
from pants.backend.python.dependency_inference.module_mapper import ThirdPartyPythonModuleMapping
from pants.backend.python.goals import lockfile
from pants.backend.python.goals.lockfile import GeneratePythonLockfile
from pants.backend.python.goals.lockfile import (
GeneratePythonLockfile,
GeneratePythonToolLockfileSentinel,
)
from pants.backend.python.subsystems.python_tool_base import PythonToolRequirementsBase
from pants.backend.python.subsystems.setup import PythonSetup
from pants.core.goals.generate_lockfiles import GenerateToolLockfileSentinel
Expand Down Expand Up @@ -86,7 +89,7 @@ class PythonProtobufMypyPlugin(PythonToolRequirementsBase):
default_lockfile_url = git_url(default_lockfile_path)


class MypyProtobufLockfileSentinel(GenerateToolLockfileSentinel):
class MypyProtobufLockfileSentinel(GeneratePythonToolLockfileSentinel):
resolve_name = PythonProtobufMypyPlugin.options_scope


Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/codegen/protobuf/scala/rules.py
Expand Up @@ -50,7 +50,7 @@
from pants.jvm.jdk_rules import InternalJdk, JvmProcess
from pants.jvm.resolve.common import ArtifactRequirements, Coordinate, GatherJvmCoordinatesRequest
from pants.jvm.resolve.coursier_fetch import ToolClasspath, ToolClasspathRequest
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool, GenerateJvmToolLockfileSentinel
from pants.jvm.target_types import PrefixedJvmJdkField, PrefixedJvmResolveField
from pants.source.source_root import SourceRoot, SourceRootRequest
from pants.util.logging import LogLevel
Expand All @@ -62,7 +62,7 @@ class GenerateScalaFromProtobufRequest(GenerateSourcesRequest):
output = ScalaSourceField


class ScalapbcToolLockfileSentinel(GenerateToolLockfileSentinel):
class ScalapbcToolLockfileSentinel(GenerateJvmToolLockfileSentinel):
resolve_name = ScalaPBSubsystem.options_scope


Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/codegen/soap/java/rules.py
Expand Up @@ -41,7 +41,7 @@
from pants.jvm.jdk_rules import InternalJdk, JvmProcess
from pants.jvm.resolve import jvm_tool
from pants.jvm.resolve.coursier_fetch import ToolClasspath, ToolClasspathRequest
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool, GenerateJvmToolLockfileSentinel
from pants.jvm.target_types import PrefixedJvmJdkField, PrefixedJvmResolveField
from pants.source.source_root import SourceRoot, SourceRootRequest
from pants.util.logging import LogLevel
Expand All @@ -52,7 +52,7 @@ class GenerateJavaFromWsdlRequest(GenerateSourcesRequest):
output = JavaSourceField


class JaxWsToolsLockfileSentinel(GenerateToolLockfileSentinel):
class JaxWsToolsLockfileSentinel(GenerateJvmToolLockfileSentinel):
resolve_name = JaxWsTools.options_scope


Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/codegen/thrift/scrooge/rules.py
Expand Up @@ -26,7 +26,7 @@
from pants.jvm.goals import lockfile
from pants.jvm.jdk_rules import InternalJdk, JvmProcess
from pants.jvm.resolve.coursier_fetch import ToolClasspath, ToolClasspathRequest
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool, GenerateJvmToolLockfileSentinel
from pants.jvm.target_types import PrefixedJvmJdkField, PrefixedJvmResolveField
from pants.source.source_root import SourceRootsRequest, SourceRootsResult
from pants.util.logging import LogLevel
Expand All @@ -44,7 +44,7 @@ class GeneratedScroogeThriftSources:
snapshot: Snapshot


class ScroogeToolLockfileSentinel(GenerateToolLockfileSentinel):
class ScroogeToolLockfileSentinel(GenerateJvmToolLockfileSentinel):
resolve_name = ScroogeSubsystem.options_scope


Expand Down
Expand Up @@ -11,7 +11,10 @@
from pants.backend.docker.target_types import DockerImageSourceField
from pants.backend.docker.util_rules.docker_build_args import DockerBuildArgs
from pants.backend.python.goals import lockfile
from pants.backend.python.goals.lockfile import GeneratePythonLockfile
from pants.backend.python.goals.lockfile import (
GeneratePythonLockfile,
GeneratePythonToolLockfileSentinel,
)
from pants.backend.python.subsystems.python_tool_base import PythonToolRequirementsBase
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.target_types import EntryPoint
Expand Down Expand Up @@ -52,7 +55,7 @@ class DockerfileParser(PythonToolRequirementsBase):
default_lockfile_url = git_url(default_lockfile_path)


class DockerfileParserLockfileSentinel(GenerateToolLockfileSentinel):
class DockerfileParserLockfileSentinel(GeneratePythonToolLockfileSentinel):
resolve_name = DockerfileParser.options_scope


Expand Down
Expand Up @@ -20,7 +20,7 @@
from pants.engine.unions import UnionRule
from pants.jvm.jdk_rules import InternalJdk, JvmProcess
from pants.jvm.resolve.coursier_fetch import ToolClasspath, ToolClasspathRequest
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool, GenerateJvmToolLockfileSentinel
from pants.option.global_options import KeepSandboxes
from pants.util.logging import LogLevel
from pants.util.ordered_set import FrozenOrderedSet
Expand All @@ -31,7 +31,7 @@
_LAUNCHER_BASENAME = "PantsJavaParserLauncher.java"


class JavaParserToolLockfileSentinel(GenerateToolLockfileSentinel):
class JavaParserToolLockfileSentinel(GenerateJvmToolLockfileSentinel):
resolve_name = "java-parser"


Expand Down
Expand Up @@ -18,7 +18,7 @@
from pants.jvm.jdk_rules import InternalJdk, JvmProcess
from pants.jvm.resolve import jvm_tool
from pants.jvm.resolve.coursier_fetch import ToolClasspath, ToolClasspathRequest
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool, GenerateJvmToolLockfileSentinel
from pants.util.logging import LogLevel
from pants.util.strutil import pluralize

Expand All @@ -41,7 +41,7 @@ class GoogleJavaFormatRequest(FmtRequest):
name = GoogleJavaFormatSubsystem.options_scope


class GoogleJavaFormatToolLockfileSentinel(GenerateToolLockfileSentinel):
class GoogleJavaFormatToolLockfileSentinel(GenerateJvmToolLockfileSentinel):
resolve_name = GoogleJavaFormatSubsystem.options_scope


Expand Down
Expand Up @@ -20,7 +20,7 @@
from pants.jvm.jdk_rules import InternalJdk, JdkEnvironment, JdkRequest, JvmProcess
from pants.jvm.resolve.common import ArtifactRequirements, Coordinate
from pants.jvm.resolve.coursier_fetch import ToolClasspath, ToolClasspathRequest
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool, GenerateJvmToolLockfileSentinel
from pants.option.global_options import KeepSandboxes
from pants.util.frozendict import FrozenDict
from pants.util.logging import LogLevel
Expand All @@ -29,7 +29,7 @@
_PARSER_KOTLIN_VERSION = "1.6.20"


class KotlinParserToolLockfileSentinel(GenerateToolLockfileSentinel):
class KotlinParserToolLockfileSentinel(GenerateJvmToolLockfileSentinel):
resolve_name = "kotlin-parser"


Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/kotlin/lint/ktlint/rules.py
Expand Up @@ -18,7 +18,7 @@
from pants.jvm.jdk_rules import InternalJdk, JvmProcess
from pants.jvm.resolve import jvm_tool
from pants.jvm.resolve.coursier_fetch import ToolClasspath, ToolClasspathRequest
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool, GenerateJvmToolLockfileSentinel
from pants.util.logging import LogLevel
from pants.util.strutil import pluralize

Expand All @@ -41,7 +41,7 @@ class KtlintRequest(FmtRequest):
name = KtlintSubsystem.options_scope


class KtlintToolLockfileSentinel(GenerateToolLockfileSentinel):
class KtlintToolLockfileSentinel(GenerateJvmToolLockfileSentinel):
resolve_name = KtlintSubsystem.options_scope


Expand Down
7 changes: 5 additions & 2 deletions src/python/pants/backend/python/goals/coverage_py.py
Expand Up @@ -13,7 +13,10 @@
import toml

from pants.backend.python.goals import lockfile
from pants.backend.python.goals.lockfile import GeneratePythonLockfile
from pants.backend.python.goals.lockfile import (
GeneratePythonLockfile,
GeneratePythonToolLockfileSentinel,
)
from pants.backend.python.subsystems.python_tool_base import PythonToolBase
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.target_types import ConsoleScript
Expand Down Expand Up @@ -226,7 +229,7 @@ def config_request(self) -> ConfigFilesRequest:
)


class CoveragePyLockfileSentinel(GenerateToolLockfileSentinel):
class CoveragePyLockfileSentinel(GeneratePythonToolLockfileSentinel):
resolve_name = CoverageSubsystem.options_scope


Expand Down
3 changes: 3 additions & 0 deletions src/python/pants/backend/python/goals/lockfile.py
Expand Up @@ -27,6 +27,9 @@
from pants.backend.python.util_rules.lockfile_metadata import PythonLockfileMetadata
from pants.backend.python.util_rules.pex import PexRequest, VenvPex, VenvPexProcess
from pants.backend.python.util_rules.pex_cli import PexCliProcess
from pants.backend.python.util_rules.pex_requirements import ( # noqa: F401
GeneratePythonToolLockfileSentinel as GeneratePythonToolLockfileSentinel,
)
from pants.backend.python.util_rules.pex_requirements import (
PexRequirements,
ResolvePexConfig,
Expand Down
7 changes: 5 additions & 2 deletions src/python/pants/backend/python/lint/autoflake/subsystem.py
Expand Up @@ -5,7 +5,10 @@

from pants.backend.python.goals import lockfile
from pants.backend.python.goals.export import ExportPythonTool, ExportPythonToolSentinel
from pants.backend.python.goals.lockfile import GeneratePythonLockfile
from pants.backend.python.goals.lockfile import (
GeneratePythonLockfile,
GeneratePythonToolLockfileSentinel,
)
from pants.backend.python.subsystems.python_tool_base import ExportToolOption, PythonToolBase
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.target_types import ConsoleScript
Expand Down Expand Up @@ -43,7 +46,7 @@ class Autoflake(PythonToolBase):
export = ExportToolOption()


class AutoflakeLockfileSentinel(GenerateToolLockfileSentinel):
class AutoflakeLockfileSentinel(GeneratePythonToolLockfileSentinel):
resolve_name = Autoflake.options_scope


Expand Down
7 changes: 5 additions & 2 deletions src/python/pants/backend/python/lint/bandit/subsystem.py
Expand Up @@ -8,7 +8,10 @@

from pants.backend.python.goals import lockfile
from pants.backend.python.goals.export import ExportPythonTool, ExportPythonToolSentinel
from pants.backend.python.goals.lockfile import GeneratePythonLockfile
from pants.backend.python.goals.lockfile import (
GeneratePythonLockfile,
GeneratePythonToolLockfileSentinel,
)
from pants.backend.python.lint.bandit.skip_field import SkipBanditField
from pants.backend.python.subsystems.python_tool_base import ExportToolOption, PythonToolBase
from pants.backend.python.subsystems.setup import PythonSetup
Expand Down Expand Up @@ -100,7 +103,7 @@ async def _bandit_interpreter_constraints(python_setup: PythonSetup) -> Interpre
return constraints or InterpreterConstraints(python_setup.interpreter_constraints)


class BanditLockfileSentinel(GenerateToolLockfileSentinel):
class BanditLockfileSentinel(GeneratePythonToolLockfileSentinel):
resolve_name = Bandit.options_scope


Expand Down
7 changes: 5 additions & 2 deletions src/python/pants/backend/python/lint/black/subsystem.py
Expand Up @@ -8,7 +8,10 @@

from pants.backend.python.goals import lockfile
from pants.backend.python.goals.export import ExportPythonTool, ExportPythonToolSentinel
from pants.backend.python.goals.lockfile import GeneratePythonLockfile
from pants.backend.python.goals.lockfile import (
GeneratePythonLockfile,
GeneratePythonToolLockfileSentinel,
)
from pants.backend.python.lint.black.skip_field import SkipBlackField
from pants.backend.python.subsystems.python_tool_base import ExportToolOption, PythonToolBase
from pants.backend.python.subsystems.setup import PythonSetup
Expand Down Expand Up @@ -101,7 +104,7 @@ async def _black_interpreter_constraints(
return constraints


class BlackLockfileSentinel(GenerateToolLockfileSentinel):
class BlackLockfileSentinel(GeneratePythonToolLockfileSentinel):
resolve_name = Black.options_scope


Expand Down
Expand Up @@ -4,7 +4,10 @@

from pants.backend.python.goals import lockfile
from pants.backend.python.goals.export import ExportPythonTool, ExportPythonToolSentinel
from pants.backend.python.goals.lockfile import GeneratePythonLockfile
from pants.backend.python.goals.lockfile import (
GeneratePythonLockfile,
GeneratePythonToolLockfileSentinel,
)
from pants.backend.python.subsystems.python_tool_base import ExportToolOption, PythonToolBase
from pants.backend.python.subsystems.setup import PythonSetup
from pants.backend.python.target_types import ConsoleScript
Expand Down Expand Up @@ -36,7 +39,7 @@ class Docformatter(PythonToolBase):
export = ExportToolOption()


class DocformatterLockfileSentinel(GenerateToolLockfileSentinel):
class DocformatterLockfileSentinel(GeneratePythonToolLockfileSentinel):
resolve_name = Docformatter.options_scope


Expand Down
7 changes: 5 additions & 2 deletions src/python/pants/backend/python/lint/flake8/subsystem.py
Expand Up @@ -8,7 +8,10 @@

from pants.backend.python.goals import lockfile
from pants.backend.python.goals.export import ExportPythonTool, ExportPythonToolSentinel
from pants.backend.python.goals.lockfile import GeneratePythonLockfile
from pants.backend.python.goals.lockfile import (
GeneratePythonLockfile,
GeneratePythonToolLockfileSentinel,
)
from pants.backend.python.lint.flake8.skip_field import SkipFlake8Field
from pants.backend.python.subsystems.python_tool_base import ExportToolOption, PythonToolBase
from pants.backend.python.subsystems.setup import PythonSetup
Expand Down Expand Up @@ -269,7 +272,7 @@ async def _flake8_interpreter_constraints(
# --------------------------------------------------------------------------------------


class Flake8LockfileSentinel(GenerateToolLockfileSentinel):
class Flake8LockfileSentinel(GeneratePythonToolLockfileSentinel):
resolve_name = Flake8.options_scope


Expand Down