From 77aa4d8b4362fcb511863c78ef548580aba906f2 Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Wed, 22 Jan 2025 14:05:09 -0800 Subject: [PATCH] Move HelpRequest classes to help package. (#21861) And delete arg_splitter.py, as those were the last remaining bits of code in that file. --- src/python/pants/goal/help.py | 14 ++++--- src/python/pants/help/help_printer.py | 42 +++++++++++++++++---- src/python/pants/option/arg_splitter.py | 49 ------------------------- 3 files changed, 43 insertions(+), 62 deletions(-) delete mode 100644 src/python/pants/option/arg_splitter.py diff --git a/src/python/pants/goal/help.py b/src/python/pants/goal/help.py index 29a75b10e0c..46e25a9491f 100644 --- a/src/python/pants/goal/help.py +++ b/src/python/pants/goal/help.py @@ -16,20 +16,24 @@ from pants.engine.unions import UnionMembership from pants.goal.builtin_goal import BuiltinGoal from pants.help.help_info_extracter import HelpInfoExtracter -from pants.help.help_printer import HelpPrinter -from pants.init.engine_initializer import GraphSession -from pants.option.arg_splitter import ( - NO_GOAL_NAME, - UNKNOWN_GOAL_NAME, +from pants.help.help_printer import ( AllHelp, + HelpPrinter, HelpRequest, NoGoalHelp, ThingHelp, UnknownGoalHelp, VersionHelp, ) +from pants.init.engine_initializer import GraphSession from pants.option.options import Options +# These are the names for the built in goals to print help message when there is no goal, or any +# unknown goals respectively. They begin with underlines to exclude them from the list of goals in +# the goal help output. +NO_GOAL_NAME = "__no_goal" +UNKNOWN_GOAL_NAME = "__unknown_goal" + class HelpBuiltinGoalBase(BuiltinGoal): def run( diff --git a/src/python/pants/help/help_printer.py b/src/python/pants/help/help_printer.py index 9c8d53c0dd2..c80c5750bf0 100644 --- a/src/python/pants/help/help_printer.py +++ b/src/python/pants/help/help_printer.py @@ -5,6 +5,8 @@ import json import re import textwrap +from abc import ABC +from dataclasses import dataclass from itertools import cycle from typing import Callable, Dict, Iterable, List, Literal, Optional, Set, Tuple, cast @@ -13,19 +15,43 @@ from pants.help.help_info_extracter import AllHelpInfo, HelpJSONEncoder from pants.help.help_tools import ToolHelpInfo from pants.help.maybe_color import MaybeColor -from pants.option.arg_splitter import ( - AllHelp, - HelpRequest, - NoGoalHelp, - ThingHelp, - UnknownGoalHelp, - VersionHelp, -) from pants.option.scope import GLOBAL_SCOPE from pants.util.docutil import bin_name, terminal_width from pants.util.strutil import first_paragraph, hard_wrap, pluralize, softwrap +class HelpRequest(ABC): + """Represents an implicit or explicit request for help by the user.""" + + +@dataclass(frozen=True) +class ThingHelp(HelpRequest): + """The user requested help on one or more things: e.g., an options scope or a target type.""" + + advanced: bool = False + things: tuple[str, ...] = () + likely_specs: tuple[str, ...] = () + + +class VersionHelp(HelpRequest): + """The user asked for the version of this instance of pants.""" + + +class AllHelp(HelpRequest): + """The user requested a dump of all help info.""" + + +@dataclass(frozen=True) +class UnknownGoalHelp(HelpRequest): + """The user specified an unknown goal (or task).""" + + unknown_goals: tuple[str, ...] + + +class NoGoalHelp(HelpRequest): + """The user specified no goals.""" + + class HelpPrinter(MaybeColor): """Prints general and goal-related help to the console.""" diff --git a/src/python/pants/option/arg_splitter.py b/src/python/pants/option/arg_splitter.py deleted file mode 100644 index 37772ca884b..00000000000 --- a/src/python/pants/option/arg_splitter.py +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -from __future__ import annotations - -from abc import ABC -from dataclasses import dataclass - -# TODO: Move these remaining classes elsewhere (probably in the help package), and -# delete this file. - - -class HelpRequest(ABC): - """Represents an implicit or explicit request for help by the user.""" - - -@dataclass(frozen=True) -class ThingHelp(HelpRequest): - """The user requested help on one or more things: e.g., an options scope or a target type.""" - - advanced: bool = False - things: tuple[str, ...] = () - likely_specs: tuple[str, ...] = () - - -class VersionHelp(HelpRequest): - """The user asked for the version of this instance of pants.""" - - -class AllHelp(HelpRequest): - """The user requested a dump of all help info.""" - - -@dataclass(frozen=True) -class UnknownGoalHelp(HelpRequest): - """The user specified an unknown goal (or task).""" - - unknown_goals: tuple[str, ...] - - -class NoGoalHelp(HelpRequest): - """The user specified no goals.""" - - -# These are the names for the built in goals to print help message when there is no goal, or any -# unknown goals respectively. They begin with underlines to exclude them from the list of goals in -# the goal help output. -NO_GOAL_NAME = "__no_goal" -UNKNOWN_GOAL_NAME = "__unknown_goal"