diff --git a/pants-plugins/experimental/plugin/BUILD b/pants-plugins/experimental/plugin/BUILD new file mode 100644 index 0000000..db46e8d --- /dev/null +++ b/pants-plugins/experimental/plugin/BUILD @@ -0,0 +1 @@ +python_sources() diff --git a/pants-plugins/experimental/plugin/__init__.py b/pants-plugins/experimental/plugin/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pants-plugins/experimental/plugin/register.py b/pants-plugins/experimental/plugin/register.py new file mode 100644 index 0000000..70f1761 --- /dev/null +++ b/pants-plugins/experimental/plugin/register.py @@ -0,0 +1,11 @@ +from __future__ import annotations + +from collections.abc import Iterable + +from experimental.plugin.rules import rules as plugin_rules +from pants.engine.rules import Rule +from pants.engine.unions import UnionRule + + +def rules() -> Iterable[Rule | UnionRule]: + return (*plugin_rules(),) diff --git a/pants-plugins/experimental/plugin/rules.py b/pants-plugins/experimental/plugin/rules.py new file mode 100644 index 0000000..959681d --- /dev/null +++ b/pants-plugins/experimental/plugin/rules.py @@ -0,0 +1,54 @@ +from __future__ import annotations + +from collections.abc import Iterable +from enum import Enum + +from pants.backend.project_info.peek import TargetDatas +from pants.engine.console import Console +from pants.engine.goal import Goal, GoalSubsystem, Outputting +from pants.engine.rules import Get, Rule, collect_rules, goal_rule +from pants.engine.target import UnexpandedTargets +from pants.option.option_types import EnumOption, StrOption + +class PluginType(Enum): + BUILTIN = "builtin" + GOAL = "goal" + LINTER = "linter" + + +class PluginSubsystem(GoalSubsystem): + name = "plugin-init" + help = "???" + + plugin_name = StrOption( + "--name", + default=None, + help="The name of the plugin to create.", + ) + + type = EnumOption( + default=None, + enum_type=PluginType, + help="The type of plugin to create.", + ) + + +class Plugin(Goal): + subsystem_cls = PluginSubsystem + environment_behavior = Goal.EnvironmentBehavior.LOCAL_ONLY + + +@goal_rule +async def plugin( + console: Console, + subsystem: PluginSubsystem, + # targets: UnexpandedTargets, +) -> Plugin: + if not subsystem.type: + console.input(f"What type of plugin do you want to create? {[p.value for p in PluginType]} ") + + return Plugin(exit_code=0) + + +def rules() -> Iterable[Rule]: + return collect_rules() diff --git a/pants.toml b/pants.toml index cd9ac93..6126c0a 100644 --- a/pants.toml +++ b/pants.toml @@ -30,6 +30,7 @@ backend_packages = [ #"experimental.ansible", #"experimental.ansible.lint.ansible_lint", #"experimental.swift", + "experimental.plugin", ] [source]