Skip to content

Commit

Permalink
Remove formatted text from main help
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnan-chandra committed May 13, 2024
1 parent d0698e3 commit 9437d14
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 42 deletions.
29 changes: 7 additions & 22 deletions src/python/pants/backend/python/subsystems/python_tool_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os
from dataclasses import dataclass
from functools import cache
from typing import ClassVar, Iterable, Sequence
from typing import ClassVar, Iterable, Optional, Sequence
from urllib.parse import urlparse

from pants.backend.python.target_types import ConsoleScript, EntryPoint, MainSpecification
Expand Down Expand Up @@ -70,6 +70,8 @@ def _install_from_resolve_help(cls) -> str:
package_and_version = cls._default_package_name_and_version()
version_clause = (
f", which uses {package_and_version.name} version {package_and_version.version}"
if package_and_version
else ""
)
return softwrap(
f"""\
Expand Down Expand Up @@ -193,7 +195,10 @@ def pex_requirements_for_default_lockfile(cls):

@classmethod
@cache
def _default_package_name_and_version(cls) -> _PackageNameAndVersion:
def _default_package_name_and_version(cls) -> Optional[_PackageNameAndVersion]:
if cls.default_lockfile_resource is None:
return None

lockfile = cls.pex_requirements_for_default_lockfile()
parts = urlparse(lockfile.url)
# urlparse retains the leading / in URLs with a netloc.
Expand Down Expand Up @@ -224,26 +229,6 @@ def _default_package_name_and_version(cls) -> _PackageNameAndVersion:
if requirement["project_name"] == first_default_requirement.project_name
)

@classproperty
def help_extended(cls) -> str:
base_help = cls.help if isinstance(cls.help, str) else cls.help()
if cls.default_lockfile_resource is None:
return base_help

help_paragraphs = [base_help]

package_name_and_version = cls._default_package_name_and_version()
help_paragraphs.append(
softwrap(
f"""
This version of Pants uses {package_name_and_version.name} {package_name_and_version.version} by default.
Use a dedicated lockfile and the `install_from_resolve` option to control this.
"""
)
)

return "\n\n".join(help_paragraphs)

def pex_requirements(
self,
*,
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/option/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ScopeInfo:

@property
def description(self) -> str:
return cast(str, self._subsystem_cls_attr("help_extended"))
return cast(str, self._subsystem_cls_attr("help"))

@property
def deprecated_scope(self) -> Optional[str]:
Expand Down
20 changes: 1 addition & 19 deletions src/python/pants/option/subsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from pants.option.options import Options
from pants.option.scope import Scope, ScopedOptions, ScopeInfo, normalize_scope
from pants.util.frozendict import FrozenDict
from pants.util.meta import classproperty
from pants.util.strutil import softwrap

if TYPE_CHECKING:
Expand Down Expand Up @@ -68,23 +67,6 @@ class Subsystem(metaclass=_SubsystemMeta):
options_scope: str
help: ClassVar[str | Callable[[], str]]

@classproperty
def help_extended(cls) -> str:
"""Help text to be used in `./pants help`.
Subclasses may override this to add more information, but by default, the text generated by
`help` is returned unchanged.
"""
# This shouldn't happen for real subsystems, but does appear to
# occur in tests.
if not hasattr(cls, "help"):
return ""

if isinstance(cls.help, str):
return cls.help

return cls.help()

# Subclasses may override these to specify a deprecated former name for this Subsystem's scope.
# Option values can be read from the deprecated scope, but a deprecation warning will be issued.
# The deprecation warning becomes an error at the given Pants version (which must therefore be
Expand Down Expand Up @@ -212,7 +194,7 @@ def _construct_subsystem_rule(cls) -> Rule:
name = f"construct_scope_{snake_scope}"
partial_construct_subsystem.__name__ = name
partial_construct_subsystem.__module__ = cls.__module__
partial_construct_subsystem.__doc__ = cls.help_extended
partial_construct_subsystem.__doc__ = cls.help

_, class_definition_lineno = inspect.getsourcelines(cls)
partial_construct_subsystem.__line_number__ = class_definition_lineno
Expand Down

0 comments on commit 9437d14

Please sign in to comment.