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

A test to prove that @fromfile invalidation works now. #21901

Merged
merged 5 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 0 additions & 7 deletions docs/docs/using-pants/key-concepts/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,6 @@ PANTS_SCOPE_OPTION=@path/to/file.json
pants --scope-option="@path/to/file.json"
```

:::caution Gotcha: If you modify the value file, you must manually restart pantsd
Until we resolve [this issue](https://github.com/pantsbuild/pants/issues/10360), changing
the value in a file used with the `@` syntax as described above will not invalidate the build.
For now, if such a file changes you will have to stop pantsd so that it will be restarted on
the next invocation of pants. To do so, run `rm -r .pants.d/pids/` in the build root.
:::

## `.pants.rc` file

You can set up personal Pants config files, using the same TOML syntax as `pants.toml`. By default, Pants looks for the paths `/etc/pantsrc`, `~/.pants.rc`, and `.pants.rc` in the repository root.
Expand Down
1 change: 0 additions & 1 deletion src/python/pants/init/options_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ class OptionsInitializer:
TODO: We would eventually like to use the bootstrap Scheduler to construct the
OptionsBootstrapper as well, but for now we do the opposite thing, and the Scheduler is
used only to resolve plugins.
see: https://github.com/pantsbuild/pants/issues/10360
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #11568 for context, but what this comment was trying to say was that doing this Scheduler->Bootstrapper thing would allow resolving #10360, which we now see as resolved anyway. So...

"""

def __init__(
Expand Down
47 changes: 47 additions & 0 deletions src/python/pants/option/options_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import os
import re
from pathlib import Path
from textwrap import dedent

from pants.fs.fs import safe_filename_from_path
from pants.testutil.pants_integration_test import (
ensure_daemon,
read_pants_log,
run_pants,
run_pants_with_workdir,
setup_tmpdir,
Expand Down Expand Up @@ -108,3 +110,48 @@ def test_pants_symlink_workdirs(tmp_path: Path) -> None:
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_fromfile_invalidation(tmp_path: Path) -> None:
workdir = (tmp_path / "workdir").as_posix()
pid = None

def assert_same_daemon():
nonlocal pid
logs = "\n".join(read_pants_log(workdir))
pids = [m.group("pid") for m in re.finditer(r"running with PID: (?P<pid>\d+)", logs)]
assert len(pids) == 1
if pid is None:
pid = pids[0]
else:
assert pids[0] == pid

fromfile_path = tmp_path / "fromfile.txt"
fromfile_path.write_text("dist1")
pants_run = run_pants_with_workdir(
[f"--pants-distdir=@{fromfile_path}"],
use_pantsd=True,
workdir=workdir,
)
assert "Scheduler initialized." in pants_run.stderr
assert_same_daemon()

pants_run = run_pants_with_workdir(
[f"--pants-distdir=@{fromfile_path}"],
use_pantsd=True,
workdir=workdir,
)
# Same pantsd process, same scheduler.
assert_same_daemon()
assert "Scheduler initialized." not in pants_run.stderr
tdyas marked this conversation as resolved.
Show resolved Hide resolved

fromfile_path.write_text("dist2")
pants_run = run_pants_with_workdir(
[f"--pants-distdir=@{fromfile_path}"],
use_pantsd=True,
workdir=workdir,
)
# Same pantsd process, new scheduler.
assert_same_daemon()
assert "Initialization options changed: reinitializing scheduler..." in pants_run.stderr
assert "Scheduler initialized." in pants_run.stderr
Loading