from pants.base.exceptions import TargetDefinitionException class MyTarget(Target): def __init__(self, **kwargs): if kwargs.get('sources') is None: raise TargetDefinitionException(self, 'Missing sources attribute') super().__init__(**kwargs)
from pants.build_graph.target import Target class MyTarget(Target): pass my_target = MyTarget(name='my_target') my_target.add_dependency('non_existent_target')This example demonstrates an error in the definition of a target. Here, we have tried to add a dependency on a non-existent target. This will raise a `TargetDefinitionException` with a message like "Target 'my_target' depends on non-existent target 'non_existent_target'". It's worth noting that the `TargetDefinitionException` class belongs to the `pants.base.exceptions` module, which is a part of the Pants build system. Therefore, it is likely that you'll encounter this exception while working on a Python project that uses Pants.