proud-dentist-22844
06/25/2024, 7:41 PME ValueError: No build root detected for the current directory of /tmp/pants-sandbox-LsFSaZ. Pants detects the build root by looking for at least one file from pants.toml, BUILDROOT, BUILD_ROOT in the cwd and its ancestors. If you have none of these files, you can create an empty file in your build root.
With pants 2.22 do I need to change how I use the RuleRunner
?wide-midnight-78598
06/25/2024, 7:44 PMproud-dentist-22844
06/25/2024, 7:46 PMwide-midnight-78598
06/25/2024, 7:46 PMproud-dentist-22844
06/25/2024, 7:46 PM@rule_helper
šwide-midnight-78598
06/25/2024, 7:47 PMwide-midnight-78598
06/25/2024, 7:47 PMproud-dentist-22844
06/25/2024, 7:48 PMwide-midnight-78598
06/25/2024, 7:50 PMproud-dentist-22844
06/25/2024, 7:50 PM/home/runner/.cache/pants/named_caches/pex_root/venvs/s/3e4d8434/venv/lib/python3.9/site-packages/pants/testutil/rule_runner.py:313: in __init__
self.options_bootstrapper = self.create_options_bootstrapper(args=bootstrap_args, env=None)
/home/runner/.cache/pants/named_caches/pex_root/venvs/s/3e4d8434/venv/lib/python3.9/site-packages/pants/testutil/rule_runner.py:443: in create_options_bootstrapper
return create_options_bootstrapper(args=args, env=env)
/home/runner/.cache/pants/named_caches/pex_root/venvs/s/3e4d8434/venv/lib/python3.9/site-packages/pants/testutil/option_util.py:18: in create_options_bootstrapper
return OptionsBootstrapper.create(
/home/runner/.cache/pants/named_caches/pex_root/venvs/s/3e4d8434/venv/lib/python3.9/site-packages/pants/option/options_bootstrapper.py:145: in create
initial_bootstrap_options = cls.parse_bootstrap_options(
/home/runner/.cache/pants/named_caches/pex_root/venvs/s/3e4d8434/venv/lib/python3.9/site-packages/pants/option/options_bootstrapper.py:95: in parse_bootstrap_options
bootstrap_options = Options.create(
/home/runner/.cache/pants/named_caches/pex_root/venvs/s/3e4d8434/venv/lib/python3.9/site-packages/pants/option/options.py:166: in create
native_parser = NativeOptionParser(args, env, config.sources(), allow_pantsrc=True)
/home/runner/.cache/pants/named_caches/pex_root/venvs/s/3e4d8434/venv/lib/python3.9/site-packages/pants/option/native_options.py:47: ValueError
self._native_parser = native_engine.PyOptionParser(
proud-dentist-22844
06/25/2024, 8:01 PMBUILDROOT
file to some of my tests, but it dies will initing RuleRunner
before I've had a chance to write any files šproud-dentist-22844
06/25/2024, 8:34 PMproud-dentist-22844
06/25/2024, 10:21 PMBuildRoot
here:
https://github.com/pantsbuild/pants/blob/ecf0a7f30800db1bcaf17079f3595a2ae8587964/src/python/pants/testutil/rule_runner.py#L280
But then, the failure happens when initializing the options bootstrapper, because the rust layer does not respect that singleton BuildRoot
python object. That initialization starts here AFTER the BuildRoot
has already been configured:
https://github.com/pantsbuild/pants/blob/ecf0a7f30800db1bcaf17079f3595a2ae8587964/src/python/pants/testutil/rule_runner.py#L313
The options bootstrapper finishes setting up the python options parser, and then just (randomly?) creates a NativeOptionParser
simply to ensure it works with the same args.
https://github.com/pantsbuild/pants/blob/ecf0a7f30800db1bcaf17079f3595a2ae8587964/src/python/pants/option/options.py#L166
This is where the rust code throws ValueError
if OptionParser init fails (note that the buildroot
kwarg is explicitly set to None
):
https://github.com/pantsbuild/pants/blob/ecf0a7f30800db1bcaf17079f3595a2ae8587964/src/rust/engine/src/externs/options.rs#L184-L193
The first thing the option parser does is search for the build root, which fails (since the RuleRunner has only created an empty directory):
https://github.com/pantsbuild/pants/blob/ecf0a7f30800db1bcaf17079f3595a2ae8587964/src/rust/engine/options/src/lib.rs#L284
Maybe the RuleRunner
should add the PANTS_BUILDROOT_OVERRIDE
env var to bypass the search logic? Or is there some way for the rust layer to find the BuildRoot
python singleton object?
https://github.com/pantsbuild/pants/blob/ecf0a7f30800db1bcaf17079f3595a2ae8587964/src/rust/engine/options/src/build_root.rs#L24happy-kitchen-89482
06/26/2024, 5:11 PMhappy-kitchen-89482
06/26/2024, 5:12 PMproud-dentist-22844
06/26/2024, 5:12 PMNativeOptionParser
(essentially bypassing the BuildRoot::find
logic in rust), or set PANTS_BUILDROOT_OVERRIDE
in the RuleRunner
, or have RuleRunner
touch a BUILD_ROOT
file in the sandbox?
Thanks for looking... Take your time. I started drafting this message before you responded šhappy-kitchen-89482
06/26/2024, 5:17 PMproud-dentist-22844
06/26/2024, 5:17 PMhappy-kitchen-89482
06/26/2024, 5:20 PMproud-dentist-22844
06/26/2024, 5:50 PMproud-dentist-22844
06/26/2024, 5:53 PMRuleRunner
does not change the cwd to the temp directory it created as a build_root, which is why that test can generate its own build root and then create RuleRunner. Once the test calls set_options, the build_root gets re-calculated based on cwd.
So, I think the cwd is the pytest sandbox instead of RuleRunner's build_root tmp dir. Maybe the pants.toml
or BUILD_ROOT
files are ending up in the pytest sandbox when running in the pants repo?proud-dentist-22844
06/26/2024, 6:09 PMpantsbuild/pants
repo are passing because the BUILD_ROOT
file is a dependency of src/python/pants/testutil/rule_runner.py
, meaning every test that uses RuleRunner
has the BUILD_ROOT
file in the pytest sandbox!proud-dentist-22844
06/26/2024, 6:11 PMproud-dentist-22844
06/26/2024, 6:14 PMRuleRunner
?
If so, please try pants 2.22.0.rc0. Does RuleRunner work for you? If the tests work, do you have a BUILD_ROOT
or BUILDROOT
file in the root of your repo?happy-kitchen-89482
06/26/2024, 6:24 PMproud-dentist-22844
06/26/2024, 7:24 PMBuildRoot
, everything in the python layer will see the tmp directory as the build root, even though cwd is the pytest sandbox.proud-dentist-22844
06/26/2024, 7:34 PMrule_runner
pytest fixture to make it add a BUILDROOT
file to the cwd before initializing the `RuleRunner`:
@pytest.fixture
def rule_runner() -> RuleRunner:
# add BUILDROOT file in the pytest sandbox to deal with the rust options layer
touch("BUILDROOT")
return RuleRunner(
And then I ran the tests (successfully!) with --keep-sandboxes=always
.
Yes. The BUILDROOT
file (which does not exist in the st2 repo) gets added to the root of the pytest sandbox:
$ pants --keep-sandboxes=always test pants-plugins/api_spec/rules_test.py
14:30:59.91 [INFO] Preserving local process execution dir /tmp/pants-sandbox-AFG2bb for Run Pytest for pants-plugins/api_spec/rules_test.py:tests
14:31:10.27 [INFO] Completed: Run Pytest - pants-plugins/api_spec/rules_test.py:tests - succeeded.
ā pants-plugins/api_spec/rules_test.py:tests succeeded in 10.36s.
$ ls /tmp/pants-sandbox-AFG2bb
BUILDROOT extra-output local_dists.pex pants-plugins pants-plugins.api_spec.rules_test.py.tests.xml pyproject.toml pytest.pex pytest_runner.pex pytest_runner.pex_bin_python_shim.sh pytest_runner.pex_pex_shim.sh requirements.pex __run.sh
proud-dentist-22844
06/27/2024, 12:51 AMRuleRunner
to depend on //BUILD_ROOT:files
?
I've traced the git history back to https://github.com/pantsbuild/pants/commit/a0bcc2314c486fcaa34de9401c29890799ead1ba#diff-d031e5fbb87740ea8f711edcd[ā¦]8bc5e983001013f3bccf590da487R35
And I'm not sure this has much to do with the current RuleRunner. I think we should remove that dependency. Doing that shows the same failure that I'm experiencing in the st2 repo on the 2.22.x branch, BUT the tests pass on the 2.21.x branch. (or at least, running the tests locally for src/python/pants/backend/pants/::
fails on 2.22 and passes on 2.21).narrow-vegetable-37489
06/27/2024, 12:54 PMRuleRunner
issue as well when running the integration tests for our internal plugins on Pants 2.23.0.dev2 instead of 2.21.0dev1.proud-dentist-22844
06/27/2024, 3:36 PMproud-dentist-22844
06/27/2024, 5:42 PMacoustic-librarian-29560
07/01/2024, 4:52 PMproud-dentist-22844
07/01/2024, 6:19 PMproud-dentist-22844
07/01/2024, 9:31 PM