Beispiel #1
0
 def run() -> None:
     run_pants_with_workdir(
         [
             "--backend-packages=['pants.backend.python', 'pants.backend.python.lint.black']",
             "fmt",
             f,
         ],
         workdir=workdir,
     ).assert_success()
def test_logs_unhandled_exception() -> None:
    directory = "testprojects/src/python/hello/main"
    with temporary_dir() as tmpdir:
        pants_run = run_pants_with_workdir(
            ["--no-pantsd", "list", f"{directory}:this-target-does-not-exist"],
            workdir=tmpdir,
            # The backtrace should be omitted when --print-stacktrace=False.
            print_stacktrace=False,
            hermetic=False,
        )

        pants_run.assert_failure()

        regex = f"'this-target-does-not-exist' was not found in namespace '{directory}'\\. Did you mean one of:"
        assert re.search(regex, pants_run.stderr)

        pid_specific_log_file, shared_log_file = get_log_file_paths(
            tmpdir, pants_run.pid)
        assert_unhandled_exception_log_matches(
            pants_run.pid,
            read_file(pid_specific_log_file),
            namespace=directory)
        assert_unhandled_exception_log_matches(pants_run.pid,
                                               read_file(shared_log_file),
                                               namespace=directory)
Beispiel #3
0
 def run_pants_with_workdir(*args, **kwargs) -> PantsResult:
     # We set our own ad-hoc pantsd configuration in most of these tests.
     return run_pants_with_workdir(*args, **{
         **kwargs,
         **{
             "use_pantsd": False
         }
     })
 def run_pants_with_workdir(*args, **kwargs) -> PantsResult:
     # Git isn't detected if hermetic=True for some reason.
     return run_pants_with_workdir(*args, **{
         **kwargs,
         **{
             "hermetic": False
         }
     })
Beispiel #5
0
def test_pants_symlink_workdirs() -> None:
    with temporary_dir() as tmp_dir:
        symlink_workdir = f"{tmp_dir}/.pants.d"
        physical_workdir_base = f"{tmp_dir}/workdirs"
        physical_workdir = f"{physical_workdir_base}/{safe_filename_from_path(symlink_workdir)}"

        pants_run = run_pants_with_workdir(
            [f"--pants-physical-workdir-base={physical_workdir_base}", "help"],
            workdir=symlink_workdir,
        )
        pants_run.assert_success()
        # Make sure symlink workdir is pointing to physical workdir
        assert os.readlink(symlink_workdir) == physical_workdir
def test_fails_ctrl_c_ffi(tmp_path: Path) -> None:
    pants_run = run_pants_with_workdir(
        command=lifecycle_stub_cmdline(),
        workdir=tmp_path.as_posix(),
        extra_env={"_RAISE_KEYBOARD_INTERRUPT_FFI": "1"},
    )
    pants_run.assert_failure()
    assert "KeyboardInterrupt: ctrl-c interrupted execution during FFI" in pants_run.stderr

    pid_specific_log_file, shared_log_file = get_log_file_paths(
        tmp_path.as_posix(), pants_run.pid)
    assert "" == read_file(pid_specific_log_file)
    assert "" == read_file(shared_log_file)
Beispiel #7
0
def test_pants_symlink_workdirs(tmp_path: Path) -> None:

    symlink_workdir = tmp_path / ".pants.d"
    physical_workdir_base = tmp_path / "workdirs"
    physical_workdir = physical_workdir_base / safe_filename_from_path(
        symlink_workdir.as_posix())

    pants_run = run_pants_with_workdir(
        [
            f"--pants-physical-workdir-base={physical_workdir_base.as_posix()}",
            "help"
        ],
        workdir=symlink_workdir.as_posix(),
    )
    pants_run.assert_success()
    # Make sure symlink workdir is pointing to physical workdir
    assert Path(os.readlink(symlink_workdir.as_posix())) == physical_workdir
def test_fails_ctrl_c_on_import(tmp_path: Path) -> None:
    # TODO: figure out the cwd of the pants subprocess, not just the "workdir"!
    pants_run = run_pants_with_workdir(
        lifecycle_stub_cmdline(),
        workdir=tmp_path.as_posix(),
        extra_env={"_RAISE_KEYBOARDINTERRUPT_ON_IMPORT": "True"},
    )
    pants_run.assert_failure()

    assert (dedent("""\
            Interrupted by user:
            ctrl-c during import!
            """) in pants_run.stderr)

    pid_specific_log_file, shared_log_file = get_log_file_paths(
        tmp_path.as_posix(), pants_run.pid)
    assert "" == read_file(pid_specific_log_file)
    assert "" == read_file(shared_log_file)
Beispiel #9
0
def test_logs_unhandled_exception(tmp_path: Path) -> None:
    pants_run = run_pants_with_workdir(
        # The backtrace should be omitted when --print-stacktrace=False.
        [*lifecycle_stub_cmdline(), "--no-print-stacktrace"],
        workdir=tmp_path.as_posix(),
        extra_env={"_RAISE_EXCEPTION_ON_IMPORT": "True"},
    )

    pants_run.assert_failure()

    regex = "exception during import!"
    assert re.search(regex, pants_run.stderr)

    pid_specific_log_file, shared_log_file = get_log_file_paths(
        tmp_path.as_posix(), pants_run.pid)
    assert_unhandled_exception_log_matches(pants_run.pid,
                                           read_file(pid_specific_log_file))
    assert_unhandled_exception_log_matches(pants_run.pid,
                                           read_file(shared_log_file))
Beispiel #10
0
def test_fails_ctrl_c_ffi_extern() -> None:
    with temporary_dir() as tmpdir:
        pants_run = run_pants_with_workdir(
            command=lifecycle_stub_cmdline(),
            workdir=tmpdir,
            extra_env={"_RAISE_KEYBOARDINTERRUPT_IN_EXTERNS": "True"},
        )
        pants_run.assert_failure()

        assert (
            "KeyboardInterrupt: ctrl-c interrupted execution of a ffi method!"
            in pants_run.stderr)

        pid_specific_log_file, shared_log_file = get_log_file_paths(
            tmpdir, pants_run.pid)

        assert "KeyboardInterrupt: ctrl-c interrupted execution of a ffi method!" in read_file(
            pid_specific_log_file)
        assert "KeyboardInterrupt: ctrl-c interrupted execution of a ffi method!" in read_file(
            shared_log_file)
Beispiel #11
0
def _run_pants_goal(
    workdir: str,
    goal: str,
    dependees: DependeesOption = DependeesOption.NONE,
    *,
    extra_args: list[str] | None = None,
) -> PantsResult:
    return run_pants_with_workdir(
        [
            *(extra_args or ()),
            "--changed-since=HEAD",
            "--print-stacktrace",
            f"--changed-dependees={dependees.value}",
            goal,
        ],
        workdir=workdir,
        config={"GLOBAL": {
            "backend_packages": ["pants.backend.shell"]
        }},
    )