proud-dentist-22844
06/02/2021, 5:24 AMgit worktree
.
For other directories with similar contents, I can just import something (typically a PATH var to that directory generated with an test infra function). But if I do that across the git submodule boundary, python will fail to import if the git submodule isn't checked out, and pants will complain about any dependencies on that empty directory.
(more in the thread)test_content_version
directory in: https://github.com/st2sandbox/st2/tree/pants/st2tests/st2tests/fixtures/packs
Here's the .gitmodules file: https://github.com/st2sandbox/st2/blob/pants/.gitmodulestest_content_version
git submodule directory is here:
https://github.com/st2sandbox/st2/blob/pants/contrib/runners/python_runner/tests/unit/test_pythonrunner.py#L62-L63
With this utility test function call here:
https://github.com/st2sandbox/st2/blob/pants/contrib/runners/python_runner/tests/unit/test_pythonrunner.py#L108
the utility function here checks to make sure this submodule is checked out before running the relevant tests:
https://github.com/st2sandbox/st2/blob/pants/st2tests/st2tests/fixturesloader.py#L451-L465enough-analyst-54434
06/02/2021, 6:09 AMOne of my test fixtures has to be a git submodule, as the code under test runsJust to chase down all avenues - "... as the " - the one doesn;t obviously follow from the other. A test can create its own ephemeral git repository with.git worktree
git init
etc in a tmp dir to then exercise git worktree
against.proud-dentist-22844
06/02/2021, 6:30 AMchecked out or not - dealer's choiceI think the idea is that it's required - you must checkout the submodule. The utility function serves to raise a helpful error message before running the tests that need it if it's not there. https://github.com/st2sandbox/st2/blob/pants/st2tests/st2tests/fixturesloader.py#L151-L157 Next time I work on this (my eyes are drooping ... bed is calling 😛 ) I need to find a way to accomplish that "fail nicely" purpose within the context of pants.
~/p/st2sandbox/st2.git/st2tests/st2tests/fixtures/packs $ cat test_content_version_fixture/BUILD
pack_metadata(
name="metadata",
sources=[
"st2tests/st2tests/fixtures/packs/test_content_version/pack.yaml",
"st2tests/st2tests/fixtures/packs/test_content_version/**/*.yaml",
"st2tests/st2tests/fixtures/packs/test_content_version/icon.png",
],
)
python_library(
name="test_content_version",
dependencies=[":metadata"],
sources=[
"st2tests/st2tests/fixtures/packs/test_content_version/**/*.py",
],
)
python_library(
dependencies=[":test_content_version"],
)
That of course leads to some warnings about unmatched globs:
12:49:28.19 [WARN] Unmatched globs from st2tests/st2tests/fixtures/packs/test_content_version_fixture:metadata's `sources` field: ["st2tests/st2tests/fixtures/packs/test_content_version_fixture/st2tests/st2tests/fixtures/packs/test_content_version/**/*.yaml", "st2tests/st2tests/fixtures/packs/test_content_version_fixture/st2tests/st2tests/fixtures/packs/test_content_version/icon.png", "st2tests/st2tests/fixtures/packs/test_content_version_fixture/st2tests/st2tests/fixtures/packs/test_content_version/pack.yaml"]
Do the file(s) exist? If so, check if the file(s) are in your `.gitignore` or the global `pants_ignore` option, which may result in Pants not being able to see the file(s) even though they exist on disk. Refer to (<https://www.pantsbuild.org/v2.6/docs/troubleshooting#pants-cannot-find-a-file-in-your-project>).
12:49:28.20 [WARN] Unmatched glob from st2tests/st2tests/fixtures/packs/test_content_version_fixture:test_content_version's `sources` field: "st2tests/st2tests/fixtures/packs/test_content_version_fixture/st2tests/st2tests/fixtures/packs/test_content_version/**/*.py"
Do the file(s) exist? If so, check if the file(s) are in your `.gitignore` or the global `pants_ignore` option, which may result in Pants not being able to see the file(s) even though they exist on disk. Refer to (<https://www.pantsbuild.org/v2.6/docs/troubleshooting#pants-cannot-find-a-file-in-your-project>).
Is there any way to enhance that error message from within a plugin? I'd like to add a note, for that directory, that explains how to initialize the git submodule.unmatched_globs_additional_context
so that the target can provide additional information if the glob doesn't match. Or maybe a function that wraps the sources field to inject that context: sources=ctx(["my.glob.*"], on_unmatched_globs="You need to do git submodule ...")
happy-kitchen-89482
06/05/2021, 10:06 AMproud-dentist-22844
06/05/2021, 3:00 PMPathGlobs
with a custom description_of_origin
. wdyt?dependencies
goal... wowhappy-kitchen-89482
06/05/2021, 5:57 PMhundreds-father-404
06/05/2021, 8:04 PMproud-dentist-22844
06/05/2021, 10:56 PMhundreds-father-404
06/06/2021, 1:22 AMproud-dentist-22844
06/06/2021, 3:30 AMhundreds-father-404
06/06/2021, 4:25 AMproud-dentist-22844
06/07/2021, 6:35 PMSources.validate_resolved_files()
doesn't work:
original_tgt: WrappedTarget = await Get(
^
SyntaxError: 'await' outside async function
https://github.com/st2sandbox/st2/commit/c366c3b0fd5b173de6f5d0c606460c17d808f73c#diff-ccb0f023e13c60e488a16c3232[…]5a5bbd8c995c009b437e521df1729R35hundreds-father-404
06/07/2021, 6:37 PMPathGlobs
again.
I was imagining that you'd check something like if self.address.spec_path == "some_dir" and not files
. That is, if it's the problematic target(s), see if the sources are missing or notproud-dentist-22844
06/07/2021, 6:40 PMSources.validate_resolved_files()
can I access another field on the same target? The closest I can find is self.address
, but I can't turn that into a Target
without the rules api afaict.Target.__init__()
So, it looks like the Field only gets the value and address. There is no way to get the error message from a different field.hundreds-father-404
06/08/2021, 2:53 AMproud-dentist-22844
06/08/2021, 3:13 AMhundreds-father-404
06/08/2021, 3:14 AMproud-dentist-22844
06/08/2021, 3:17 AMTarget.__init__()
here:
https://github.com/st2sandbox/st2/blob/pants/pants-plugins/unmatched_globs/target_types.py#L61-L69
I get this:
Traceback (most recent call last):
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev0_py37/lib/python3.7/site-packages/pants/bin/local_pants_runner.py", line 234, in _run_inner
return self._perform_run(goals)
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev0_py37/lib/python3.7/site-packages/pants/bin/local_pants_runner.py", line 173, in _perform_run
return self._perform_run_body(goals, poll=False)
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev0_py37/lib/python3.7/site-packages/pants/bin/local_pants_runner.py", line 195, in _perform_run_body
poll_delay=(0.1 if poll else None),
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev0_py37/lib/python3.7/site-packages/pants/init/engine_initializer.py", line 136, in run_goal_rules
goal_product, params, poll=poll, poll_delay=poll_delay
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev0_py37/lib/python3.7/site-packages/pants/engine/internals/scheduler.py", line 530, in run_goal_rule
self._raise_on_error([t for _, t in throws])
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev0_py37/lib/python3.7/site-packages/pants/engine/internals/scheduler.py", line 494, in _raise_on_error
wrapped_exceptions=tuple(t.exc for t in throws),
pants.engine.internals.scheduler.ExecutionError: 1 Exception encountered:
Engine traceback:
in select
in pants.backend.project_info.dependencies.dependencies
in pants.engine.internals.graph.resolve_targets (st2tests/st2tests/fixtures/packs/test_content_version_fixture)
in pants.engine.internals.graph.resolve_unexpanded_targets (st2tests/st2tests/fixtures/packs/test_content_version_fixture)
in pants.engine.internals.graph.resolve_dependencies (st2tests/st2tests/fixtures/packs/test_content_version_fixture)
in pants.backend.python.dependency_inference.rules.infer_python_dependencies_via_imports (st2tests/st2tests/fixtures/packs/test_content_version_fixture)
in pants.backend.python.dependency_inference.module_mapper.map_module_to_address
in pants.backend.python.dependency_inference.module_mapper.merge_first_party_module_mappings
in pants.backend.python.dependency_inference.module_mapper.map_first_party_python_targets_to_modules
in pants.engine.internals.graph.resolve_targets
in pants.engine.internals.graph.generate_subtargets (st2tests/st2tests/fixtures/packs/test_content_version_fixture:test_content_version)
in pants.engine.internals.graph.resolve_source_paths (st2tests/st2tests/fixtures/packs/test_content_version_fixture:test_content_version)
Traceback (most recent call last):
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev0_py37/lib/python3.7/site-packages/pants/engine/internals/selectors.py", line 654, in native_engine_generator_send
res = func.send(arg)
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev0_py37/lib/python3.7/site-packages/pants/engine/internals/graph.py", line 645, in resolve_source_paths
sources_field.validate_resolved_files(paths.files)
File "/home/cognifloyd/p/st2sandbox/st2.git/pants-plugins/unmatched_globs/target_types.py", line 37, in validate_resolved_files
raise UnmatchedGlobsError
unmatched_globs.target_types.UnmatchedGlobsError
Is there a way to catch that error so I can define the error message in the build file (which makes the purpose of that funky BUILD file much clearer)?hundreds-father-404
06/08/2021, 4:00 AMTarget
constructor. That try catch won't ever trigger how you want
There is currently no plugin hook to try catch the hydrate_sources
rule from pants/engine/internals/graph.py
.
Instead, I was envisioning something like:
# BUILD
custom_tgt(sources=["maybe_exist/**"])
class CustomSources(Sources):
def validate_resolved_files(self, files: Sequence[str]) -> None:
if files:
return
raise AssertionError("Init git submodule!")
That is, error if the files were not resolved, meaning we can assume the git submodule is not set up.
Does that make sense?proud-dentist-22844
06/08/2021, 4:05 AM"Init git submodule!"
error message from the BUILD file somehow.hundreds-father-404
06/08/2021, 4:08 AMproud-dentist-22844
06/08/2021, 4:11 AMTarget.__init__ -> Field.__init__
. But I'm not throwing the error in Field.__init__
. Bummer. It was worth a shot.11:03:21.38 [ERROR] Exception caught: (pants.engine.internals.scheduler.ExecutionError)
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev0_py37/lib/python3.7/site-packages/pants/bin/local_pants_runner.py", line 234, in _run_inner
return self._perform_run(goals)
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev0_py37/lib/python3.7/site-packages/pants/bin/local_pants_runner.py", line 173, in _perform_run
return self._perform_run_body(goals, poll=False)
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev0_py37/lib/python3.7/site-packages/pants/bin/local_pants_runner.py", line 195, in _perform_run_body
poll_delay=(0.1 if poll else None),
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev0_py37/lib/python3.7/site-packages/pants/init/engine_initializer.py", line 136, in run_goal_rules
goal_product, params, poll=poll, poll_delay=poll_delay
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev0_py37/lib/python3.7/site-packages/pants/engine/internals/scheduler.py", line 530, in run_goal_rule
self._raise_on_error([t for _, t in throws])
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev0_py37/lib/python3.7/site-packages/pants/engine/internals/scheduler.py", line 500, in _raise_on_error
wrapped_exceptions=tuple(t.exc for t in throws),
Exception message: 1 Exception encountered:
UnmatchedGlobsError: Instructions go here
hundreds-father-404
06/08/2021, 4:05 PMproud-dentist-22844
06/08/2021, 4:42 PM$ ./pants dependencies st2tests/st2tests/fixtures/packs/test_content_version_fixture
11:42:14.13 [ERROR] Exception caught: (pants.engine.internals.scheduler.ExecutionError)
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev1_py37/lib/python3.7/site-packages/pants/bin/local_pants_runner.py", line 234, in _run_inner
return self._perform_run(goals)
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev1_py37/lib/python3.7/site-packages/pants/bin/local_pants_runner.py", line 173, in _perform_run
return self._perform_run_body(goals, poll=False)
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev1_py37/lib/python3.7/site-packages/pants/bin/local_pants_runner.py", line 195, in _perform_run_body
poll_delay=(0.1 if poll else None),
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev1_py37/lib/python3.7/site-packages/pants/init/engine_initializer.py", line 136, in run_goal_rules
goal_product, params, poll=poll, poll_delay=poll_delay
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev1_py37/lib/python3.7/site-packages/pants/engine/internals/scheduler.py", line 530, in run_goal_rule
self._raise_on_error([t for _, t in throws])
File "/home/cognifloyd/.cache/pants/setup/bootstrap-Linux-x86_64/2.6.0.dev1_py37/lib/python3.7/site-packages/pants/engine/internals/scheduler.py", line 500, in _raise_on_error
wrapped_exceptions=tuple(t.exc for t in throws),
Exception message: 1 Exception encountered:
UnmatchedGlobsError: Instructions go here
(Use --print-stacktrace to see more error details.)