Last active
May 29, 2020 22:54
-
-
Save Eric-Arellano/f83dcb8cfb891afe6af50f4b15707894 to your computer and use it in GitHub Desktop.
See https://pants.readme.io/docs/target-api-concepts for more instructions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pants.build_graph.build_file_aliases import BuildFileAliases | |
from pants.build_graph.payload_field import PrimitiveField | |
from pants.build_graph.target import Target as TargetV1 | |
from pants.engine.target import Target as TargetV2 | |
from pants.engine.target import COMMON_TARGET_FIELDS, Dependencies, IntField, Sources | |
"""This sets up a new target called `elixir_tests`, with both a V1 definition and a V2 Target API definition. | |
In a BUILD file, this would look like: | |
elixir_tests( | |
name="demo", | |
sources=["test_demo.ex"], | |
timeout=120, | |
) | |
""" | |
class ElixirTestTargetV1(TargetV1): | |
default_sources_globs = ("test_*.ex",) | |
@classmethod | |
def alias(cls): | |
return "elixir_tests" | |
def __init__(self, sources=None, timeout=None, payload=None, **kwargs): | |
if timeout < 0: | |
raise ValueError(f"Invalid timeout field: {timeout}. Must be > 0.") | |
payload = payload or Payload() | |
payload.add_fields( | |
{ | |
"sources": self.create_sources_field( | |
sources=sources, sources_rel_path=address.spec_path, key_arg="sources" | |
), | |
"timeout": PrimitiveField(timeout), | |
} | |
) | |
super().__init__(payload=payload, **kwargs) | |
class ElixirSources(Sources): | |
default = ("test_*.ex",) | |
class ElixirTestTimeout(IntField): | |
alias = "timeout" | |
class ElixirTestTargetV2(TargetV2): | |
alias = "elixir_tests" | |
core_fields = (*COMMON_TARGET_FIELDS, Dependencies, ElixirSources, ElixirTestTimeout) | |
def build_file_aliases(): | |
return BuildFileAliases(targets={ElixirTestTargetV1.alias(): ElixirTestTargetV1}) | |
def target_types(): | |
return [ElixirTestTargetV2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment