cool-easter-32542
06/22/2023, 7:36 AM❯ pants dependencies ::
12:44:06.76 [ERROR] 1 Exception encountered:
Engine traceback:
in `dependencies` goal
DependencyRuleActionDeniedError: cheeseshop/cli/utils/utils.py has 1 dependency violation:
* cheeseshop/cli/utils/BUILD[!*] -> cheeseshop/repository/parsing : DENY
python_sources cheeseshop/cli/utils/utils.py -> python_sources cheeseshop/repository/parsing/casts.py
---------------------------------------------------------------------------------------------------------------
To learn more about the visibility rules violations and how to fix them,
please see <https://mycompany.org/development-guidelines/pants#visibility-violations>.
---------------------------------------------------------------------------------------------------------------
Describe the solution you'd like
Be able to write custom plugin that would let Pants users specify the actions that should take place upon certain exceptions thrown or upon completion of a certain goal.
Describe alternatives you've considered
This is currently possible to achieve (for certain conditions) and definitely with certain limitations by adding code into the rules() call inside the plugin module containing rules code (as the rules() is guaranteed to be executed on any Pants run). This is achieved by monkey patching the exception so that a custom one (with an epilogue added to the message) will be used instead.
from pants.engine import target
from pants.engine.rules import collect_rules
class DependencyRuleActionDeniedError(Exception):
@classmethod
def create(cls, description_of_origin: str) -> "DependencyRuleActionDeniedError":
return cls(f"Dependency rule violation for {description_of_origin}")
def __init__(self, message):
super(DependencyRuleActionDeniedError, self).__init__(
message + "\n\n" + construct_epilogue_body(DependencyRuleActionDeniedErrorEpilogue)
)
def rules():
target.DependencyRuleActionDeniedError = DependencyRuleActionDeniedError
return collect_rules()
This isn't the most optimal way to achieve this as this may require some duplication of the Pants code in a plugin which may be brittle.
pantsbuild/pants