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

Pants internally uses dedicated Sources and Dependencies fields #16037

Merged
merged 5 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/python/pants/backend/cc/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
CC_FILE_EXTENSIONS = (".c", ".h", ".cc", ".cpp", ".hpp")


class CCDependenciesField(Dependencies):
pass


class CCSourceField(SingleSourceField):
expected_file_extensions = CC_FILE_EXTENSIONS

Expand Down Expand Up @@ -51,7 +55,7 @@ class CCSourceTarget(Target):
alias = "cc_source"
core_fields = (
*COMMON_TARGET_FIELDS,
Dependencies,
CCDependenciesField,
CCSourceField,
)
help = "A single C/C++ source file or header file."
Expand Down
2 changes: 0 additions & 2 deletions src/python/pants/backend/codegen/avro/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from pants.util.strutil import softwrap


# NB: We subclass Dependencies so that specific backends can add dependency injection rules to
# `avro_source` targets.
class AvroDependenciesField(Dependencies):
pass

Expand Down
2 changes: 0 additions & 2 deletions src/python/pants/backend/codegen/protobuf/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
from pants.util.strutil import softwrap


# NB: We subclass Dependencies so that specific backends can add dependency injection rules to
# `protobuf_source` targets.
class ProtobufDependenciesField(Dependencies):
pass

Expand Down
2 changes: 0 additions & 2 deletions src/python/pants/backend/codegen/thrift/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
from pants.util.strutil import softwrap


# NB: We subclass Dependencies so that specific backends can add dependency injection rules to
# `thrift_source` targets.
class ThriftDependenciesField(Dependencies):
pass

Expand Down
10 changes: 5 additions & 5 deletions src/python/pants/backend/java/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pants.engine.rules import collect_rules
from pants.engine.target import (
COMMON_TARGET_FIELDS,
Dependencies,
FieldSet,
MultipleSourcesField,
SingleSourceField,
Expand All @@ -18,6 +17,7 @@
)
from pants.jvm.target_types import (
JunitTestSourceField,
JvmDependenciesField,
JvmJdkField,
JvmProvidesTypesField,
JvmResolveField,
Expand Down Expand Up @@ -60,7 +60,7 @@ class JunitTestTarget(Target):
core_fields = (
*COMMON_TARGET_FIELDS,
JavaJunitTestSourceField,
Dependencies,
JvmDependenciesField,
JvmResolveField,
JvmProvidesTypesField,
JvmJdkField,
Expand All @@ -84,7 +84,7 @@ class JunitTestsGeneratorTarget(TargetFilesGenerator):
generated_target_cls = JunitTestTarget
copied_fields = COMMON_TARGET_FIELDS
moved_fields = (
Dependencies,
JvmDependenciesField,
JvmJdkField,
JvmProvidesTypesField,
JvmResolveField,
Expand All @@ -101,7 +101,7 @@ class JavaSourceTarget(Target):
alias = "java_source"
core_fields = (
*COMMON_TARGET_FIELDS,
Dependencies,
JvmDependenciesField,
JavaSourceField,
JvmResolveField,
JvmProvidesTypesField,
Expand All @@ -126,7 +126,7 @@ class JavaSourcesGeneratorTarget(TargetFilesGenerator):
generated_target_cls = JavaSourceTarget
copied_fields = COMMON_TARGET_FIELDS
moved_fields = (
Dependencies,
JvmDependenciesField,
JvmResolveField,
JvmJdkField,
JvmProvidesTypesField,
Expand Down
8 changes: 6 additions & 2 deletions src/python/pants/backend/javascript/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
JS_FILE_EXTENSIONS = (".js",)


class JSDependenciesField(Dependencies):
pass


class JSSourceField(SingleSourceField):
expected_file_extensions = JS_FILE_EXTENSIONS

Expand All @@ -32,7 +36,7 @@ class JSSourceTarget(Target):
alias = "javascript_source"
core_fields = (
*COMMON_TARGET_FIELDS,
Dependencies,
JSDependenciesField,
JSSourceField,
)
help = "A single Javascript source file."
Expand All @@ -50,5 +54,5 @@ class JSSourcesGeneratorTarget(TargetFilesGenerator):
)
generated_target_cls = JSSourceTarget
copied_fields = COMMON_TARGET_FIELDS
moved_fields = (Dependencies,)
moved_fields = (JSDependenciesField,)
help = "Generate a `javascript_source` target for each file in the `sources` field."
6 changes: 5 additions & 1 deletion src/python/pants/backend/project_info/dependees_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ class SpecialDeps(SpecialCasedDependencies):
alias = "special_deps"


class MockDepsField(Dependencies):
pass


class MockTarget(Target):
alias = "tgt"
core_fields = (Dependencies, SpecialDeps)
core_fields = (MockDepsField, SpecialDeps)


@pytest.fixture
Expand Down
8 changes: 6 additions & 2 deletions src/python/pants/backend/project_info/filedeps_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ class MockSources(MultipleSourcesField):
default = ("*.ext",)


class MockDepsField(Dependencies):
pass


class MockTarget(Target):
alias = "tgt"
core_fields = (MockSources, Dependencies)
core_fields = (MockSources, MockDepsField)


class MockSingleSourceField(SingleSourceField):
Expand All @@ -26,7 +30,7 @@ class MockSingleSourceField(SingleSourceField):

class MockSingleSourceTarget(Target):
alias = "single_source"
core_fields = (MockSingleSourceField, Dependencies)
core_fields = (MockSingleSourceField, MockDepsField)


@pytest.fixture
Expand Down
12 changes: 10 additions & 2 deletions src/python/pants/backend/project_info/filter_targets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,23 @@ class MockTarget(Target):
deprecated_alias_removal_version = "99.9.0.dev0"


class MockSingleSourceField(SingleSourceField):
pass


class MockGeneratedFileTarget(Target):
alias = "file_generated"
core_fields = (SingleSourceField, Tags)
core_fields = (MockSingleSourceField, Tags)


class MockMultipleSourcesField(MultipleSourcesField):
pass


class MockFileTargetGenerator(TargetFilesGenerator):
alias = "file_generator"
generated_target_cls = MockGeneratedFileTarget
core_fields = (MultipleSourcesField, Tags)
core_fields = (MockMultipleSourcesField, Tags)
copied_fields = (Tags,)
moved_fields = ()

Expand Down
6 changes: 5 additions & 1 deletion src/python/pants/backend/project_info/paths_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ class MockSourceField(OptionalSingleSourceField):
expected_file_extensions: ClassVar[tuple[str, ...]] = (".txt",)


class MockDepsField(Dependencies):
pass


class MockTarget(Target):
alias = "tgt"
core_fields = (
MockSourceField,
Dependencies,
MockDepsField,
)


Expand Down
16 changes: 12 additions & 4 deletions src/python/pants/backend/python/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class PythonSourceField(SingleSourceField):
expected_file_extensions: ClassVar[tuple[str, ...]] = ("", ".py", ".pyi")


class PythonDependenciesField(Dependencies):
pass


class PythonGeneratingSourcesBase(MultipleSourcesField):
expected_file_extensions: ClassVar[tuple[str, ...]] = ("", ".py", ".pyi")

Expand Down Expand Up @@ -930,7 +934,7 @@ class PythonSourceTarget(Target):
core_fields = (
*COMMON_TARGET_FIELDS,
InterpreterConstraintsField,
Dependencies,
PythonDependenciesField,
PythonResolveField,
PythonRunGoalUseSandboxField,
PythonSourceField,
Expand Down Expand Up @@ -982,7 +986,7 @@ class PythonTestUtilsGeneratorTarget(TargetFilesGenerator):
moved_fields = (
PythonResolveField,
PythonRunGoalUseSandboxField,
Dependencies,
PythonDependenciesField,
InterpreterConstraintsField,
)
settings_request_cls = PythonFilesGeneratorSettingsRequest
Expand Down Expand Up @@ -1013,7 +1017,7 @@ class PythonSourcesGeneratorTarget(TargetFilesGenerator):
moved_fields = (
PythonResolveField,
PythonRunGoalUseSandboxField,
Dependencies,
PythonDependenciesField,
InterpreterConstraintsField,
)
settings_request_cls = PythonFilesGeneratorSettingsRequest
Expand Down Expand Up @@ -1070,6 +1074,10 @@ def compute_value(
return tuple(result)


class PythonRequirementDependenciesField(Dependencies):
pass


class PythonRequirementsField(_PipRequirementSequenceField):
alias = "requirements"
required = True
Expand Down Expand Up @@ -1161,8 +1169,8 @@ class PythonRequirementTarget(Target):
alias = "python_requirement"
core_fields = (
*COMMON_TARGET_FIELDS,
Dependencies,
PythonRequirementsField,
PythonRequirementDependenciesField,
PythonRequirementModulesField,
PythonRequirementTypeStubModulesField,
PythonRequirementResolveField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ class PythonTarget(Target):
core_fields = (PythonSourceField,)


class NonPythonSourceField(SingleSourceField):
pass


class NonPythonTarget(Target):
alias = "non_python_target"
core_fields = (SingleSourceField,)
core_fields = (NonPythonSourceField,)


@pytest.fixture
Expand Down
11 changes: 3 additions & 8 deletions src/python/pants/backend/scala/test/scalatest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,15 @@
ProcessCacheScope,
)
from pants.engine.rules import Get, MultiGet, collect_rules, rule
from pants.engine.target import (
Dependencies,
SourcesField,
TransitiveTargets,
TransitiveTargetsRequest,
)
from pants.engine.target import SourcesField, TransitiveTargets, TransitiveTargetsRequest
from pants.engine.unions import UnionRule
from pants.jvm.classpath import Classpath
from pants.jvm.goals import lockfile
from pants.jvm.jdk_rules import JdkEnvironment, JdkRequest, JvmProcess
from pants.jvm.resolve.coursier_fetch import ToolClasspath, ToolClasspathRequest
from pants.jvm.resolve.jvm_tool import GenerateJvmLockfileFromTool
from pants.jvm.subsystems import JvmSubsystem
from pants.jvm.target_types import JvmJdkField
from pants.jvm.target_types import JvmDependenciesField, JvmJdkField
from pants.util.logging import LogLevel

logger = logging.getLogger(__name__)
Expand All @@ -55,7 +50,7 @@ class ScalatestTestFieldSet(TestFieldSet):

sources: ScalatestTestSourceField
jdk_version: JvmJdkField
dependencies: Dependencies
dependencies: JvmDependenciesField


class ScalatestToolLockfileSentinel(GenerateToolLockfileSentinel):
Expand Down
13 changes: 3 additions & 10 deletions src/python/pants/backend/shell/lint/shellcheck/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pants.backend.shell.lint.shellcheck.skip_field import SkipShellcheckField
from pants.backend.shell.lint.shellcheck.subsystem import Shellcheck
from pants.backend.shell.target_types import ShellSourceField
from pants.backend.shell.target_types import ShellDependenciesField, ShellSourceField
from pants.core.goals.lint import LintResult, LintResults, LintTargetsRequest
from pants.core.util_rules.config_files import ConfigFiles, ConfigFilesRequest
from pants.core.util_rules.external_tool import DownloadedExternalTool, ExternalToolRequest
Expand All @@ -14,14 +14,7 @@
from pants.engine.platform import Platform
from pants.engine.process import FallibleProcessResult, Process
from pants.engine.rules import Get, MultiGet, collect_rules, rule
from pants.engine.target import (
Dependencies,
DependenciesRequest,
FieldSet,
SourcesField,
Target,
Targets,
)
from pants.engine.target import DependenciesRequest, FieldSet, SourcesField, Target, Targets
from pants.engine.unions import UnionRule
from pants.util.logging import LogLevel
from pants.util.strutil import pluralize
Expand All @@ -32,7 +25,7 @@ class ShellcheckFieldSet(FieldSet):
required_fields = (ShellSourceField,)

sources: ShellSourceField
dependencies: Dependencies
dependencies: ShellDependenciesField

@classmethod
def opt_out(cls, tgt: Target) -> bool:
Expand Down
Loading