https://pantsbuild.org/ logo
#general
Title
# general
l

limited-insurance-37393

04/28/2021, 7:42 PM
So, I've got a
templates
directory in my repository that has some Python files and other templates, but shouldn't necessarily have any BUILD files. When I run
./pants tailor
it errors out because one of the subdirectories doesn't have a BUILD file, and there doesn't appear to be a way to tell the command to ignore any directories, or to tell it to run only against the
src/
directory.
Full output with
--print-stacktrace
Copy code
./pants --print-stacktrace tailor
15:43:02.77 [ERROR] Exception caught: (pants.engine.internals.scheduler.ExecutionError)
  File "/home/tmacey/.cache/pants/setup/bootstrap-Linux-x86_64/2.4.0_py37/lib/python3.7/site-packages/pants/bin/local_pants_runner.py", line 229, in _run_inner
    return self._perform_run(goals)
  File "/home/tmacey/.cache/pants/setup/bootstrap-Linux-x86_64/2.4.0_py37/lib/python3.7/site-packages/pants/bin/local_pants_runner.py", line 168, in _perform_run
    return self._perform_run_body(goals, poll=False)
  File "/home/tmacey/.cache/pants/setup/bootstrap-Linux-x86_64/2.4.0_py37/lib/python3.7/site-packages/pants/bin/local_pants_runner.py", line 190, in _perform_run_body
    poll_delay=(0.1 if poll else None),
  File "/home/tmacey/.cache/pants/setup/bootstrap-Linux-x86_64/2.4.0_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/tmacey/.cache/pants/setup/bootstrap-Linux-x86_64/2.4.0_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/tmacey/.cache/pants/setup/bootstrap-Linux-x86_64/2.4.0_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),

Exception message: 1 Exception encountered:

Engine traceback:
  in select
  in pants.core.goals.tailor.tailor
  in pants.backend.python.goals.tailor.find_putative_targets
  in pants.core.goals.tailor.determine_all_owned_sources
  in pants.engine.internals.graph.resolve_unexpanded_targets
  in pants.engine.internals.build_files.addresses_from_address_specs
  in pants.engine.internals.build_files.parse_address_family (templates/pyinfra_component/[[ _copier_answers.component_name ]])
Traceback (most recent call last):
  File "/home/tmacey/.cache/pants/setup/bootstrap-Linux-x86_64/2.4.0_py37/lib/python3.7/site-packages/pants/engine/internals/selectors.py", line 654, in native_engine_generator_send
    res = func.send(arg)
  File "/home/tmacey/.cache/pants/setup/bootstrap-Linux-x86_64/2.4.0_py37/lib/python3.7/site-packages/pants/engine/internals/build_files.py", line 106, in parse_address_family
    raise ResolveError(f"Directory '{directory.path}' does not contain any BUILD files.")
pants.base.exceptions.ResolveError: Directory 'templates/pyinfra_component/[[ _copier_answers.component_name ]]' does not contain any BUILD files.


(Use --print-stacktrace to see more error details.)
The repository in question is at github.com/mitodl/ol-infrastructure
h

happy-kitchen-89482

04/29/2021, 2:13 AM
👀
That is probably a bug, since
tailor
should not error like that even if it gets confused. Thanks for posting the repo that exposes this, I will take a look.
h

hundreds-father-404

04/29/2021, 10:56 PM
Interesting, so turns out you do have a BUILD file in that directory, but Pants doesn't like the directory
[[ _copier_answers.component_name ]]
and it causes Pants to get confused if there is or is not a BUILD file there. I'm creating a minimal repro now
h

happy-kitchen-89482

04/29/2021, 11:12 PM
Is it confused by dots in the dirname or something?
h

hundreds-father-404

04/29/2021, 11:16 PM
So far it looks like the
[[
]]
, spaces were fine. Still narrowing it down, got pulled into some other things
Okay I see what's going on. Our
PathGlobs
syntax uses
.gitignore
syntax, and
[a-zA-Z]
can be used as a range, per: https://git-scm.com/docs/gitignore#_pattern_format. For example:
Copy code
$ ./pants list 'debug/[abc::'
...
Exception: Could not parse "debug/[abc/**/BUILD" as a glob: PatternError { pos: 0, msg: "invalid range pattern" }
@limited-insurance-37393 the (temporary) workaround is to not use
[
and
]
in a file path
h

happy-kitchen-89482

04/30/2021, 12:14 AM
So what would the long-term fix be?
Can we not use escape sequences? How does git manage this?
h

hundreds-father-404

04/30/2021, 12:17 AM
I haven't spent the time to investigate how the relevant Rust library handles escapes (couldn't get it to escape via renaming the file to
\[
), but yeah, presumably through escaping I think the tricky thing is if we do ever want to support
[
ranges, e.g. is that useful in the
sources
field? We've only really documented
!
and `*`/`**` being supported. If we do want to support, I think we would need to selectively add the normalization
l

limited-insurance-37393

04/30/2021, 2:09 AM
Thanks for the detail! For now I think I'll probably just remove the BUILD file in the template. Since tailor is a thing now I can easily just generate the BUILD after generating the templated directory.
👍 1
4 Views