From c82c87bfdac2170b8092f5965a131fa6f1159f96 Mon Sep 17 00:00:00 2001 From: Stu Hood Date: Tue, 18 Sep 2018 20:37:13 -0700 Subject: [PATCH] Remove HasProducts and Variants --- src/python/pants/engine/native.py | 6 ------ src/python/pants/engine/scheduler.py | 8 +------- src/python/pants/engine/struct.py | 27 -------------------------- src/rust/engine/src/lib.rs | 4 ---- src/rust/engine/src/nodes.rs | 27 ++++++++------------------ src/rust/engine/src/types.rs | 2 -- tests/python/pants_test/engine/util.py | 8 ++------ 7 files changed, 11 insertions(+), 71 deletions(-) diff --git a/src/python/pants/engine/native.py b/src/python/pants/engine/native.py index 9b4d2be469f..db1f839961b 100644 --- a/src/python/pants/engine/native.py +++ b/src/python/pants/engine/native.py @@ -196,8 +196,6 @@ TypeConstraint, TypeConstraint, TypeConstraint, - TypeConstraint, - TypeConstraint, TypeId, TypeId, Buffer, @@ -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, @@ -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), diff --git a/src/python/pants/engine/scheduler.py b/src/python/pants/engine/scheduler.py index de7e5851991..4dec907aa01 100644 --- a/src/python/pants/engine/scheduler.py +++ b/src/python/pants/engine/scheduler.py @@ -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 @@ -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) @@ -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), diff --git a/src/python/pants/engine/struct.py b/src/python/pants/engine/struct.py index 2e648eacb73..537566999a6 100644 --- a/src/python/pants/engine/struct.py +++ b/src/python/pants/engine/struct.py @@ -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 @@ -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) diff --git a/src/rust/engine/src/lib.rs b/src/rust/engine/src/lib.rs index 5209646bf60..044eb142c10 100644 --- a/src/rust/engine/src/lib.rs +++ b/src/rust/engine/src/lib.rs @@ -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, @@ -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, diff --git a/src/rust/engine/src/nodes.rs b/src/rust/engine/src/nodes.rs index 16ab7fc8ee6..db990a78860 100644 --- a/src/rust/engine/src/nodes.rs +++ b/src/rust/engine/src/nodes.rs @@ -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 { - // Check whether the subject is-a instance of the product. + fn select_literal(&self, candidate: Value) -> Result { 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( @@ -307,8 +297,7 @@ impl WrappedNode for Select { fn run(self, context: Context) -> NodeFuture { // 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); } @@ -316,7 +305,7 @@ impl WrappedNode for Select { 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), diff --git a/src/rust/engine/src/types.rs b/src/rust/engine/src/types.rs index 8f41141c50d..d19dd2b446e 100644 --- a/src/rust/engine/src/types.rs +++ b/src/rust/engine/src/types.rs @@ -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, diff --git a/tests/python/pants_test/engine/util.py b/tests/python/pants_test/engine/util.py index b51894da490..9756569888e 100644 --- a/tests/python/pants_test/engine/util.py +++ b/tests/python/pants_test/engine/util.py @@ -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 @@ -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