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

Remove leftover v1 Target API bindings #10276

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
9 changes: 0 additions & 9 deletions examples/tests/python/example_test/hello/greet/BUILD
Expand Up @@ -6,14 +6,5 @@
python_tests(
dependencies=[
'examples/src/python/example/hello/greet:greet',
':prep',
],
)

# Prepare for the 'greet' test. Realistically, you wouldn't set up a
# prep_command just to create an empty temp file. This is meant as a
# simple example.
prep_command(name='prep',
prep_executable='touch',
prep_args=['/tmp/prep_command_result']
)
16 changes: 2 additions & 14 deletions src/python/pants/backend/pants_info/list_target_types.py
Expand Up @@ -54,15 +54,10 @@ class TargetTypes(Goal):
class AbbreviatedTargetInfo:
alias: str
description: Optional[str]
v1_only: bool

@classmethod
def create(cls, target_type: Type[Target]) -> "AbbreviatedTargetInfo":
return cls(
alias=target_type.alias,
description=get_docstring_summary(target_type),
v1_only=target_type.v1_only,
)
return cls(alias=target_type.alias, description=get_docstring_summary(target_type))

def format_for_cli(self, console: Console, *, longest_target_alias: int) -> str:
chars_before_description = longest_target_alias + 2
Expand All @@ -87,7 +82,6 @@ class FieldInfo:
type_hint: str
required: bool
default: Optional[str]
v1_only: bool

@classmethod
def create(cls, field: Type[Field]) -> "FieldInfo":
Expand Down Expand Up @@ -155,7 +149,6 @@ def create(cls, field: Type[Field]) -> "FieldInfo":
type_hint=type_hint,
required=field.required,
default=repr(field.default) if not field.required else None,
v1_only=field.v1_only,
)

def format_for_cli(self, console: Console) -> str:
Expand Down Expand Up @@ -195,11 +188,7 @@ def format_for_cli(self, console: Console, *, v1_disabled: bool) -> str:
output.extend(
[
"Valid fields:\n",
*sorted(
f"{field.format_for_cli(console)}\n"
for field in self.fields
if not field.alias.startswith("_") and (not v1_disabled or not field.v1_only)
),
*sorted(f"{field.format_for_cli(console)}\n" for field in self.fields),
]
)
return "\n".join(output).rstrip()
Expand Down Expand Up @@ -250,7 +239,6 @@ def list_target_types(
target_info.format_for_cli(console, longest_target_alias=longest_target_alias)
for target_info in target_infos
if not target_info.alias.startswith("_")
and (not v1_disabled or not target_info.v1_only)
),
]
print_stdout("\n".join(lines).rstrip())
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/python/lint/BUILD
Expand Up @@ -28,6 +28,6 @@ python_tests(
'src/python/pants/testutil:external_tool_test_base',
'src/python/pants/testutil/subsystem',
],
timeout=90,
timeout=120,
tags = {'integration'},
)
2 changes: 1 addition & 1 deletion src/python/pants/backend/python/lint/pylint/BUILD
Expand Up @@ -37,5 +37,5 @@ python_tests(
'src/python/pants/testutil/option',
],
tags = ['integration'],
timeout = 280,
timeout = 330,
)
2 changes: 1 addition & 1 deletion src/python/pants/core/goals/BUILD
Expand Up @@ -67,5 +67,5 @@ python_tests(
'examples:isort_cfg',
],
tags = ['integration'],
timeout = 210,
timeout = 240,
)
11 changes: 2 additions & 9 deletions src/python/pants/core/register.py
Expand Up @@ -7,14 +7,7 @@
"""

from pants.core.goals import binary, fmt, lint, repl, run, test, typecheck
from pants.core.target_types import (
AliasTarget,
Files,
GenericTarget,
PrepCommand,
RemoteSources,
Resources,
)
from pants.core.target_types import Files, GenericTarget, Resources
from pants.core.util_rules import (
archive,
determine_source_files,
Expand Down Expand Up @@ -48,4 +41,4 @@ def rules():


def target_types():
return [AliasTarget, Files, GenericTarget, PrepCommand, RemoteSources, Resources]
return [Files, GenericTarget, Resources]
185 changes: 1 addition & 184 deletions src/python/pants/core/target_types.py
@@ -1,22 +1,7 @@
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import collections.abc
from typing import Any, Dict, Optional

from pants.engine.addresses import Address
from pants.engine.target import (
COMMON_TARGET_FIELDS,
BoolField,
Dependencies,
InvalidFieldTypeException,
PrimitiveField,
Sources,
StringField,
StringSequenceField,
Target,
)
from pants.util.frozendict import FrozenDict
from pants.engine.target import COMMON_TARGET_FIELDS, Dependencies, Sources, Target

# -----------------------------------------------------------------------------------------------
# `files` target
Expand Down Expand Up @@ -75,171 +60,3 @@ class GenericTarget(Target):

alias = "target"
core_fields = (*COMMON_TARGET_FIELDS, Dependencies, Sources)


# -----------------------------------------------------------------------------------------------
# `alias` target
# -----------------------------------------------------------------------------------------------


class AliasTargetRequestedAddress(StringField):
"""The address to the target that you are creating an alias for, e.g.
`src/python/project:lib`."""

alias = "target"


class AliasDependencies(Dependencies):
"""This field must not be explicitly defined for `alias` targets.

The `alias()` macro will fill in the value automatically.
"""


# TODO: figure out how to support aliases in V2. When adding support, unmark this as `v1_only`.
class AliasTarget(Target):
"""A target that gets replaced by the address specified in the `target` field.

See https://www.pantsbuild.org/alias.html.
"""

alias = "alias"
core_fields = (*COMMON_TARGET_FIELDS, AliasDependencies, AliasTargetRequestedAddress)
v1_only = True


# -----------------------------------------------------------------------------------------------
# `prep_command` target
# -----------------------------------------------------------------------------------------------


class PrepCommandExecutable(StringField):
"""The path to the executable that should be run."""

alias = "prep_executable"
required = True


class PrepCommandArgs(StringSequenceField):
"""A list of command-line args to the executable."""

alias = "prep_args"


class PrepCommandEnviron(BoolField):
"""If True, the output of the command will be treated as a \\\\0-separated list of key=value
pairs to insert into the environment.

Note that this will pollute the environment for all future tests, so avoid it if at all
possible.
"""

alias = "prep_environ"
default = False


class PrepCommandGoals(StringSequenceField):
"""One or more pants goals to run this command in, e.g. `["test", "binary", "compile"]`."""

alias = "goals"
default = ("test",)


# TODO(#9388): maybe remove? Audit V1 usages.
class PrepCommand(Target):
"""A V1-only shell command to be run prior to running a goal.

For example, you can use `prep_command()` to execute a script that sets up tunnels to database
servers. These tunnels could then be leveraged by integration tests.

Pants will only execute the `prep_command()` under the specified goal, when processing targets
that depend on the `prep_command()` target. If not otherwise specified, prep_commands
execute in the test goal.

See also the target type jvm_prep_command() for running tasks defined by a JVM language.
"""

alias = "prep_command"
core_fields = (
*COMMON_TARGET_FIELDS,
PrepCommandExecutable,
PrepCommandArgs,
PrepCommandEnviron,
PrepCommandGoals,
)
v1_only = True


# -----------------------------------------------------------------------------------------------
# `remote_sources` targets
# -----------------------------------------------------------------------------------------------


class RemoteSourcesTargetRequestedAddress(StringField):
"""The address of the target which specifies the JAR whose sources will be unpacked.

Usually, this is an `unpacked_jars()` target.
"""

alias = "sources_target"
required = True


class RemoteSourcesTargetType(StringField):
"""The target type of the synthetic target to generate.

Use the raw symbol rather than a string, e.g. `java_library` rather than `"java_library"`.
"""

alias = "dest"
required = True


class RemoteSourcesArgs(PrimitiveField):
"""Any additional arguments necessary to construct the synthetic destination target (sources and
dependencies are supplied automatically)."""

alias = "args"
value: Optional[FrozenDict[str, Any]]
default = None

@classmethod
def sanitize_dict(cls, d: Dict[str, Any]) -> FrozenDict[str, Any]:
result = d.copy()
for k, v in d.items():
if not isinstance(v, str) and isinstance(v, collections.abc.Iterable):
result[k] = tuple(v)
if isinstance(v, dict):
result[k] = cls.sanitize_dict(v)
return FrozenDict(result)

@classmethod
def compute_value(
cls, raw_value: Optional[Dict[str, Any]], *, address: Address
) -> Optional[FrozenDict[str, Any]]:
value_or_default = super().compute_value(raw_value, address=address)
if value_or_default is None:
return None
if not isinstance(value_or_default, dict):
raise InvalidFieldTypeException(
address, cls.alias, value_or_default, expected_type="a dictionary"
)
return cls.sanitize_dict(value_or_default)


# TODO: figure out what support looks like for this in V2. Is this an example of codegen?
class RemoteSources(Target):
"""A target that generates a synthetic target using deferred sources.

This provides a mechanism for using the contents of a JAR as sources for another target.
"""

alias = "remote_sources"
core_fields = (
*COMMON_TARGET_FIELDS,
Dependencies,
RemoteSourcesTargetRequestedAddress,
RemoteSourcesTargetType,
RemoteSourcesArgs,
)
v1_only = True
39 changes: 4 additions & 35 deletions src/python/pants/engine/target.py
Expand Up @@ -61,7 +61,6 @@ class Field(ABC):
default: ClassVar[ImmutableValue]
# Subclasses may define these.
required: ClassVar[bool] = False
v1_only: ClassVar[bool] = False

# This is a little weird to have an abstract __init__(). We do this to ensure that all
# subclasses have this exact type signature for their constructor.
Expand Down Expand Up @@ -263,8 +262,6 @@ class Target(ABC):
# Subclasses must define these
alias: ClassVar[str]
core_fields: ClassVar[Tuple[Type[Field], ...]]
# Subclasses may define these
v1_only: ClassVar[bool] = False

# These get calculated in the constructor
address: Address
Expand Down Expand Up @@ -1753,42 +1750,14 @@ class DescriptionField(StringField):
alias = "description"


# TODO(#9388): remove? We don't want this in V2, but maybe keep it for V1.
class NoCacheField(BoolField):
"""If True, don't store results for this target in the V1 cache."""

alias = "no_cache"
default = False
v1_only = True


# TODO(#9388): remove?
class ScopeField(StringField):
"""A V1-only field for the scope of the target, which is used by the JVM to determine the
target's inclusion in the class path.

See `pants.build_graph.target_scopes.Scopes`.
"""

alias = "scope"
v1_only = True


# TODO(#9388): Remove.
class IntransitiveField(BoolField):
alias = "_transitive"
default = False
v1_only = True


COMMON_TARGET_FIELDS = (Tags, DescriptionField, NoCacheField, ScopeField, IntransitiveField)
COMMON_TARGET_FIELDS = (Tags, DescriptionField)


# TODO: figure out what support looks like for this with the Target API. The expected value is an
# Artifact, but V1 has no common Artifact interface.
# Artifact, there is no common Artifact interface.
class ProvidesField(PrimitiveField):
"""An `artifact`, such as `setup_py` or `scala_artifact`, that describes how to represent this
target to the outside world."""
"""An `artifact`, such as `setup_py`, that describes how to represent this target to the outside
world."""

alias = "provides"
default: ClassVar[Optional[Any]] = None
Expand Down