Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow plugins to provide "auxiliary" goals (and refactor BSP into backends) #20913

Merged
merged 23 commits into from
Aug 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more progress on DaemonGoal API
tdyas committed Jun 26, 2024
commit e50f12822db5b80dce92a264efa554e6372b0f80
5 changes: 1 addition & 4 deletions src/python/pants/bsp/goal.py
Original file line number Diff line number Diff line change
@@ -12,16 +12,13 @@

from pants.base.build_root import BuildRoot
from pants.base.exiter import PANTS_FAILED_EXIT_CODE, PANTS_SUCCEEDED_EXIT_CODE, ExitCode
from pants.base.specs import Specs
from pants.bsp.context import BSPContext
from pants.bsp.protocol import BSPConnection
from pants.bsp.util_rules.lifecycle import BSP_VERSION, BSPLanguageSupport
from pants.build_graph.build_configuration import BuildConfiguration
from pants.engine.env_vars import CompleteEnvironmentVars
from pants.engine.internals.session import SessionValues
from pants.engine.unions import UnionMembership
from pants.goal.builtin_goal import BuiltinGoal
from pants.goal.daemon_goal import DaemonGoalContext
from pants.goal.daemon_goal import DaemonGoal, DaemonGoalContext
from pants.init.engine_initializer import GraphSession
from pants.option.option_types import BoolOption, FileListOption, StrListOption
from pants.option.option_value_container import OptionValueContainer
2 changes: 1 addition & 1 deletion src/python/pants/build_graph/build_configuration.py
Original file line number Diff line number Diff line change
@@ -270,7 +270,7 @@ def register_remote_auth_plugin(self, remote_auth_plugin: Callable) -> None:
self._remote_auth_plugin = remote_auth_plugin

def register_daemon_goals(self, plugin_or_backend: str, daemon_goals: Iterable[type]):
"""Registers the given builtin goals."""
"""Registers the given daemon goals."""
if not isinstance(daemon_goals, Iterable):
raise TypeError(
f"The entrypoint `daemon_goals` must return an iterable. "
15 changes: 10 additions & 5 deletions src/python/pants/goal/daemon_goal.py
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
from pants.engine.unions import UnionMembership
from pants.init.engine_initializer import GraphSession
from pants.option.options import Options
from pants.option.scope import ScopeInfo


@dataclass
@@ -23,20 +24,24 @@ class DaemonGoalContext:
options: Options
specs: Specs
union_membership: UnionMembership


class DaemonGoal(ABC, GoalSubsystem):
"""Configure a "daemon" goal which allows rules to "take over" Pants client execution.
"""Configure a "daemon" goal which allows rules to "take over" Pants client execution in lieu
of executing an ordnary goal.

Only a single daemon goal is executed per run, any remaining goals/arguments are passed
unaltered to the builtin goal. Daemon goals have precedence over regular goals.
unaltered to the daemon goal. Daemon goals have precedence over regular goals.

When multiple daemon goals are presented, the first builtin goal will be used unless there is a
When multiple daemon goals are presented, the first daemon goal will be used unless there is a
daemon goal that begin with a hyphen (`-`), in which case the last such "option goal" will be
prioritized. This is to support things like `./pants some-builtin-goal --help`.

The intended use for this API is rule code which runs a server (for example, a BSP server)
which provides an alternate interface to the Pants rule engine.
"""

# Used by `pants.option.arg_splitter.ArgSplitter()` to optionally allow aliasing builtin goals.
# Used by `pants.option.arg_splitter.ArgSplitter()` to optionally allow aliasing daemon goals.
aliases: ClassVar[tuple[str, ...]] = ()

@classmethod