Skip to content

Commit

Permalink
Remove HasProducts and Variants
Browse files Browse the repository at this point in the history
  • Loading branch information
stuhood committed Sep 20, 2018
1 parent 392504d commit c82c87b
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 71 deletions.
6 changes: 0 additions & 6 deletions src/python/pants/engine/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@
TypeConstraint,
TypeConstraint,
TypeConstraint,
TypeConstraint,
TypeConstraint,
TypeId,
TypeId,
Buffer,
Expand Down Expand Up @@ -801,9 +799,7 @@ def new_scheduler(self,
construct_file,
construct_link,
construct_process_result,
constraint_has_products,
constraint_address,
constraint_variants,
constraint_path_globs,
constraint_directory_digest,
constraint_snapshot,
Expand Down Expand Up @@ -835,8 +831,6 @@ def tc(constraint):
func(construct_process_result),
# TypeConstraints.
tc(constraint_address),
tc(constraint_has_products),
tc(constraint_variants),
tc(constraint_path_globs),
tc(constraint_directory_digest),
tc(constraint_snapshot),
Expand Down
8 changes: 1 addition & 7 deletions src/python/pants/engine/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
from pants.engine.nodes import Return, State, Throw
from pants.engine.rules import RuleIndex, SingletonRule, TaskRule
from pants.engine.selectors import Select, constraint_for
from pants.engine.struct import HasProducts, Variants
from pants.util.contextutil import temporary_file_path
from pants.util.dirutil import check_no_overlapping_paths
from pants.util.objects import Collection, SubclassesOf, datatype
from pants.util.objects import Collection, datatype
from pants.util.strutil import pluralize


Expand Down Expand Up @@ -103,9 +102,6 @@ def __init__(
self._native = native
self.include_trace_on_error = include_trace_on_error

# TODO: The only (?) case where we use inheritance rather than exact type unions.
has_products_constraint = SubclassesOf(HasProducts)

# Validate and register all provided and intrinsic tasks.
rule_index = RuleIndex.create(list(rules))
self._root_subject_types = sorted(rule_index.roots, key=repr)
Expand All @@ -132,9 +128,7 @@ def __init__(
construct_file=File,
construct_link=Link,
construct_process_result=FallibleExecuteProcessResult,
constraint_has_products=has_products_constraint,
constraint_address=constraint_for(Address),
constraint_variants=constraint_for(Variants),
constraint_path_globs=constraint_for(PathGlobs),
constraint_directory_digest=constraint_for(DirectoryDigest),
constraint_snapshot=constraint_for(Snapshot),
Expand Down
27 changes: 0 additions & 27 deletions src/python/pants/engine/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

from __future__ import absolute_import, division, print_function, unicode_literals

from abc import abstractproperty
from collections import MutableMapping, MutableSequence

from future.utils import binary_type, text_type

from pants.engine.addressable import addressable, addressable_list
from pants.engine.objects import Serializable, SerializableFactory, Validatable, ValidationError
from pants.util.meta import AbstractClass
from pants.util.objects import SubclassesOf, SuperclassesOf


Expand Down Expand Up @@ -307,28 +305,3 @@ def dependencies(self):
:rtype: list
"""


class HasProducts(AbstractClass):
"""A mixin for a class that has a collection of products which it would like to expose."""

@abstractproperty
def products(self):
"""Returns a collection of products held by this class."""


class Variants(Struct):
"""A struct that holds default variant values.
Variants are key-value pairs representing uniquely identifying parameters for a Node.
Default variants are usually configured on a Target to be used whenever they are
not specified by a caller.
"""

def __init__(self, default=None, **kwargs):
"""
:param dict default: A dict of default variant values.
"""
# TODO: enforce the type of variants using the Addressable framework.
super(Variants, self).__init__(default=default, **kwargs)
4 changes: 0 additions & 4 deletions src/rust/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ pub extern "C" fn scheduler_create(
construct_link: Function,
construct_process_result: Function,
type_address: TypeConstraint,
type_has_products: TypeConstraint,
type_has_variants: TypeConstraint,
type_path_globs: TypeConstraint,
type_directory_digest: TypeConstraint,
type_snapshot: TypeConstraint,
Expand Down Expand Up @@ -261,8 +259,6 @@ pub extern "C" fn scheduler_create(
construct_link: construct_link,
construct_process_result: construct_process_result,
address: type_address,
has_products: type_has_products,
has_variants: type_has_variants,
path_globs: type_path_globs,
directory_digest: type_directory_digest,
snapshot: type_snapshot,
Expand Down
27 changes: 8 additions & 19 deletions src/rust/engine/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,16 @@ impl Select {
}

///
/// Looks for has-a or is-a relationships between the given value and the requested product.
/// Looks for an is-a relationship between the given value and the requested product.
///
/// Returns the resulting product Value for success, or the original Value for failure.
/// Returns the original product Value for either success or failure.
///
fn select_literal(&self, context: &Context, candidate: Value) -> Result<Value, Value> {
// Check whether the subject is-a instance of the product.
fn select_literal(&self, candidate: Value) -> Result<Value, Value> {
if externs::satisfied_by(&self.selector.product, &candidate) {
return Ok(candidate);
Ok(candidate)
} else {
Err(candidate)
}

// Else, check whether it has-a instance of the product.
// TODO: returning only the first item of a particular type.
if externs::satisfied_by(&context.core.types.has_products, &candidate) {
for child in externs::project_multi(&candidate, "products") {
if externs::satisfied_by(&self.selector.product, &child) {
return Ok(child);
}
}
}
Err(candidate)
}

fn snapshot(
Expand Down Expand Up @@ -307,16 +297,15 @@ impl WrappedNode for Select {

fn run(self, context: Context) -> NodeFuture<Value> {
// If the Subject "is a" or "has a" Product, then we're done.
if let Ok(value) = self.select_literal(&context, externs::val_for(self.params.expect_single()))
{
if let Ok(value) = self.select_literal(externs::val_for(self.params.expect_single())) {
return ok(value);
}

// Attempt to use the configured Task to compute the value.
self
.gen_node(&context)
.and_then(move |value| {
self.select_literal(&context, value).map_err(|value| {
self.select_literal(value).map_err(|value| {
throw(&format!(
"{} returned a result value that did not satisfy its constraints: {:?}",
rule_graph::entry_str(&self.entry),
Expand Down
2 changes: 0 additions & 2 deletions src/rust/engine/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ pub struct Types {
pub construct_link: Function,
pub construct_process_result: Function,
pub address: TypeConstraint,
pub has_products: TypeConstraint,
pub has_variants: TypeConstraint,
pub path_globs: TypeConstraint,
pub directory_digest: TypeConstraint,
pub snapshot: TypeConstraint,
Expand Down
8 changes: 2 additions & 6 deletions tests/python/pants_test/engine/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pants.engine.parser import SymbolTable
from pants.engine.scheduler import Scheduler
from pants.engine.selectors import Get
from pants.engine.struct import HasProducts, Struct
from pants.engine.struct import Struct
from pants.option.global_options import DEFAULT_EXECUTION_OPTIONS
from pants.util.memo import memoized
from pants.util.objects import SubclassesOf
Expand Down Expand Up @@ -105,15 +105,11 @@ def create_scheduler(rules, validate=True, native=None):
)


class Target(Struct, HasProducts):
class Target(Struct):
def __init__(self, name=None, configurations=None, **kwargs):
super(Target, self).__init__(name=name, **kwargs)
self.configurations = configurations

@property
def products(self):
return self.configurations

@addressable_list(SubclassesOf(Struct))
def configurations(self):
pass
Expand Down

0 comments on commit c82c87b

Please sign in to comment.