Skip to content

Commit

Permalink
2.15.0.dev1 prep (pantsbuild#16768)
Browse files Browse the repository at this point in the history
[ci skip-rust]
[ci skip-build-wheels]

Co-authored-by: Stu Hood <[email protected]>
  • Loading branch information
wisechengyi and stuhood authored Sep 4, 2022
1 parent 2168bb3 commit 74879e5
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 530 deletions.
13 changes: 5 additions & 8 deletions src/python/pants/backend/docker/goals/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
PublishRequest,
)
from pants.engine.environment import Environment, EnvironmentRequest
from pants.engine.process import InteractiveProcess, InteractiveProcessRequest
from pants.engine.rules import Get, MultiGet, collect_rules, rule
from pants.engine.process import InteractiveProcess
from pants.engine.rules import Get, collect_rules, rule

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -75,7 +75,7 @@ async def push_docker_images(
skip_push = defaultdict(set)
jobs: list[PublishPackages] = []
refs: list[str] = []
processes: list[Get] = []
processes: list[InteractiveProcess] = []

for tag in tags:
for registry in options.registries().registries.values():
Expand All @@ -84,12 +84,9 @@ async def push_docker_images(
break
else:
refs.append(tag)
processes.append(
Get(InteractiveProcess, InteractiveProcessRequest(docker.push_image(tag, env)))
)
processes.append(InteractiveProcess.from_process(docker.push_image(tag, env)))

interactive_processes = await MultiGet(processes)
for ref, process in zip(refs, interactive_processes):
for ref, process in zip(refs, processes):
jobs.append(
PublishPackages(
names=(ref,),
Expand Down
53 changes: 13 additions & 40 deletions src/python/pants/backend/python/goals/run_pex_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
import os

from pants.backend.python.goals.package_pex_binary import PexBinaryFieldSet
from pants.backend.python.goals.run_helper import (
_create_python_source_run_dap_request,
_create_python_source_run_request,
)
from pants.backend.python.subsystems.debugpy import DebugPy
from pants.backend.python.target_types import PexBinaryDefaults, PexLayout
from pants.backend.python.util_rules.pex_environment import PexEnvironment
Expand All @@ -16,60 +12,37 @@
from pants.core.subsystems.debug_adapter import DebugAdapterSubsystem
from pants.engine.rules import Get, collect_rules, rule
from pants.engine.unions import UnionRule
from pants.option.global_options import UseDeprecatedPexBinaryRunSemanticsOption
from pants.util.logging import LogLevel


@rule(level=LogLevel.DEBUG)
async def create_pex_binary_run_request(
field_set: PexBinaryFieldSet,
use_deprecated_pex_binary_run_semantics: UseDeprecatedPexBinaryRunSemanticsOption,
pex_binary_defaults: PexBinaryDefaults,
pex_env: PexEnvironment,
) -> RunRequest:
if not use_deprecated_pex_binary_run_semantics.val:
built_pex = await Get(BuiltPackage, PexBinaryFieldSet, field_set)
relpath = built_pex.artifacts[0].relpath
assert relpath is not None
if field_set.layout.value != PexLayout.ZIPAPP.value:
relpath = os.path.join(relpath, "__main__.py")

return RunRequest(
digest=built_pex.digest,
args=[os.path.join("{chroot}", relpath)],
)

return await _create_python_source_run_request(
field_set.address,
entry_point_field=field_set.entry_point,
pex_env=pex_env,
run_in_sandbox=True,
console_script=field_set.script.value,
additional_pex_args=field_set.generate_additional_args(pex_binary_defaults),
built_pex = await Get(BuiltPackage, PexBinaryFieldSet, field_set)
relpath = built_pex.artifacts[0].relpath
assert relpath is not None
if field_set.layout.value != PexLayout.ZIPAPP.value:
relpath = os.path.join(relpath, "__main__.py")

return RunRequest(
digest=built_pex.digest,
args=[os.path.join("{chroot}", relpath)],
)


@rule
async def run_pex_debug_adapter_binary(
field_set: PexBinaryFieldSet,
use_deprecated_pex_binary_run_semantics: UseDeprecatedPexBinaryRunSemanticsOption,
debugpy: DebugPy,
debug_adapter: DebugAdapterSubsystem,
) -> RunDebugAdapterRequest:
if not use_deprecated_pex_binary_run_semantics.val:
# NB: Technically we could run this using `debugpy`, however it is unclear how the user
# would be able to debug the code, as the client and server will disagree on the code's path.
raise NotImplementedError(
"Debugging a `pex_binary` using a debug adapter has not yet been implemented."
)

run_request = await Get(RunRequest, PexBinaryFieldSet, field_set)
return await _create_python_source_run_dap_request(
run_request,
entry_point_field=field_set.entry_point,
debugpy=debugpy,
debug_adapter=debug_adapter,
console_script=field_set.script.value,
# NB: Technically we could run this using `debugpy`, however it is unclear how the user
# would be able to debug the code, as the client and server will disagree on the code's path.
raise NotImplementedError(
"Debugging a `pex_binary` using a debug adapter has not yet been implemented."
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,9 @@
from pants.backend.python.target_types import PexExecutionMode, PexLayout
from pants.testutil.pants_integration_test import PantsResult, run_pants, setup_tmpdir

use_deprecated_semantics_args = pytest.mark.parametrize(
"use_deprecated_semantics_args",
[
(),
("--use-deprecated-pex-binary-run-semantics",),
],
)


def run_generic_test(
*,
use_deprecated_semantics_args: tuple[str, ...],
entry_point: str = "app.py",
execution_mode: Optional[PexExecutionMode] = None,
include_tools: bool = False,
Expand Down Expand Up @@ -77,7 +68,6 @@ def run(*extra_args: str, **extra_env: str) -> PantsResult:
args = [
"--backend-packages=pants.backend.python",
"--backend-packages=pants.backend.codegen.protobuf.python",
*use_deprecated_semantics_args,
f"--source-root-patterns=['/{tmpdir}/src_root1', '/{tmpdir}/src_root2']",
"--pants-ignore=__pycache__",
"--pants-ignore=/src/python",
Expand All @@ -91,43 +81,32 @@ def run(*extra_args: str, **extra_env: str) -> PantsResult:

assert "Hola, mundo.\n" in result.stderr
file = result.stdout.strip()
if use_deprecated_semantics_args:
assert file.endswith("src_root2/utils/strutil.py")
assert "src_root2" not in file
assert file.endswith("utils/strutil.py")
if layout == PexLayout.LOOSE:
# Loose PEXs execute their own code directly
assert "pants-sandbox-" in file
else:
assert "src_root2" not in file
assert file.endswith("utils/strutil.py")
if layout == PexLayout.LOOSE:
# Loose PEXs execute their own code directly
assert "pants-sandbox-" in file
else:
assert "pants-sandbox-" not in file
assert "pants-sandbox-" not in file
assert result.exit_code == 23

return run


@pytest.mark.parametrize("entry_point", ["app.py", "app.py:main"])
@use_deprecated_semantics_args
def test_entry_point(
entry_point: str,
use_deprecated_semantics_args: tuple[str, ...],
):
run_generic_test(
use_deprecated_semantics_args=use_deprecated_semantics_args, entry_point=entry_point
)
run_generic_test(entry_point=entry_point)


@pytest.mark.parametrize("execution_mode", [None, PexExecutionMode.VENV])
@pytest.mark.parametrize("include_tools", [True, False])
@use_deprecated_semantics_args
def test_execution_mode_and_include_tools(
execution_mode: Optional[PexExecutionMode],
include_tools: bool,
use_deprecated_semantics_args: tuple[str, ...],
):
run = run_generic_test(
use_deprecated_semantics_args=use_deprecated_semantics_args,
execution_mode=execution_mode,
include_tools=include_tools,
)
Expand All @@ -140,23 +119,17 @@ def test_execution_mode_and_include_tools(
assert ("prepend" if execution_mode is PexExecutionMode.VENV else "false") == pex_info[
"venv_bin_path"
]
if use_deprecated_semantics_args:
assert not pex_info["strip_pex_env"]
else:
assert pex_info["strip_pex_env"]
assert pex_info["strip_pex_env"]


@pytest.mark.parametrize("layout", PexLayout)
@use_deprecated_semantics_args
def test_layout(
layout: Optional[PexLayout],
use_deprecated_semantics_args: tuple[str, ...],
):
run_generic_test(use_deprecated_semantics_args=use_deprecated_semantics_args, layout=layout)
run_generic_test(layout=layout)


@use_deprecated_semantics_args
def test_no_strip_pex_env_issues_12057(use_deprecated_semantics_args: tuple[str, ...]) -> None:
def test_no_strip_pex_env_issues_12057() -> None:
sources = {
"src/app.py": dedent(
"""\
Expand Down Expand Up @@ -185,7 +158,6 @@ def test_no_strip_pex_env_issues_12057(use_deprecated_semantics_args: tuple[str,
with setup_tmpdir(sources) as tmpdir:
args = [
"--backend-packages=pants.backend.python",
*use_deprecated_semantics_args,
f"--source-root-patterns=['/{tmpdir}/src']",
"run",
f"{tmpdir}/src:binary",
Expand All @@ -194,8 +166,7 @@ def test_no_strip_pex_env_issues_12057(use_deprecated_semantics_args: tuple[str,
assert result.exit_code == 42, result.stderr


@use_deprecated_semantics_args
def test_local_dist(use_deprecated_semantics_args: tuple[str, ...]) -> None:
def test_local_dist() -> None:
sources = {
"foo/bar.py": "BAR = 'LOCAL DIST'",
"foo/setup.py": dedent(
Expand Down Expand Up @@ -232,7 +203,6 @@ def test_local_dist(use_deprecated_semantics_args: tuple[str, ...]) -> None:
with setup_tmpdir(sources) as tmpdir:
args = [
"--backend-packages=pants.backend.python",
*use_deprecated_semantics_args,
f"--source-root-patterns=['/{tmpdir}']",
"run",
f"{tmpdir}/foo:bin",
Expand All @@ -241,8 +211,7 @@ def test_local_dist(use_deprecated_semantics_args: tuple[str, ...]) -> None:
assert result.stdout == "LOCAL DIST\n"


@use_deprecated_semantics_args
def test_run_script_from_3rdparty_dist_issue_13747(use_deprecated_semantics_args) -> None:
def test_run_script_from_3rdparty_dist_issue_13747() -> None:
sources = {
"src/BUILD": dedent(
"""\
Expand All @@ -255,7 +224,6 @@ def test_run_script_from_3rdparty_dist_issue_13747(use_deprecated_semantics_args
SAY = "moooo"
args = [
"--backend-packages=pants.backend.python",
*use_deprecated_semantics_args,
f"--source-root-patterns=['/{tmpdir}/src']",
"run",
f"{tmpdir}/src:test",
Expand All @@ -265,37 +233,3 @@ def test_run_script_from_3rdparty_dist_issue_13747(use_deprecated_semantics_args
result = run_pants(args)
result.assert_success()
assert SAY in result.stdout.strip()


# NB: Can be removed in 2.15
@use_deprecated_semantics_args
def test_filename_spec_ambiutity(use_deprecated_semantics_args) -> None:
sources = {
"src/app.py": dedent(
"""\
if __name__ == "__main__":
print(__file__)
"""
),
"src/BUILD": dedent(
"""\
python_sources(name="lib")
pex_binary(
name="binary",
entry_point="app.py"
)
"""
),
}
with setup_tmpdir(sources) as tmpdir:
args = [
"--backend-packages=pants.backend.python",
*use_deprecated_semantics_args,
f"--source-root-patterns=['/{tmpdir}/src']",
"run",
f"{tmpdir}/src/app.py",
]
result = run_pants(args)
file = result.stdout.strip()
assert file.endswith("src/app.py")
assert "pants-sandbox-" in file
34 changes: 1 addition & 33 deletions src/python/pants/backend/python/subsystems/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from pants.engine.rules import collect_rules, rule
from pants.engine.target import Target
from pants.engine.unions import UnionRule
from pants.option.option_types import ArgsListOption, BoolOption, FileOption, IntOption, StrOption
from pants.option.option_types import ArgsListOption, BoolOption, FileOption, StrOption
from pants.util.docutil import bin_name, doc_url, git_url
from pants.util.logging import LogLevel
from pants.util.memo import memoized_method
Expand Down Expand Up @@ -80,38 +80,6 @@ class PyTest(PythonToolBase):
default_lockfile_url = git_url(default_lockfile_path)

args = ArgsListOption(example="-k test_foo --quiet", passthrough=True)
timeouts = BoolOption(
default=True,
help=softwrap(
"""
Enable test target timeouts. If timeouts are enabled then test targets with a
timeout= parameter set on their target will time out after the given number of
seconds if not completed. If no timeout is set, then either the default timeout
is used or no timeout is configured.
"""
),
removal_version="2.15.0.dev1",
removal_hint="Use `timeouts` option in the `test` scope instead.",
)
timeout_default = IntOption(
default=None,
advanced=True,
help=softwrap(
"""
The default timeout (in seconds) for a test target if the `timeout` field is not
set on the target.
"""
),
removal_version="2.15.0.dev1",
removal_hint="Use `timeout_default` option in the `test` scope instead.",
)
timeout_maximum = IntOption(
default=None,
advanced=True,
help="The maximum timeout (in seconds) that may be used on a `python_tests` target.",
removal_version="2.15.0.dev1",
removal_hint="Use `timeout_maximum` option in the `test` scope instead.",
)
junit_family = StrOption(
default="xunit2",
advanced=True,
Expand Down
Loading

0 comments on commit 74879e5

Please sign in to comment.