Skip to content
Permalink
Browse files

convert many manual NotImplementedError() calls to @AbstractMethod

  • Loading branch information...
cosmicexplorer committed Mar 3, 2019
1 parent 1b4f534 commit 205e79108a44a6b620568dc7dc94e85ed4fc26d1
@@ -4,6 +4,8 @@

from __future__ import absolute_import, division, print_function, unicode_literals

from abc import abstractmethod

from pants.backend.native.subsystems.utils.mirrored_target_option_mixin import \
MirroredTargetOptionMixin
from pants.option.compiler_option_sets_mixin import CompilerOptionSetsMixin
@@ -66,8 +68,9 @@ def subsystem_dependencies(cls):
)

@classproperty
@abstractmethod
def header_file_extensions_default(cls):
raise NotImplementedError('header_file_extensions_default() must be overridden!')
"""Default value for --header-file-extensions."""

@classmethod
def register_options(cls, register):
@@ -4,24 +4,24 @@

from __future__ import absolute_import, division, print_function, unicode_literals

from builtins import object
from abc import abstractmethod

from pants.util.meta import classproperty
from pants.util.meta import AbstractClass, classproperty


# TODO: consider coalescing existing methods of mirroring options between a target and a subsystem
# -- see pants.backend.jvm.subsystems.dependency_context.DependencyContext#defaulted_property()!
class MirroredTargetOptionMixin(object):
class MirroredTargetOptionMixin(AbstractClass):
"""Get option values which may be set in this subsystem or in a Target's keyword argument."""

@classproperty
@abstractmethod
def mirrored_option_to_kwarg_map(cls):
"""Subclasses should override and return a dict of (subsystem option name) -> (target kwarg).
This classproperty should return a dict mapping this subsystem's options attribute name (with
underscores) to the corresponding target's keyword argument name.
"""
raise NotImplementedError()

def get_target_mirrored_option(self, option_name, target):
field_name = self.mirrored_option_to_kwarg_map[option_name]
@@ -43,11 +43,16 @@ class NativeCompile(NativeTask, AbstractClass):
# NB: `source_target_constraint` must be overridden.
source_target_constraint = None

# `NativeCompile` will use `workunit_label` as the name of the workunit when executing the
# compiler process. `workunit_label` must be set to a string.
@classproperty
@abstractmethod
def workunit_label(cls):
raise NotImplementedError('subclasses of NativeCompile must override workunit_label!')
"""A string describing the work being done during compilation.
`NativeCompile` will use `workunit_label` as the name of the workunit when executing the
compiler process.
:rtype: str
"""

@classmethod
def product_types(cls):
@@ -4,6 +4,7 @@

from __future__ import absolute_import, division, print_function, unicode_literals

from abc import abstractmethod
from builtins import filter

from pants.backend.native.config.environment import CppToolchain, CToolchain
@@ -24,6 +25,7 @@
class NativeTask(Task):

@classproperty
@abstractmethod
def source_target_constraint(cls):
"""Return a type constraint which is used to filter "source" targets for this task.
@@ -33,7 +35,6 @@ def source_target_constraint(cls):
:return: :class:`pants.util.objects.TypeConstraint`
"""
raise NotImplementedError()

@classproperty
def dependent_target_constraint(cls):
@@ -4,6 +4,7 @@

from __future__ import absolute_import, division, print_function, unicode_literals

from abc import abstractmethod
from builtins import str

from future.utils import string_types
@@ -28,39 +29,31 @@ class WrongTargetTypeError(AddressLookupError):
"""Thrown if the wrong type of target is encountered."""

@classproperty
@abstractmethod
def expected_target_constraint(cls):
"""
:returns: A type constraint which is used to validate the targets containing remote sources,
specified `imported_target_kwargs_field` in a BUILD file.
:rtype: TypeConstraint
"""
# TODO: make a utility in pants.util.meta to register these standard `NotImplementedError`s!
raise NotImplementedError(
'subclasses of ImportRemoteSourcesMixin must implement an '
'`expected_target_constraint` classproperty'
)

@classproperty
@abstractmethod
def imported_target_kwargs_field(cls):
"""
:returns: string representing the keyword argument of an uninitialized target representing
source target specs to be imported.
:rtype: str
"""
raise NotImplementedError(
'subclasses of ImportRemoteSourcesMixin must implement an '
'`imported_target_kwargs_field` classproperty'
)

@classproperty
@abstractmethod
def imported_target_payload_field(cls):
"""
:returns: string representing the payload field of an already-initialized target containing
source target specs to be imported.
:rtype: str
"""
raise NotImplementedError(
'subclasses of ImportRemoteSourcesMixin must implement an '
'`imported_target_payload_field` classproperty'
)

@classmethod
def imported_target_specs(cls, kwargs=None, payload=None):
@@ -42,12 +42,12 @@ def product_types(cls):
return [UnpackedArchives]

@classproperty
@abstractmethod
def source_target_constraint(cls):
"""Return a type constraint which is evaluated to determine "source" targets for this task.
:return: :class:`pants.util.objects.TypeConstraint`
"""
raise NotImplementedError()

@abstractmethod
def unpack_target(unpackable_target, unpack_dir):
@@ -18,7 +18,7 @@ def __call__(cls, *args, **kwargs):


class ClassPropertyDescriptor(object):
"""Define a readable class property, given a function."""
"""Define a readable attribute on a class, given a function."""

# TODO: it seems overriding __set__ and __delete__ would require defining a metaclass or
# overriding __setattr__/__delattr__ (see
@@ -412,13 +412,6 @@ class TypeOnlyConstraint(TypeConstraint):
and easier to understand than the more complex validation allowed by `.satisfied_by()`.
"""

# TODO: make an @abstract_classproperty decorator to do this boilerplate!
@classproperty
def _variance_symbol(cls):
"""This is propagated to the the `TypeConstraint` constructor."""
raise NotImplementedError('{} must implement the _variance_symbol classproperty!'
.format(cls.__name__))

def __init__(self, *types):
"""Creates a type constraint based on some logic to match the given types.
@@ -5,6 +5,7 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import re
from abc import abstractmethod
from builtins import next, str

from pants.backend.native.register import rules as native_backend_rules
@@ -40,9 +41,9 @@ def rules(cls):
return super(BuildLocalPythonDistributionsTestBase, cls).rules() + native_backend_rules()

@classproperty
@abstractmethod
def dist_specs(cls):
"""Fed into `self.populate_target_dict()`."""
raise NotImplementedError('dist_specs must be implemented!')

def setUp(self):
super(BuildLocalPythonDistributionsTestBase, self).setUp()
@@ -6,6 +6,7 @@

import glob
import os
from abc import abstractmethod
from builtins import object
from contextlib import closing, contextmanager
from io import BytesIO
@@ -65,12 +66,12 @@ class TaskTestBase(TestBase):
options_scope = 'test_scope'

@classmethod
@abstractmethod
def task_type(cls):
"""Subclasses must return the type of the Task subclass under test.
:API: public
"""
raise NotImplementedError()

def setUp(self):
"""
@@ -8,6 +8,7 @@
import logging
import os
import unittest
from abc import abstractmethod
from builtins import object, open, str
from collections import defaultdict
from contextlib import contextmanager
@@ -39,16 +40,18 @@
from pants.util.dirutil import (recursive_dirname, relative_symlink, safe_file_dump, safe_mkdir,
safe_mkdtemp, safe_open, safe_rmtree)
from pants.util.memo import memoized_method
from pants.util.meta import AbstractClass
from pants_test.base.context_utils import create_context_from_options
from pants_test.engine.util import init_native
from pants_test.option.util.fakes import create_options_for_optionables
from pants_test.subsystem import subsystem_util


class TestGenerator(object):
class TestGenerator(AbstractClass):
"""A mixin that facilitates test generation at runtime."""

@classmethod
@abstractmethod
def generate_tests(cls):
"""Generate tests for a given class.
@@ -60,7 +63,6 @@ class ThingTest(TestGenerator):
ThingTest.generate_tests()
"""
raise NotImplementedError()

@classmethod
def add_test(cls, method_name, method):

0 comments on commit 205e791

Please sign in to comment.
You can’t perform that action at this time.