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

[internal] softwrap pants.jvm #14989

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 9 additions & 6 deletions src/python/pants/jvm/resolve/coursier_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pants.util.logging import LogLevel
from pants.util.memo import memoized_property
from pants.util.ordered_set import FrozenOrderedSet
from pants.util.strutil import softwrap

COURSIER_POST_PROCESSING_SCRIPT = textwrap.dedent(
"""\
Expand Down Expand Up @@ -133,12 +134,14 @@ class CoursierSubsystem(TemplatedExternalTool):
"https://maven-central.storage-download.googleapis.com/maven2",
"https://repo1.maven.org/maven2",
],
help=(
"Maven style repositories to resolve artifacts from."
"\n\n"
"Coursier will resolve these repositories in the order in which they are "
"specifed, and re-ordering repositories will cause artifacts to be "
"re-downloaded. This can result in artifacts in lockfiles becoming invalid."
help=softwrap(
"""
Maven style repositories to resolve artifacts from.

Coursier will resolve these repositories in the order in which they are
specifed, and re-ordering repositories will cause artifacts to be
re-downloaded. This can result in artifacts in lockfiles becoming invalid.
"""
),
)

Expand Down
52 changes: 32 additions & 20 deletions src/python/pants/jvm/resolve/jvm_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from pants.option.subsystem import Subsystem
from pants.util.docutil import bin_name
from pants.util.ordered_set import FrozenOrderedSet
from pants.util.strutil import softwrap


class JvmToolBase(Subsystem):
Expand All @@ -45,35 +46,42 @@ class JvmToolBase(Subsystem):
"--version",
advanced=True,
default=lambda cls: cls.default_version,
help=lambda cls: (
"Version string for the tool. This is available for substitution in the "
f"`[{cls.options_scope}].artifacts` option by including the string "
"`{version}`."
help=lambda cls: softwrap(
f"""
Version string for the tool. This is available for substitution in the
`[{cls.options_scope}].artifacts` option by including the string `{{version}}`.
"""
),
)
artifacts = StrListOption(
"--artifacts",
advanced=True,
default=lambda cls: list(cls.default_artifacts),
help=lambda cls: (
"Artifact requirements for this tool using specified as either the address of a `jvm_artifact` "
"target or, alternatively, as a colon-separated Maven coordinates (e.g., group:name:version). "
"For Maven coordinates, the string `{version}` version will be substituted with the value of the "
f"`[{cls.options_scope}].version` option."
help=lambda cls: softwrap(
f"""
Artifact requirements for this tool using specified as either the address of a `jvm_artifact`
target or, alternatively, as a colon-separated Maven coordinates (e.g., group:name:version).
For Maven coordinates, the string `{{version}}` version will be substituted with the value of the
`[{cls.options_scope}].version` option.
"""
),
)
lockfile = StrOption(
"--lockfile",
default=DEFAULT_TOOL_LOCKFILE,
advanced=True,
help=lambda cls: (
"Path to a lockfile used for installing the tool.\n\n"
f"Set to the string `{DEFAULT_TOOL_LOCKFILE}` to use a lockfile provided by "
"Pants, so long as you have not changed the `--version` option. "
f"See {cls.default_lockfile_url} for the default lockfile contents.\n\n"
"To use a custom lockfile, set this option to a file path relative to the "
f"build root, then run `{bin_name()} jvm-generate-lockfiles "
f"--resolve={cls.options_scope}`.\n\n"
help=lambda cls: softwrap(
f"""
Path to a lockfile used for installing the tool.

Set to the string `{DEFAULT_TOOL_LOCKFILE}` to use a lockfile provided by
Pants, so long as you have not changed the `--version` option.
See {cls.default_lockfile_url} for the default lockfile contents.

To use a custom lockfile, set this option to a file path relative to the
build root, then run `{bin_name()} jvm-generate-lockfiles
--resolve={cls.options_scope}`.
"""
),
)

Expand Down Expand Up @@ -126,9 +134,13 @@ async def gather_coordinates_for_jvm_lockfile(

if other_targets:
raise ValueError(
"The following addresses reference targets that are not `jvm_artifact` targets. "
f"Please only supply the addresses of `jvm_artifact` for the `{request.option_name}` "
f"option. The problematic addresses are: {', '.join(str(tgt.address) for tgt in other_targets)}."
softwrap(
f"""
The following addresses reference targets that are not `jvm_artifact` targets.
Please only supply the addresses of `jvm_artifact` for the `{request.option_name}`
option. The problematic addresses are: {', '.join(str(tgt.address) for tgt in other_targets)}.
"""
)
)

return ArtifactRequirements(requirements)
Expand Down
65 changes: 41 additions & 24 deletions src/python/pants/jvm/subsystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,49 @@

from pants.option.option_types import DictOption, StrListOption, StrOption
from pants.option.subsystem import Subsystem
from pants.util.strutil import softwrap


class JvmSubsystem(Subsystem):
options_scope = "jvm"
help = (
"Options for general JVM functionality.\n\n"
" JDK strings will be passed directly to Coursier's `--jvm` parameter."
" Run `cs java --available` to see a list of available JVM versions on your platform.\n\n"
" If the string 'system' is passed, Coursier's `--system-jvm` option will be used"
" instead, but note that this can lead to inconsistent behavior since the JVM version"
" will be whatever happens to be found first on the system's PATH."
help = softwrap(
"""
Options for general JVM functionality.

JDK strings will be passed directly to Coursier's `--jvm` parameter.
Run `cs java --available` to see a list of available JVM versions on your platform.

If the string 'system' is passed, Coursier's `--system-jvm` option will be used
instead, but note that this can lead to inconsistent behavior since the JVM version
will be whatever happens to be found first on the system's PATH.
"""
)

tool_jdk = StrOption(
"--tool-jdk",
default="adopt:1.11",
help=(
"The JDK to use when building and running Pants' internal JVM support code and other "
"non-compiler tools. See `jvm` help for supported values."
help=softwrap(
"""
The JDK to use when building and running Pants' internal JVM support code and other
non-compiler tools. See `jvm` help for supported values.
"""
),
advanced=True,
)
jdk = StrOption(
"--jdk",
default="adopt:1.11",
help=(
"The JDK to use.\n\n"
" This string will be passed directly to Coursier's `--jvm` parameter."
Copy link
Member Author

@thejcannon thejcannon Apr 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This leading space was a mistake because it was already after \n. There's a few more of these I'll leave to the reader to find.

" Run `cs java --available` to see a list of available JVM versions on your platform.\n\n"
" If the string 'system' is passed, Coursier's `--system-jvm` option will be used"
" instead, but note that this can lead to inconsistent behavior since the JVM version"
" will be whatever happens to be found first on the system's PATH."
help=softwrap(
"""
The JDK to use.

This string will be passed directly to Coursier's `--jvm` parameter.
Run `cs java --available` to see a list of available JVM versions on your platform.

If the string 'system' is passed, Coursier's `--system-jvm` option will be used
instead, but note that this can lead to inconsistent behavior since the JVM version
will be whatever happens to be found first on the system's PATH.
"""
),
advanced=True,
)
Expand All @@ -49,16 +60,22 @@ class JvmSubsystem(Subsystem):
default_resolve = StrOption(
"--default-resolve",
default="jvm-default",
help=(
"The default value used for the `resolve` and `compatible_resolves` fields.\n\n"
"The name must be defined as a resolve in `[jvm].resolves`."
help=softwrap(
"""
The default value used for the `resolve` and `compatible_resolves` fields.

The name must be defined as a resolve in `[jvm].resolves`.
"""
),
)
debug_args = StrListOption(
"--debug-args",
help=(
"Extra JVM arguments to use when running tests in debug mode.\n\n"
"For example, if you want to attach a remote debugger, use something like "
"['-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005']"
help=softwrap(
"""
Extra JVM arguments to use when running tests in debug mode.

For example, if you want to attach a remote debugger, use something like
['-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005']
"""
),
)
Loading