Skip to content

Commit

Permalink
Review feedback: call it Sources field still
Browse files Browse the repository at this point in the history
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
  • Loading branch information
Eric-Arellano committed Sep 26, 2021
1 parent a7abc52 commit 299ab17
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/python/pants/backend/shell/dependency_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from pants.backend.shell.lint.shellcheck.subsystem import Shellcheck
from pants.backend.shell.shell_setup import ShellSetup
from pants.backend.shell.target_types import ShellSourceField
from pants.backend.shell.target_types import ShellSourcesField
from pants.base.specs import AddressSpecs, DescendantAddresses
from pants.core.util_rules.external_tool import DownloadedExternalTool, ExternalToolRequest
from pants.engine.addresses import Address
Expand Down Expand Up @@ -53,9 +53,9 @@ class ShellMapping:
@rule(desc="Creating map of Shell file names to Shell targets", level=LogLevel.DEBUG)
async def map_shell_files() -> ShellMapping:
all_targets = await Get(Targets, AddressSpecs([DescendantAddresses("")]))
shell_tgts = tuple(tgt for tgt in all_targets if tgt.has_field(ShellSourceField))
shell_tgts = tuple(tgt for tgt in all_targets if tgt.has_field(ShellSourcesField))
sources_per_target = await MultiGet(
Get(SourcesPaths, SourcesPathsRequest(tgt[ShellSourceField])) for tgt in shell_tgts
Get(SourcesPaths, SourcesPathsRequest(tgt[ShellSourcesField])) for tgt in shell_tgts
)

files_to_addresses: dict[str, Address] = {}
Expand Down Expand Up @@ -153,7 +153,7 @@ async def parse_shell_imports(


class InferShellDependencies(InferDependenciesRequest):
infer_from = ShellSourceField
infer_from = ShellSourcesField


@rule(desc="Inferring Shell dependencies by analyzing imports")
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/shell/dependency_inference_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ParseShellImportsRequest,
ShellMapping,
)
from pants.backend.shell.target_types import ShellSourceField, ShellSourcesGeneratorTarget
from pants.backend.shell.target_types import ShellSourcesField, ShellSourcesGeneratorTarget
from pants.backend.shell.target_types import rules as target_types_rules
from pants.core.util_rules import external_tool
from pants.engine.addresses import Address
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_dependency_inference(rule_runner: RuleRunner, caplog) -> None:
def run_dep_inference(address: Address) -> InferredDependencies:
tgt = rule_runner.get_target(address)
return rule_runner.request(
InferredDependencies, [InferShellDependencies(tgt[ShellSourceField])]
InferredDependencies, [InferShellDependencies(tgt[ShellSourcesField])]
)

assert run_dep_inference(Address("a", relative_file_path="f1.sh")) == InferredDependencies(
Expand Down
6 changes: 3 additions & 3 deletions src/python/pants/backend/shell/lint/shell_fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dataclasses import dataclass
from typing import Iterable

from pants.backend.shell.target_types import ShellSourceField
from pants.backend.shell.target_types import ShellSourcesField
from pants.core.goals.fmt import FmtResult, LanguageFmtResults, LanguageFmtTargets
from pants.core.goals.style_request import StyleRequest
from pants.core.util_rules.source_files import SourceFiles, SourceFilesRequest
Expand All @@ -17,7 +17,7 @@

@dataclass(frozen=True)
class ShellFmtTargets(LanguageFmtTargets):
required_fields = (ShellSourceField,)
required_fields = (ShellSourcesField,)


@union
Expand All @@ -31,7 +31,7 @@ async def format_shell_targets(
) -> LanguageFmtResults:
original_sources = await Get(
SourceFiles,
SourceFilesRequest(target[ShellSourceField] for target in shell_fmt_targets.targets),
SourceFilesRequest(target[ShellSourcesField] for target in shell_fmt_targets.targets),
)
prior_formatter_result = original_sources.snapshot

Expand Down
10 changes: 5 additions & 5 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 ShellSourcesField
from pants.core.goals.lint import LintRequest, LintResult, LintResults
from pants.core.util_rules.config_files import ConfigFiles, ConfigFilesRequest
from pants.core.util_rules.external_tool import DownloadedExternalTool, ExternalToolRequest
Expand All @@ -29,9 +29,9 @@

@dataclass(frozen=True)
class ShellcheckFieldSet(FieldSet):
required_fields = (ShellSourceField,)
required_fields = (ShellSourcesField,)

sources: ShellSourceField
sources: ShellSourcesField
dependencies: Dependencies

@classmethod
Expand All @@ -58,15 +58,15 @@ async def run_shellcheck(request: ShellcheckRequest, shellcheck: Shellcheck) ->
SourceFiles,
SourceFilesRequest(
(field_set.sources for field_set in request.field_sets),
for_sources_types=(ShellSourceField,),
for_sources_types=(ShellSourcesField,),
enable_codegen=True,
),
)
dependency_sources_get = Get(
SourceFiles,
SourceFilesRequest(
(tgt.get(Sources) for dependencies in all_dependencies for tgt in dependencies),
for_sources_types=(ShellSourceField,),
for_sources_types=(ShellSourcesField,),
enable_codegen=True,
),
)
Expand Down
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.shell_fmt import ShellFmtRequest
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.backend.shell.target_types import ShellSourcesField
from pants.core.goals.fmt import FmtResult
from pants.core.goals.lint import LintRequest, LintResult, LintResults
from pants.core.util_rules.config_files import ConfigFiles, ConfigFilesRequest
Expand All @@ -24,9 +24,9 @@

@dataclass(frozen=True)
class ShfmtFieldSet(FieldSet):
required_fields = (ShellSourceField,)
required_fields = (ShellSourcesField,)

sources: ShellSourceField
sources: ShellSourcesField

@classmethod
def opt_out(cls, tgt: Target) -> bool:
Expand Down
10 changes: 5 additions & 5 deletions src/python/pants/backend/shell/shunit2_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

from pants.backend.shell.shell_setup import ShellSetup
from pants.backend.shell.target_types import (
ShellSourceField,
ShellSourcesField,
Shunit2Shell,
Shunit2ShellField,
Shunit2TestsGeneratorTarget,
Shunit2TestSourceField,
Shunit2TestSourcesField,
Shunit2TestTimeoutField,
)
from pants.core.goals.test import (
Expand Down Expand Up @@ -56,9 +56,9 @@

@dataclass(frozen=True)
class Shunit2FieldSet(TestFieldSet):
required_fields = (Shunit2TestSourceField,)
required_fields = (Shunit2TestSourcesField,)

sources: Shunit2TestSourceField
sources: Shunit2TestSourcesField
timeout: Shunit2TestTimeoutField
shell: Shunit2ShellField
runtime_package_dependencies: RuntimePackageDependenciesField
Expand Down Expand Up @@ -172,7 +172,7 @@ async def setup_shunit2_for_target(
SourceFiles,
SourceFilesRequest(
(tgt.get(Sources) for tgt in transitive_targets.dependencies),
for_sources_types=(ShellSourceField, FilesSources, ResourcesSources),
for_sources_types=(ShellSourcesField, FilesSources, ResourcesSources),
enable_codegen=True,
),
)
Expand Down
8 changes: 4 additions & 4 deletions src/python/pants/backend/shell/target_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from pants.util.enums import match


class ShellSourceField(Sources):
class ShellSourcesField(Sources):
# Normally, we would add `expected_file_extensions = ('.sh',)`, but Bash scripts don't need a
# file extension, so we don't use this.
uses_source_roots = False
Expand Down Expand Up @@ -113,7 +113,7 @@ def compute_value(cls, raw_value: Optional[int], address: Address) -> Optional[i
return value


class Shunit2TestSourceField(ShellSourceField):
class Shunit2TestSourcesField(ShellSourcesField):
pass


Expand All @@ -127,7 +127,7 @@ class Shunit2TestTarget(Target):
alias = "shunit2_tests" # TODO(#12954): rename to `shunit_test` when ready. Update `help` too.
core_fields = (
*COMMON_TARGET_FIELDS,
Shunit2TestSourceField,
Shunit2TestSourcesField,
Shunit2TestDependenciesField,
Shunit2TestTimeoutField,
Shunit2ShellField,
Expand Down Expand Up @@ -196,7 +196,7 @@ async def generate_targets_from_shunit2_tests(

class ShellSourceTarget(Target):
alias = "shell_library" # TODO(#12954): rename to `shell_source` when ready.
core_fields = (*COMMON_TARGET_FIELDS, Dependencies, ShellSourceField)
core_fields = (*COMMON_TARGET_FIELDS, Dependencies, ShellSourcesField)
help = "A Bourne-based shell script, e.g. a Bash script."


Expand Down

0 comments on commit 299ab17

Please sign in to comment.