Skip to content

Commit

Permalink
See issue #105: Hacking around
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshjoshi committed Jun 24, 2024
1 parent e7b141f commit 721b383
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions pants-plugins/experimental/plugin/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python_sources()
Empty file.
11 changes: 11 additions & 0 deletions pants-plugins/experimental/plugin/register.py
Original file line number Diff line number Diff line change
@@ -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(),)
54 changes: 54 additions & 0 deletions pants-plugins/experimental/plugin/rules.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ backend_packages = [
#"experimental.ansible",
#"experimental.ansible.lint.ansible_lint",
#"experimental.swift",
"experimental.plugin",
]

[source]
Expand Down

0 comments on commit 721b383

Please sign in to comment.