Skip to content

Commit

Permalink
pex-cli: add [pex-cli].args option to pass arguments to the PEX proce…
Browse files Browse the repository at this point in the history
…ss globally
  • Loading branch information
AlexTereshenkov committed Jul 24, 2024
1 parent 8e4450f commit 2bb9b3e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/notes/2.23.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ The default version of the `ruff` tool has been updated from 0.4.4 to 0.4.9.

The default version of the [Pex](https://docs.pex-tool.org/) tool has been updated from 2.3.1 to [2.11.0](https://github.com/pex-tool/pex/releases/tag/v2.11.0).

A new option `[pex-cli].args` has been added to be able to pass arbitrary arguments to the `pex` tool as part
of any Pants goal invocation. This should make it a lot easier to modify behavior of `pex` tool without needing
to make changes in the Pants codebase.

Fix running python source files that have dashes in them (bug introduced in 2.20). For example: `pants run path/to/some-executable.py`

A new `entry_point_dependencies` field is now available for `python_tests` and `python_test` targets. This allows tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,31 @@ def test_run_script_from_3rdparty_dist_issue_13747() -> None:
result = run_pants(args)
result.assert_success()
assert SAY in result.stdout.strip()


def test_pass_extra_pex_cli_subsystem_args() -> None:
"""Test that extra args passed to the pex-cli subsystem propagate to the actual pex
invocation."""
sources = {
"src/BUILD": dedent(
"""\
python_requirement(name="cowsay", requirements=["cowsay==4.0"])
pex_binary(name="test", script="cowsay", dependencies=[":cowsay"])
"""
),
}
with setup_tmpdir(sources) as tmpdir:
args = [
"--backend-packages=pants.backend.python",
"--pex-cli-args='--non-existing-flag-name=some-value'",
f"--source-root-patterns=['/{tmpdir}/src']",
"run",
f"{tmpdir}/src:test",
"--",
"moooo",
]
result = run_pants(args)
result.assert_failure()
stderr = result.stderr.strip()
assert "unrecognized arguments" in stderr
assert "non-existing-flag-name" in stderr
7 changes: 7 additions & 0 deletions src/python/pants/backend/python/util_rules/pex_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from pants.engine.process import Process, ProcessCacheScope
from pants.engine.rules import Get, collect_rules, rule
from pants.option.global_options import GlobalOptions, ca_certs_path_to_file_content
from pants.option.option_types import ArgsListOption
from pants.util.frozendict import FrozenDict
from pants.util.logging import LogLevel
from pants.util.meta import classproperty
Expand All @@ -42,6 +43,10 @@ class PexCli(TemplatedExternalTool):
default_url_template = "https://github.com/pex-tool/pex/releases/download/{version}/pex"
version_constraints = ">=2.3.0,<3.0"

# extra args to be passed to the pex tool; note that they
# are going to apply to all invocations of the pex tool.
args = ArgsListOption(example="--check=error --no-compile")

@classproperty
def default_known_versions(cls):
return [
Expand Down Expand Up @@ -123,6 +128,7 @@ async def setup_pex_cli_process(
python_native_code: PythonNativeCodeSubsystem.EnvironmentAware,
global_options: GlobalOptions,
pex_subsystem: PexSubsystem,
pex_cli_subsystem: PexCli,
python_setup: PythonSetup,
) -> Process:
tmpdir = ".tmp"
Expand Down Expand Up @@ -179,6 +185,7 @@ async def setup_pex_cli_process(
*warnings_args,
*pip_version_args,
*resolve_args,
*pex_cli_subsystem.args,
# NB: This comes at the end because it may use `--` passthrough args, # which must come at
# the end.
*request.extra_args,
Expand Down

0 comments on commit 2bb9b3e

Please sign in to comment.